github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/upgrade_kyma/skip_for_trial_step_test.go (about) 1 package upgrade_kyma 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/kyma-project/kyma-environment-broker/internal" 8 "github.com/kyma-project/kyma-environment-broker/internal/broker" 9 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 10 "github.com/kyma-project/kyma-environment-broker/internal/process/upgrade_kyma/automock" 11 "github.com/sirupsen/logrus" 12 "github.com/stretchr/testify/assert" 13 ) 14 15 const ( 16 instanceID = "58f8c703-1756-48ab-9299-a847974d1fee" 17 operationID = "fd5cee4d-0eeb-40d0-a7a7-0708e5eba470" 18 ) 19 20 func TestSkipForTrialPlanStepShouldSkip(t *testing.T) { 21 // Given 22 log := logrus.New() 23 wantSkipTime := time.Duration(0) 24 wantOperation := fixOperationWithPlanID(broker.TrialPlanID) 25 26 mockStep := new(automock.Step) 27 mockStep.On("Name").Return("Test") 28 skipStep := NewSkipForTrialPlanStep(mockStep) 29 30 // When 31 gotOperation, gotSkipTime, gotErr := skipStep.Run(wantOperation, log) 32 33 // Then 34 mockStep.AssertExpectations(t) 35 assert.Nil(t, gotErr) 36 assert.Equal(t, wantSkipTime, gotSkipTime) 37 assert.Equal(t, wantOperation, gotOperation) 38 } 39 40 func TestSkipForTrialPlanStepShouldNotSkip(t *testing.T) { 41 // Given 42 log := logrus.New() 43 wantSkipTime := time.Duration(10) 44 givenOperation1 := fixOperationWithPlanID("operation1") 45 wantOperation2 := fixOperationWithPlanID("operation2") 46 47 mockStep := new(automock.Step) 48 mockStep.On("Run", givenOperation1, log).Return(wantOperation2, wantSkipTime, nil) 49 skipStep := NewSkipForTrialPlanStep(mockStep) 50 51 // When 52 gotOperation, gotSkipTime, gotErr := skipStep.Run(givenOperation1, log) 53 54 // Then 55 mockStep.AssertExpectations(t) 56 assert.Nil(t, gotErr) 57 assert.Equal(t, wantSkipTime, gotSkipTime) 58 assert.Equal(t, wantOperation2, gotOperation) 59 } 60 61 func fixOperationWithPlanID(planID string) internal.UpgradeKymaOperation { 62 upgradeOperation := fixture.FixUpgradeKymaOperation(operationID, instanceID) 63 upgradeOperation.ProvisioningParameters = fixture.FixProvisioningParameters("dummy") 64 upgradeOperation.ProvisioningParameters.PlanID = planID 65 66 return upgradeOperation 67 }