github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/deprovisioning/edp_deregistration_test.go (about) 1 package deprovisioning 2 3 import ( 4 "encoding/base64" 5 "fmt" 6 "testing" 7 "time" 8 9 "github.com/kyma-project/kyma-environment-broker/internal" 10 "github.com/kyma-project/kyma-environment-broker/internal/edp" 11 "github.com/kyma-project/kyma-environment-broker/internal/storage" 12 "github.com/sirupsen/logrus" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 const ( 17 edpName = "f88401ba-c601-45bb-bec0-a2156c07c9a6" 18 edpEnvironment = "test" 19 ) 20 21 func TestEDPDeregistration_Run(t *testing.T) { 22 // given 23 client := edp.NewFakeClient() 24 err := client.CreateDataTenant(edp.DataTenantPayload{ 25 Name: edpName, 26 Environment: edpEnvironment, 27 Secret: base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s%s", edpName, edpEnvironment))), 28 }) 29 assert.NoError(t, err) 30 31 metadataTenantKeys := []string{ 32 edp.MaasConsumerEnvironmentKey, 33 edp.MaasConsumerRegionKey, 34 edp.MaasConsumerSubAccountKey, 35 edp.MaasConsumerServicePlan, 36 } 37 38 for _, key := range metadataTenantKeys { 39 err = client.CreateMetadataTenant(edpName, edpEnvironment, edp.MetadataTenantPayload{ 40 Key: key, 41 Value: "-", 42 }) 43 assert.NoError(t, err) 44 } 45 46 memoryStorage := storage.NewMemoryStorage() 47 step := NewEDPDeregistrationStep(memoryStorage.Operations(), client, edp.Config{ 48 Environment: edpEnvironment, 49 }) 50 51 // when 52 _, repeat, err := step.Run( 53 internal.Operation{ 54 InstanceDetails: internal.InstanceDetails{ 55 SubAccountID: edpName, 56 }, 57 }, logrus.New()) 58 59 // then 60 assert.Equal(t, 0*time.Second, repeat) 61 assert.NoError(t, err) 62 63 for _, key := range metadataTenantKeys { 64 metadataTenant, metadataTenantExists := client.GetMetadataItem(edpName, edpEnvironment, key) 65 assert.False(t, metadataTenantExists) 66 assert.Equal(t, edp.MetadataItem{}, metadataTenant) 67 } 68 69 dataTenant, dataTenantExists := client.GetDataTenantItem(edpName, edpEnvironment) 70 assert.False(t, dataTenantExists) 71 assert.Equal(t, edp.DataTenantItem{}, dataTenant) 72 }