github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/deprovisioning/remove_runtime_test.go (about) 1 package deprovisioning 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 8 provisionerAutomock "github.com/kyma-project/kyma-environment-broker/internal/provisioner/automock" 9 "github.com/kyma-project/kyma-environment-broker/internal/storage" 10 "github.com/sirupsen/logrus" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestRemoveRuntimeStep_Run(t *testing.T) { 15 t.Run("Should repeat process when deprovisioning call to provisioner succeeded", func(t *testing.T) { 16 // given 17 log := logrus.New() 18 memoryStorage := storage.NewMemoryStorage() 19 20 operation := fixture.FixDeprovisioningOperation(fixOperationID, fixInstanceID) 21 operation.GlobalAccountID = fixGlobalAccountID 22 operation.RuntimeID = fixRuntimeID 23 err := memoryStorage.Operations().InsertDeprovisioningOperation(operation) 24 assert.NoError(t, err) 25 26 err = memoryStorage.Instances().Insert(fixInstanceRuntimeStatus()) 27 assert.NoError(t, err) 28 29 provisionerClient := &provisionerAutomock.Client{} 30 provisionerClient.On("DeprovisionRuntime", fixGlobalAccountID, fixRuntimeID).Return(fixProvisionerOperationID, nil) 31 32 step := NewRemoveRuntimeStep(memoryStorage.Operations(), memoryStorage.Instances(), provisionerClient, time.Minute) 33 34 // when 35 entry := log.WithFields(logrus.Fields{"step": "TEST"}) 36 result, repeat, err := step.Run(operation.Operation, entry) 37 38 // then 39 assert.NoError(t, err) 40 assert.Equal(t, 0*time.Second, repeat) 41 assert.Equal(t, fixProvisionerOperationID, result.ProvisionerOperationID) 42 43 instance, err := memoryStorage.Instances().GetByID(result.InstanceID) 44 assert.NoError(t, err) 45 assert.Equal(t, instance.RuntimeID, fixRuntimeID) 46 47 }) 48 }