github.com/kyma-project/kyma-environment-broker@v0.0.1/internal/process/provisioning/create_runtime_without_kyma_test.go (about) 1 package provisioning 2 3 import ( 4 "fmt" 5 "reflect" 6 "testing" 7 8 "github.com/kyma-project/control-plane/components/provisioner/pkg/gqlschema" 9 "github.com/kyma-project/kyma-environment-broker/internal/broker" 10 provisionerAutomock "github.com/kyma-project/kyma-environment-broker/internal/provisioner/automock" 11 "github.com/kyma-project/kyma-environment-broker/internal/ptr" 12 "github.com/kyma-project/kyma-environment-broker/internal/storage" 13 "github.com/pivotal-cf/brokerapi/v8/domain" 14 "github.com/sirupsen/logrus" 15 "github.com/stretchr/testify/assert" 16 "github.com/stretchr/testify/mock" 17 ) 18 19 func TestCreateRuntimeWithoutKyma_Run(t *testing.T) { 20 // given 21 log := logrus.New() 22 memoryStorage := storage.NewMemoryStorage() 23 24 operation := fixOperationCreateRuntime(t, broker.GCPPlanID, "europe-west3") 25 operation.ShootDomain = "kyma.org" 26 err := memoryStorage.Operations().InsertOperation(operation) 27 assert.NoError(t, err) 28 29 err = memoryStorage.Instances().Insert(fixInstance()) 30 assert.NoError(t, err) 31 32 disabled := false 33 provisionerInput := fixProvisionerInput(disabled, false) 34 35 provisionerClient := &provisionerAutomock.Client{} 36 provisionerClient.On("ProvisionRuntime", globalAccountID, subAccountID, mock.MatchedBy( 37 func(input gqlschema.ProvisionRuntimeInput) bool { 38 return reflect.DeepEqual(input.RuntimeInput.Labels, provisionerInput.RuntimeInput.Labels) && 39 input.KymaConfig == nil && reflect.DeepEqual(input.ClusterConfig, provisionerInput.ClusterConfig) 40 }, 41 )).Return(gqlschema.OperationStatus{ 42 ID: ptr.String(provisionerOperationID), 43 Operation: "", 44 State: "", 45 Message: nil, 46 RuntimeID: ptr.String(runtimeID), 47 }, nil) 48 49 step := NewCreateRuntimeWithoutKymaStep(memoryStorage.Operations(), memoryStorage.RuntimeStates(), memoryStorage.Instances(), provisionerClient) 50 51 // when 52 entry := log.WithFields(logrus.Fields{"step": "TEST"}) 53 operation, repeat, err := step.Run(operation, entry) 54 55 // then 56 assert.NoError(t, err) 57 assert.Zero(t, repeat) 58 assert.Equal(t, provisionerOperationID, operation.ProvisionerOperationID) 59 60 instance, err := memoryStorage.Instances().GetByID(operation.InstanceID) 61 assert.NoError(t, err) 62 assert.Equal(t, instance.RuntimeID, runtimeID) 63 } 64 65 func TestCreateRuntimeWithoutKyma_RunWithEuAccess(t *testing.T) { 66 // given 67 log := logrus.New() 68 memoryStorage := storage.NewMemoryStorage() 69 70 operation := fixOperationCreateRuntimeWithPlatformRegion(t, broker.GCPPlanID, "europe-west3", "cf-ch20") 71 operation.ShootDomain = "kyma.org" 72 err := memoryStorage.Operations().InsertOperation(operation) 73 assert.NoError(t, err) 74 75 err = memoryStorage.Instances().Insert(fixInstance()) 76 assert.NoError(t, err) 77 78 disabled := false 79 provisionerInput := fixProvisionerInput(disabled, true) 80 81 provisionerClient := &provisionerAutomock.Client{} 82 provisionerClient.On("ProvisionRuntime", globalAccountID, subAccountID, mock.MatchedBy( 83 func(input gqlschema.ProvisionRuntimeInput) bool { 84 return reflect.DeepEqual(input.RuntimeInput.Labels, provisionerInput.RuntimeInput.Labels) && 85 input.KymaConfig == nil && reflect.DeepEqual(input.ClusterConfig, provisionerInput.ClusterConfig) 86 }, 87 )).Return(gqlschema.OperationStatus{ 88 ID: ptr.String(provisionerOperationID), 89 Operation: "", 90 State: "", 91 Message: nil, 92 RuntimeID: ptr.String(runtimeID), 93 }, nil) 94 95 step := NewCreateRuntimeWithoutKymaStep(memoryStorage.Operations(), memoryStorage.RuntimeStates(), memoryStorage.Instances(), provisionerClient) 96 97 // when 98 entry := log.WithFields(logrus.Fields{"step": "TEST"}) 99 operation, repeat, err := step.Run(operation, entry) 100 101 // then 102 assert.NoError(t, err) 103 assert.Zero(t, repeat) 104 assert.Equal(t, provisionerOperationID, operation.ProvisionerOperationID) 105 106 instance, err := memoryStorage.Instances().GetByID(operation.InstanceID) 107 assert.NoError(t, err) 108 assert.Equal(t, instance.RuntimeID, runtimeID) 109 } 110 111 func fixProvisionerInput(disabled bool, euAccess bool) gqlschema.ProvisionRuntimeInput { 112 administrator := "" 113 return gqlschema.ProvisionRuntimeInput{ 114 RuntimeInput: &gqlschema.RuntimeInput{ 115 Name: "dummy", 116 Description: nil, 117 Labels: gqlschema.Labels{ 118 "broker_instance_id": instanceID, 119 "global_subaccount_id": subAccountID, 120 "operator_grafanaUrl": "https://grafana.kyma.org", 121 }, 122 }, 123 ClusterConfig: &gqlschema.ClusterConfigInput{ 124 GardenerConfig: &gqlschema.GardenerConfigInput{ 125 Name: shootName, 126 KubernetesVersion: k8sVersion, 127 DiskType: ptr.String("pd-standard"), 128 VolumeSizeGb: ptr.Integer(50), 129 MachineType: "n2-standard-4", 130 Region: "europe-west3", 131 Provider: "gcp", 132 Purpose: &shootPurpose, 133 LicenceType: nil, 134 WorkerCidr: "10.250.0.0/22", 135 AutoScalerMin: 3, 136 AutoScalerMax: 20, 137 MaxSurge: 3, 138 MaxUnavailable: 0, 139 TargetSecret: "", 140 ControlPlaneFailureTolerance: ptr.String("zone"), 141 EnableKubernetesVersionAutoUpdate: ptr.Bool(autoUpdateKubernetesVersion), 142 EnableMachineImageVersionAutoUpdate: ptr.Bool(autoUpdateMachineImageVersion), 143 ProviderSpecificConfig: &gqlschema.ProviderSpecificInput{ 144 GcpConfig: &gqlschema.GCPProviderConfigInput{ 145 Zones: []string{"europe-west3-b", "europe-west3-c"}, 146 }, 147 }, 148 Seed: nil, 149 OidcConfig: &gqlschema.OIDCConfigInput{ 150 ClientID: "9bd05ed7-a930-44e6-8c79-e6defeb7dec9", 151 GroupsClaim: "groups", 152 IssuerURL: "https://kymatest.accounts400.ondemand.com", 153 SigningAlgs: []string{"RS256"}, 154 UsernameClaim: "sub", 155 UsernamePrefix: "-", 156 }, 157 DNSConfig: &gqlschema.DNSConfigInput{ 158 Domain: "kyma.org", 159 Providers: []*gqlschema.DNSProviderInput{ 160 { 161 DomainsInclude: []string{"devtest.kyma.ondemand.com"}, 162 Primary: true, 163 SecretName: "aws_dns_domain_secrets_test_intest", 164 Type: "route53_type_test", 165 }, 166 }, 167 }, 168 ShootNetworkingFilterDisabled: &disabled, 169 EuAccess: &euAccess, 170 }, 171 Administrators: []string{administrator}, 172 }, 173 KymaConfig: nil, 174 } 175 } 176 177 func TestCreateRuntimeWithoutKymaStep_RunWithBadRequestError(t *testing.T) { 178 // given 179 log := logrus.New() 180 memoryStorage := storage.NewMemoryStorage() 181 182 operation := fixOperationCreateRuntime(t, broker.AzurePlanID, "westeurope") 183 err := memoryStorage.Operations().InsertOperation(operation) 184 assert.NoError(t, err) 185 186 err = memoryStorage.Instances().Insert(fixInstance()) 187 assert.NoError(t, err) 188 189 provisionerClient := &provisionerAutomock.Client{} 190 provisionerClient.On("ProvisionRuntime", globalAccountID, subAccountID, mock.Anything).Return(gqlschema.OperationStatus{}, fmt.Errorf("some permanent error")) 191 192 step := NewCreateRuntimeWithoutKymaStep(memoryStorage.Operations(), memoryStorage.RuntimeStates(), memoryStorage.Instances(), provisionerClient) 193 194 // when 195 entry := log.WithFields(logrus.Fields{"step": "TEST"}) 196 operation, _, err = step.Run(operation, entry) 197 198 // then 199 assert.Equal(t, domain.Failed, operation.State) 200 }