github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/provisioning/override_kyma_modules_test.go (about) 1 package provisioning 2 3 import ( 4 "testing" 5 6 "github.com/google/uuid" 7 "github.com/kyma-project/kyma-environment-broker/internal" 8 "github.com/kyma-project/kyma-environment-broker/internal/fixture" 9 "github.com/kyma-project/kyma-environment-broker/internal/ptr" 10 "github.com/kyma-project/kyma-environment-broker/internal/storage" 11 "github.com/sirupsen/logrus" 12 "github.com/stretchr/testify/assert" 13 "github.com/stretchr/testify/require" 14 ) 15 16 const ( 17 technicalNameBtpManager = "btp-operator" 18 technicalNameKeda = "keda" 19 givenKymaTemplateWithModules = "kyma-with-keda-and-btp-operator.yaml" 20 defaultModules = givenKymaTemplateWithModules 21 givenKymaTemplateWithoutModules = "kyma-no-modules.yaml" 22 kymaExpectedNamespace = "kyma-system" 23 ) 24 25 func execTest(t *testing.T, parameters *internal.ModulesDTO, in, out string) { 26 db := storage.NewMemoryStorage() 27 operation := fixture.FixOperation(uuid.NewString(), uuid.NewString(), internal.OperationTypeProvision) 28 operation.KymaTemplate = internal.GetKymaTemplateForTests(t, in) 29 expectedKymaTemplate := internal.GetKymaTemplateForTests(t, out) 30 operation.ProvisioningParameters.Parameters.Modules = parameters 31 err := db.Operations().InsertOperation(operation) 32 assert.NoError(t, err) 33 svc := NewOverrideKymaModules(db.Operations()) 34 35 // when 36 op, backoff, err := svc.Run(operation, logrus.New()) 37 assert.Zero(t, backoff) 38 assert.Equal(t, kymaExpectedNamespace, op.KymaResourceNamespace) 39 assert.YAMLEq(t, expectedKymaTemplate, op.KymaTemplate) 40 require.NoError(t, err) 41 } 42 43 func TestOverrideKymaModules(t *testing.T) { 44 t.Run("default modules are installed when default is true", func(t *testing.T) { 45 modules := &internal.ModulesDTO{} 46 modules.Default = ptr.Bool(true) 47 execTest(t, modules, givenKymaTemplateWithModules, defaultModules) 48 execTest(t, modules, givenKymaTemplateWithoutModules, "kyma-no-modules.yaml") 49 }) 50 51 t.Run("no modules are installed when default is false", func(t *testing.T) { 52 modules := &internal.ModulesDTO{} 53 modules.Default = ptr.Bool(false) 54 execTest(t, modules, givenKymaTemplateWithModules, "kyma-no-modules.yaml") 55 execTest(t, modules, givenKymaTemplateWithoutModules, "kyma-no-modules.yaml") 56 }) 57 58 t.Run("custom list of modules are installed when given custom list not empty", func(t *testing.T) { 59 modules := &internal.ModulesDTO{} 60 modules.List = make([]*internal.ModuleDTO, 0) 61 m1 := internal.ModuleDTO{ 62 Name: technicalNameBtpManager, 63 CustomResourcePolicy: internal.CreateAndDelete, 64 } 65 m2 := internal.ModuleDTO{ 66 Name: technicalNameKeda, 67 Channel: internal.Fast, 68 } 69 modules.List = append(modules.List, &m1, &m2) 70 execTest(t, modules, givenKymaTemplateWithModules, "kyma-with-keda-and-btp-operator.yaml") 71 execTest(t, modules, givenKymaTemplateWithoutModules, "kyma-with-keda-and-btp-operator.yaml") 72 }) 73 74 t.Run("custom list of modules are installed when given custom list not empty", func(t *testing.T) { 75 modules := &internal.ModulesDTO{} 76 modules.List = make([]*internal.ModuleDTO, 0) 77 m1 := internal.ModuleDTO{ 78 Name: technicalNameBtpManager, 79 Channel: internal.Fast, 80 CustomResourcePolicy: internal.CreateAndDelete, 81 } 82 modules.List = append(modules.List, &m1) 83 execTest(t, modules, givenKymaTemplateWithModules, "kyma-with-btp-operator.yaml") 84 execTest(t, modules, givenKymaTemplateWithoutModules, "kyma-with-btp-operator.yaml") 85 }) 86 87 t.Run("no modules are installed when given custom list is empty", func(t *testing.T) { 88 modules := &internal.ModulesDTO{} 89 modules.List = make([]*internal.ModuleDTO, 0) 90 execTest(t, modules, givenKymaTemplateWithModules, "kyma-no-modules.yaml") 91 execTest(t, modules, givenKymaTemplateWithoutModules, "kyma-no-modules.yaml") 92 }) 93 94 t.Run("default modules are installed when modules are empty", func(t *testing.T) { 95 execTest(t, &internal.ModulesDTO{}, givenKymaTemplateWithModules, defaultModules) 96 execTest(t, &internal.ModulesDTO{}, givenKymaTemplateWithoutModules, "kyma-no-modules.yaml") 97 }) 98 99 t.Run("default modules are installed when modules are not set", func(t *testing.T) { 100 execTest(t, nil, givenKymaTemplateWithModules, defaultModules) 101 execTest(t, nil, givenKymaTemplateWithoutModules, "kyma-no-modules.yaml") 102 }) 103 }