github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/deprovisioning/skip_for_trial_step_test.go (about) 1 package deprovisioning 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/deprovisioning/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 subAccountID = "12df5747-3efb-4df6-ad6f-4414bb661ce3" 19 globalAccountID = "80ac17bd-33e8-4ffa-8d56-1d5367755723" 20 ) 21 22 func TestSkipForTrialPlanStepShouldSkip(t *testing.T) { 23 // Given 24 log := logrus.New() 25 wantSkipTime := time.Duration(0) 26 wantOperation := fixOperationWithPlanID(broker.TrialPlanID) 27 28 mockStep := new(automock.Step) 29 mockStep.On("Name").Return("Test") 30 skipStep := NewSkipForTrialPlanStep(mockStep) 31 32 // When 33 gotOperation, gotSkipTime, gotErr := skipStep.Run(wantOperation, log) 34 35 // Then 36 mockStep.AssertExpectations(t) 37 assert.Nil(t, gotErr) 38 assert.Equal(t, wantSkipTime, gotSkipTime) 39 assert.Equal(t, wantOperation, gotOperation) 40 } 41 42 func TestSkipForTrialPlanStepShouldNotSkip(t *testing.T) { 43 // Given 44 log := logrus.New() 45 wantSkipTime := time.Duration(10) 46 givenOperation1 := fixOperationWithPlanID("operation1") 47 wantOperation2 := fixOperationWithPlanID("operation2") 48 49 mockStep := new(automock.Step) 50 mockStep.On("Run", givenOperation1, log).Return(wantOperation2, wantSkipTime, nil) 51 skipStep := NewSkipForTrialPlanStep(mockStep) 52 53 // When 54 gotOperation, gotSkipTime, gotErr := skipStep.Run(givenOperation1, log) 55 56 // Then 57 mockStep.AssertExpectations(t) 58 assert.Nil(t, gotErr) 59 assert.Equal(t, wantSkipTime, gotSkipTime) 60 assert.Equal(t, wantOperation2, gotOperation) 61 } 62 63 func fixOperationWithPlanID(planID string) internal.DeprovisioningOperation { 64 deprovisioningOperation := fixture.FixDeprovisioningOperation(operationID, instanceID) 65 deprovisioningOperation.Operation.ProvisioningParameters.PlanID = planID 66 deprovisioningOperation.Operation.ProvisioningParameters.ErsContext.GlobalAccountID = globalAccountID 67 deprovisioningOperation.Operation.ProvisioningParameters.ErsContext.SubAccountID = subAccountID 68 return deprovisioningOperation 69 }