How to use Execute method of v1 Package

Best Testkube code snippet using v1.Execute

applications_controller_test.go

Source:applications_controller_test.go Github

copy

Full Screen

...67 NewApplicationController(68 func(client kubernetes.Interface, rr v1.RadixRegistration) bool {69 return false70 }))71 responseChannel := controllerTestUtils.ExecuteRequest("GET", "/api/v1/applications")72 response := <-responseChannel73 applications := make([]applicationModels.ApplicationSummary, 0)74 controllertest.GetResponseBody(response, &applications)75 assert.Equal(t, 0, len(applications))76 })77 t.Run("access to single app", func(t *testing.T) {78 controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, NewApplicationController(79 func(client kubernetes.Interface, rr v1.RadixRegistration) bool {80 return rr.GetName() == "my-second-app"81 }))82 responseChannel := controllerTestUtils.ExecuteRequest("GET", "/api/v1/applications")83 response := <-responseChannel84 applications := make([]applicationModels.ApplicationSummary, 0)85 controllertest.GetResponseBody(response, &applications)86 assert.Equal(t, 1, len(applications))87 })88 t.Run("access to all app", func(t *testing.T) {89 controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, NewApplicationController(90 func(client kubernetes.Interface, rr v1.RadixRegistration) bool {91 return true92 }))93 responseChannel := controllerTestUtils.ExecuteRequest("GET", "/api/v1/applications")94 response := <-responseChannel95 applications := make([]applicationModels.ApplicationSummary, 0)96 controllertest.GetResponseBody(response, &applications)97 assert.Equal(t, 2, len(applications))98 })99}100func TestGetApplications_WithFilterOnSSHRepo_Filter(t *testing.T) {101 // Setup102 commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest()103 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().104 WithCloneURL("git@github.com:Equinor/my-app.git"))105 // Test106 t.Run("matching repo", func(t *testing.T) {107 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications?sshRepo=%s", url.QueryEscape("git@github.com:Equinor/my-app.git")))108 response := <-responseChannel109 applications := make([]applicationModels.ApplicationSummary, 0)110 controllertest.GetResponseBody(response, &applications)111 assert.Equal(t, 1, len(applications))112 })113 t.Run("unmatching repo", func(t *testing.T) {114 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications?sshRepo=%s", url.QueryEscape("git@github.com:Equinor/my-app2.git")))115 response := <-responseChannel116 applications := make([]*applicationModels.ApplicationSummary, 0)117 controllertest.GetResponseBody(response, &applications)118 assert.Equal(t, 0, len(applications))119 })120 t.Run("no filter", func(t *testing.T) {121 responseChannel := controllerTestUtils.ExecuteRequest("GET", "/api/v1/applications")122 response := <-responseChannel123 applications := make([]*applicationModels.ApplicationSummary, 0)124 controllertest.GetResponseBody(response, &applications)125 assert.Equal(t, 1, len(applications))126 })127}128func TestSearchApplications(t *testing.T) {129 // Setup130 commonTestUtils, _, kubeclient, radixclient, _, secretproviderclient := setupTest()131 appNames := []string{"app-1", "app-2"}132 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().WithName(appNames[0]))133 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().WithName(appNames[1]))134 app2Job1Started, _ := radixutils.ParseTimestamp("2018-11-12T12:30:14Z")135 createRadixJob(commonTestUtils, appNames[1], "app-2-job-1", app2Job1Started)136 controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, NewApplicationController(137 func(client kubernetes.Interface, rr v1.RadixRegistration) bool {138 return true139 }))140 // Tests141 t.Run("search for "+appNames[0], func(t *testing.T) {142 searchParam := applicationModels.ApplicationsSearchRequest{Names: []string{appNames[0]}}143 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications/_search", &searchParam)144 response := <-responseChannel145 applications := make([]applicationModels.ApplicationSummary, 0)146 controllertest.GetResponseBody(response, &applications)147 assert.Equal(t, 1, len(applications))148 assert.Equal(t, appNames[0], applications[0].Name)149 })150 t.Run("search for both apps", func(t *testing.T) {151 searchParam := applicationModels.ApplicationsSearchRequest{Names: appNames}152 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications/_search", &searchParam)153 response := <-responseChannel154 applications := make([]applicationModels.ApplicationSummary, 0)155 controllertest.GetResponseBody(response, &applications)156 assert.Equal(t, 2, len(applications))157 })158 t.Run("empty appname list", func(t *testing.T) {159 searchParam := applicationModels.ApplicationsSearchRequest{Names: []string{}}160 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications/_search", &searchParam)161 response := <-responseChannel162 applications := make([]applicationModels.ApplicationSummary, 0)163 controllertest.GetResponseBody(response, &applications)164 assert.Equal(t, 0, len(applications))165 })166 t.Run("search for "+appNames[1]+" - with includeFields", func(t *testing.T) {167 searchParam := applicationModels.ApplicationsSearchRequest{168 Names: []string{appNames[1]},169 IncludeFields: applicationModels.ApplicationSearchIncludeFields{170 JobSummary: true,171 },172 }173 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications/_search", &searchParam)174 response := <-responseChannel175 applications := make([]applicationModels.ApplicationSummary, 0)176 controllertest.GetResponseBody(response, &applications)177 assert.Equal(t, 1, len(applications))178 assert.Equal(t, appNames[1], applications[0].Name)179 assert.NotNil(t, applications[0].LatestJob)180 })181 t.Run("search for "+appNames[0]+" - no access", func(t *testing.T) {182 controllerTestUtils := controllertest.NewTestUtils(kubeclient, radixclient, secretproviderclient, NewApplicationController(183 func(client kubernetes.Interface, rr v1.RadixRegistration) bool {184 return false185 }))186 searchParam := applicationModels.ApplicationsSearchRequest{Names: []string{appNames[0]}}187 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications/_search", &searchParam)188 response := <-responseChannel189 applications := make([]applicationModels.ApplicationSummary, 0)190 controllertest.GetResponseBody(response, &applications)191 assert.Equal(t, 0, len(applications))192 })193}194func TestSearchApplications_WithJobs_ShouldOnlyHaveLatest(t *testing.T) {195 // Setup196 commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest()197 appNames := []string{"app-1", "app-2", "app-3"}198 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().199 WithName(appNames[0]))200 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().201 WithName(appNames[1]))202 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().203 WithName(appNames[2]))204 commontest.CreateAppNamespace(kubeclient, appNames[0])205 commontest.CreateAppNamespace(kubeclient, appNames[1])206 commontest.CreateAppNamespace(kubeclient, appNames[2])207 app1Job1Started, _ := radixutils.ParseTimestamp("2018-11-12T11:45:26Z")208 app2Job1Started, _ := radixutils.ParseTimestamp("2018-11-12T12:30:14Z")209 app2Job2Started, _ := radixutils.ParseTimestamp("2018-11-20T09:00:00Z")210 app2Job3Started, _ := radixutils.ParseTimestamp("2018-11-20T09:00:01Z")211 createRadixJob(commonTestUtils, appNames[0], "app-1-job-1", app1Job1Started)212 createRadixJob(commonTestUtils, appNames[1], "app-2-job-1", app2Job1Started)213 createRadixJob(commonTestUtils, appNames[1], "app-2-job-2", app2Job2Started)214 createRadixJob(commonTestUtils, appNames[1], "app-2-job-3", app2Job3Started)215 // Test216 searchParam := applicationModels.ApplicationsSearchRequest{217 Names: appNames,218 IncludeFields: applicationModels.ApplicationSearchIncludeFields{219 JobSummary: true,220 },221 }222 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications/_search", &searchParam)223 response := <-responseChannel224 applications := make([]*applicationModels.ApplicationSummary, 0)225 controllertest.GetResponseBody(response, &applications)226 for _, application := range applications {227 if strings.EqualFold(application.Name, appNames[0]) {228 assert.NotNil(t, application.LatestJob)229 assert.Equal(t, "app-1-job-1", application.LatestJob.Name)230 } else if strings.EqualFold(application.Name, appNames[1]) {231 assert.NotNil(t, application.LatestJob)232 assert.Equal(t, "app-2-job-3", application.LatestJob.Name)233 } else if strings.EqualFold(application.Name, appNames[2]) {234 assert.Nil(t, application.LatestJob)235 }236 }237}238func TestCreateApplication_NoName_ValidationError(t *testing.T) {239 // Setup240 _, controllerTestUtils, _, _, _, _ := setupTest()241 // Test242 parameters := AnApplicationRegistration().withName("").Build()243 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)244 response := <-responseChannel245 assert.Equal(t, http.StatusBadRequest, response.Code)246 errorResponse, _ := controllertest.GetErrorResponse(response)247 assert.Equal(t, "Error: app name cannot be empty", errorResponse.Message)248}249func TestCreateApplication_WhenRepoIsNotSet_DoNotGenerateDeployKey(t *testing.T) {250 // Setup251 _, controllerTestUtils, _, _, _, _ := setupTest()252 // Test253 parameters := AnApplicationRegistration().withRepository("").Build()254 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)255 response := <-responseChannel256 application := applicationModels.ApplicationRegistration{}257 controllertest.GetResponseBody(response, &application)258 assert.Equal(t, "", application.PublicKey)259}260func TestCreateApplication_WhenRepoIsSetAnDeployKeyIsNot_GenerateDeployKey(t *testing.T) {261 // Setup262 _, controllerTestUtils, _, _, _, _ := setupTest()263 // Test264 parameters := AnApplicationRegistration().265 withName("any-name-1").266 withRepository("https://github.com/Equinor/any-repo").267 Build()268 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)269 response := <-responseChannel270 application := applicationModels.ApplicationRegistration{}271 controllertest.GetResponseBody(response, &application)272 assert.NotEmpty(t, application.PublicKey)273}274func TestCreateApplication_WhenOnlyOnePartOfDeployKeyIsSet_ReturnError(t *testing.T) {275 // Setup276 _, controllerTestUtils, _, _, _, _ := setupTest()277 // Test278 parameters := AnApplicationRegistration().279 withName("any-name-2").280 withRepository("https://github.com/Equinor/any-repo").281 withPublicKey("Any public key").282 Build()283 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)284 response := <-responseChannel285 assert.Equal(t, http.StatusBadRequest, response.Code)286 errorResponse, _ := controllertest.GetErrorResponse(response)287 expectedError := applicationModels.OnePartOfDeployKeyIsNotAllowed()288 assert.Equal(t, (expectedError.(*radixhttp.Error)).Message, errorResponse.Message)289 parameters = AnApplicationRegistration().290 withName("any-name-2").291 withRepository("https://github.com/Equinor/any-repo").292 withPrivateKey("Any private key").293 Build()294 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)295 response = <-responseChannel296 assert.Equal(t, http.StatusBadRequest, response.Code)297 errorResponse, _ = controllertest.GetErrorResponse(response)298 expectedError = applicationModels.OnePartOfDeployKeyIsNotAllowed()299 assert.Equal(t, (expectedError.(*radixhttp.Error)).Message, errorResponse.Message)300}301func TestCreateApplication_WhenDeployKeyIsSet_DoNotGenerateDeployKey(t *testing.T) {302 // Setup303 _, controllerTestUtils, _, _, _, _ := setupTest()304 // Test305 parameters := AnApplicationRegistration().306 withName("any-name-2").307 withRepository("https://github.com/Equinor/any-repo").308 withPublicKey("Any public key").309 withPrivateKey("Any private key").310 Build()311 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)312 response := <-responseChannel313 application := applicationModels.ApplicationRegistration{}314 controllertest.GetResponseBody(response, &application)315 assert.Equal(t, "Any public key", application.PublicKey)316}317func TestCreateApplication_WhenOwnerIsNotSet_ReturnError(t *testing.T) {318 // Setup319 _, controllerTestUtils, _, _, _, _ := setupTest()320 // Test321 parameters := AnApplicationRegistration().322 withName("any-name-2").323 withRepository("https://github.com/Equinor/any-repo").324 withPublicKey("Any public key").325 withPrivateKey("Any private key").326 withOwner("").327 Build()328 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)329 response := <-responseChannel330 assert.Equal(t, http.StatusBadRequest, response.Code)331 errorResponse, _ := controllertest.GetErrorResponse(response)332 expectedError := radixvalidators.InvalidEmailError("owner", "")333 assert.Equal(t, fmt.Sprintf("Error: %v", expectedError), errorResponse.Message)334}335func TestCreateApplication_WhenConfigBranchIsNotSet_ReturnError(t *testing.T) {336 // Setup337 _, controllerTestUtils, _, _, _, _ := setupTest()338 // Test339 parameters := AnApplicationRegistration().340 withName("any-name").341 withRepository("https://github.com/Equinor/any-repo").342 withPublicKey("Any public key").343 withPrivateKey("Any private key").344 withConfigBranch("").345 Build()346 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)347 response := <-responseChannel348 assert.Equal(t, http.StatusBadRequest, response.Code)349 errorResponse, _ := controllertest.GetErrorResponse(response)350 expectedError := radixvalidators.ResourceNameCannotBeEmptyError("branch name")351 assert.Equal(t, fmt.Sprintf("Error: %v", expectedError), errorResponse.Message)352}353func TestCreateApplication_WhenConfigBranchIsInvalid_ReturnError(t *testing.T) {354 // Setup355 _, controllerTestUtils, _, _, _, _ := setupTest()356 // Test357 configBranch := "main.."358 parameters := AnApplicationRegistration().359 withName("any-name").360 withRepository("https://github.com/Equinor/any-repo").361 withPublicKey("Any public key").362 withPrivateKey("Any private key").363 withConfigBranch(configBranch).364 Build()365 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)366 response := <-responseChannel367 assert.Equal(t, http.StatusBadRequest, response.Code)368 errorResponse, _ := controllertest.GetErrorResponse(response)369 expectedError := radixvalidators.InvalidConfigBranchName(configBranch)370 assert.Equal(t, fmt.Sprintf("Error: %v", expectedError), errorResponse.Message)371}372func TestGetApplication_ShouldNeverReturnPrivatePartOfDeployKey(t *testing.T) {373 // Setup374 commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest()375 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().376 WithName("some-app").377 WithPublicKey("some-public-key").378 WithPrivateKey("some-private-key"))379 // Test380 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "some-app"))381 response := <-responseChannel382 application := applicationModels.Application{}383 controllertest.GetResponseBody(response, &application)384 assert.Equal(t, "", application.Registration.PrivateKey)385}386func TestCreateApplication_DuplicateRepo_ShouldFailAsWeCannotHandleThatSituation(t *testing.T) {387 // Setup388 _, controllerTestUtils, _, _, _, _ := setupTest()389 parameters := AnApplicationRegistration().390 withName("any-name").391 withRepository("https://github.com/Equinor/any-repo").392 Build()393 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)394 <-responseChannel395 // Test396 parameters = AnApplicationRegistration().397 withName("any-other-name").398 withRepository("https://github.com/Equinor/any-repo").399 Build()400 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)401 response := <-responseChannel402 assert.Equal(t, http.StatusBadRequest, response.Code)403 errorResponse, _ := controllertest.GetErrorResponse(response)404 assert.Equal(t, "Error: repository is in use by any-name", errorResponse.Message)405}406func TestGetApplication_AllFieldsAreSet(t *testing.T) {407 // Setup408 _, controllerTestUtils, _, _, _, _ := setupTest()409 parameters := AnApplicationRegistration().410 withName("any-name").411 withRepository("https://github.com/Equinor/any-repo").412 withSharedSecret("Any secret").413 withAdGroups([]string{"a6a3b81b-34gd-sfsf-saf2-7986371ea35f"}).414 withOwner("AN_OWNER@equinor.com").415 withWBS("A.BCD.00.999").416 withConfigBranch("abranch").417 Build()418 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)419 <-responseChannel420 // Test421 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))422 response := <-responseChannel423 application := applicationModels.Application{}424 controllertest.GetResponseBody(response, &application)425 assert.Equal(t, "https://github.com/Equinor/any-repo", application.Registration.Repository)426 assert.Equal(t, "Any secret", application.Registration.SharedSecret)427 assert.Equal(t, []string{"a6a3b81b-34gd-sfsf-saf2-7986371ea35f"}, application.Registration.AdGroups)428 assert.Equal(t, "AN_OWNER@equinor.com", application.Registration.Owner)429 assert.Equal(t, "not-existing-test-radix-email@equinor.com", application.Registration.Creator)430 assert.Equal(t, "A.BCD.00.999", application.Registration.WBS)431 assert.Equal(t, "abranch", application.Registration.ConfigBranch)432}433func TestGetApplication_WithJobs(t *testing.T) {434 // Setup435 commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest()436 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().437 WithName("any-name"))438 commontest.CreateAppNamespace(kubeclient, "any-name")439 app1Job1Started, _ := radixutils.ParseTimestamp("2018-11-12T11:45:26Z")440 app1Job2Started, _ := radixutils.ParseTimestamp("2018-11-12T12:30:14Z")441 app1Job3Started, _ := radixutils.ParseTimestamp("2018-11-20T09:00:00Z")442 createRadixJob(commonTestUtils, "any-name", "any-name-job-1", app1Job1Started)443 createRadixJob(commonTestUtils, "any-name", "any-name-job-2", app1Job2Started)444 createRadixJob(commonTestUtils, "any-name", "any-name-job-3", app1Job3Started)445 // Test446 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))447 response := <-responseChannel448 application := applicationModels.Application{}449 controllertest.GetResponseBody(response, &application)450 assert.Equal(t, 3, len(application.Jobs))451}452func TestGetApplication_WithEnvironments(t *testing.T) {453 // Setup454 commonTestUtils, controllerTestUtils, _, radix, _, _ := setupTest()455 anyAppName := "any-app"456 anyOrphanedEnvironment := "feature"457 commonTestUtils.ApplyRegistration(builders.458 NewRegistrationBuilder().459 WithName(anyAppName))460 commonTestUtils.ApplyApplication(builders.461 NewRadixApplicationBuilder().462 WithAppName(anyAppName).463 WithEnvironment("dev", "master").464 WithEnvironment("prod", "release"))465 commonTestUtils.ApplyDeployment(builders.466 NewDeploymentBuilder().467 WithAppName(anyAppName).468 WithEnvironment("dev").469 WithImageTag("someimageindev"))470 commonTestUtils.ApplyDeployment(builders.471 NewDeploymentBuilder().472 WithAppName(anyAppName).473 WithEnvironment(anyOrphanedEnvironment).474 WithImageTag("someimageinfeature"))475 re, _ := commonTestUtils.ApplyEnvironment(builders.476 NewEnvironmentBuilder().477 WithAppLabel().478 WithAppName(anyAppName).479 WithEnvironmentName(anyOrphanedEnvironment))480 re.Status.Orphaned = true481 radix.RadixV1().RadixEnvironments().Update(context.TODO(), re, metav1.UpdateOptions{})482 // Test483 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", anyAppName))484 response := <-responseChannel485 application := applicationModels.Application{}486 controllertest.GetResponseBody(response, &application)487 assert.Equal(t, 3, len(application.Environments))488 for _, environment := range application.Environments {489 if strings.EqualFold(environment.Name, "dev") {490 assert.Equal(t, environmentModels.Consistent.String(), environment.Status)491 assert.NotNil(t, environment.ActiveDeployment)492 } else if strings.EqualFold(environment.Name, "prod") {493 assert.Equal(t, environmentModels.Pending.String(), environment.Status)494 assert.Nil(t, environment.ActiveDeployment)495 } else if strings.EqualFold(environment.Name, anyOrphanedEnvironment) {496 assert.Equal(t, environmentModels.Orphan.String(), environment.Status)497 assert.NotNil(t, environment.ActiveDeployment)498 }499 }500}501func TestUpdateApplication_DuplicateRepo_ShouldFailAsWeCannotHandleThatSituation(t *testing.T) {502 // Setup503 _, controllerTestUtils, _, _, _, _ := setupTest()504 parameters := AnApplicationRegistration().505 withName("any-name").506 withRepository("https://github.com/Equinor/any-repo").507 Build()508 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)509 <-responseChannel510 parameters = AnApplicationRegistration().511 withName("any-other-name").512 withRepository("https://github.com/Equinor/any-other-repo").513 Build()514 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)515 <-responseChannel516 // Test517 parameters = AnApplicationRegistration().518 withName("any-other-name").519 withRepository("https://github.com/Equinor/any-repo").520 Build()521 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-other-name"), parameters)522 response := <-responseChannel523 assert.Equal(t, http.StatusBadRequest, response.Code)524 errorResponse, _ := controllertest.GetErrorResponse(response)525 assert.Equal(t, "Error: repository is in use by any-name", errorResponse.Message)526}527func TestUpdateApplication_MismatchingNameOrNotExists_ShouldFailAsIllegalOperation(t *testing.T) {528 // Setup529 _, controllerTestUtils, _, _, _, _ := setupTest()530 parameters := AnApplicationRegistration().withName("any-name").Build()531 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)532 <-responseChannel533 // Test534 parameters = AnApplicationRegistration().withName("any-name").Build()535 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "another-name"), parameters)536 response := <-responseChannel537 assert.Equal(t, http.StatusNotFound, response.Code)538 errorResponse, _ := controllertest.GetErrorResponse(response)539 assert.Equal(t, controllertest.AppNotFoundErrorMsg("another-name"), errorResponse.Message)540 parameters = AnApplicationRegistration().withName("another-name").Build()541 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-name"), parameters)542 response = <-responseChannel543 assert.Equal(t, http.StatusBadRequest, response.Code)544 errorResponse, _ = controllertest.GetErrorResponse(response)545 assert.Equal(t, "App name any-name does not correspond with application name another-name", errorResponse.Message)546 parameters = AnApplicationRegistration().withName("another-name").Build()547 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "another-name"), parameters)548 response = <-responseChannel549 assert.Equal(t, http.StatusNotFound, response.Code)550}551func TestUpdateApplication_AbleToSetAnySpecField(t *testing.T) {552 // Setup553 _, controllerTestUtils, _, _, _, _ := setupTest()554 builder := AnApplicationRegistration().555 withName("any-name").556 withRepository("https://github.com/Equinor/a-repo").557 withSharedSecret("").558 withPublicKey("")559 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", builder.Build())560 <-responseChannel561 // Test Repository562 newRepository := "https://github.com/Equinor/any-repo"563 builder = builder.564 withRepository(newRepository)565 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-name"), builder.Build())566 response := <-responseChannel567 application := applicationModels.ApplicationRegistration{}568 controllertest.GetResponseBody(response, &application)569 assert.Equal(t, newRepository, application.Repository)570 // Test SharedSecret571 newSharedSecret := "Any shared secret"572 builder = builder.573 withSharedSecret(newSharedSecret)574 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-name"), builder.Build())575 response = <-responseChannel576 controllertest.GetResponseBody(response, &application)577 assert.Equal(t, newSharedSecret, application.SharedSecret)578 // Test PublicKey579 newPublicKey := "Any public key"580 builder = builder.581 withPublicKey(newPublicKey)582 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-name"), builder.Build())583 response = <-responseChannel584 controllertest.GetResponseBody(response, &application)585 assert.Equal(t, newPublicKey, application.PublicKey)586 // Test WBS587 newWbs := "new.wbs.code"588 builder = builder.589 withWBS(newWbs)590 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-name"), builder.Build())591 response = <-responseChannel592 controllertest.GetResponseBody(response, &application)593 assert.Equal(t, newWbs, application.WBS)594 // Test ConfigBranch595 newConfigBranch := "newcfgbranch"596 builder = builder.597 withConfigBranch(newConfigBranch)598 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PUT", fmt.Sprintf("/api/v1/applications/%s", "any-name"), builder.Build())599 response = <-responseChannel600 controllertest.GetResponseBody(response, &application)601 assert.Equal(t, newConfigBranch, application.ConfigBranch)602}603func TestModifyApplication_AbleToSetField(t *testing.T) {604 // Setup605 _, controllerTestUtils, _, _, _, _ := setupTest()606 builder := AnApplicationRegistration().607 withName("any-name").608 withRepository("https://github.com/Equinor/a-repo").609 withSharedSecret("").610 withPublicKey("").611 withAdGroups([]string{"a5dfa635-dc00-4a28-9ad9-9e7f1e56919d"}).612 withOwner("AN_OWNER@equinor.com").613 withWBS("T.O123A.AZ.45678").614 withConfigBranch("main1")615 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", builder.Build())616 <-responseChannel617 // Test618 anyNewAdGroup := []string{"98765432-dc00-4a28-9ad9-9e7f1e56919d"}619 patchRequest := applicationModels.ApplicationPatchRequest{620 AdGroups: &anyNewAdGroup,621 }622 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", "any-name"), patchRequest)623 <-responseChannel624 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))625 response := <-responseChannel626 application := applicationModels.Application{}627 controllertest.GetResponseBody(response, &application)628 assert.Equal(t, anyNewAdGroup, application.Registration.AdGroups)629 assert.Equal(t, "AN_OWNER@equinor.com", application.Registration.Owner)630 assert.Equal(t, "T.O123A.AZ.45678", application.Registration.WBS)631 assert.Equal(t, "main1", application.Registration.ConfigBranch)632 // Test633 anyNewOwner := "A_NEW_OWNER@equinor.com"634 patchRequest = applicationModels.ApplicationPatchRequest{635 Owner: &anyNewOwner,636 }637 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", "any-name"), patchRequest)638 <-responseChannel639 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))640 response = <-responseChannel641 controllertest.GetResponseBody(response, &application)642 assert.Equal(t, anyNewAdGroup, application.Registration.AdGroups)643 assert.Equal(t, anyNewOwner, application.Registration.Owner)644 // Test645 anyNewAdGroup = []string{}646 patchRequest = applicationModels.ApplicationPatchRequest{647 AdGroups: &anyNewAdGroup,648 }649 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", "any-name"), patchRequest)650 <-responseChannel651 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))652 response = <-responseChannel653 controllertest.GetResponseBody(response, &application)654 assert.Nil(t, application.Registration.AdGroups)655 assert.Equal(t, anyNewOwner, application.Registration.Owner)656 // Test657 anyNewWBS := "A.BCD.00.999"658 patchRequest = applicationModels.ApplicationPatchRequest{659 WBS: &anyNewWBS,660 }661 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", "any-name"), patchRequest)662 <-responseChannel663 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))664 response = <-responseChannel665 controllertest.GetResponseBody(response, &application)666 assert.Equal(t, anyNewWBS, application.Registration.WBS)667 // Test ConfigBranch668 anyNewConfigBranch := "main2"669 patchRequest = applicationModels.ApplicationPatchRequest{670 ConfigBranch: &anyNewConfigBranch,671 }672 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", "any-name"), patchRequest)673 <-responseChannel674 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))675 response = <-responseChannel676 controllertest.GetResponseBody(response, &application)677 assert.Equal(t, anyNewConfigBranch, application.Registration.ConfigBranch)678}679func TestModifyApplication_AbleToUpdateRepository(t *testing.T) {680 // Setup681 _, controllerTestUtils, _, _, _, _ := setupTest()682 builder := AnApplicationRegistration().683 withName("any-name").684 withRepository("https://github.com/Equinor/a-repo")685 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", builder.Build())686 <-responseChannel687 // Test688 anyNewRepo := "https://github.com/repo/updated-version"689 patchRequest := applicationModels.ApplicationPatchRequest{690 Repository: &anyNewRepo,691 }692 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", "any-name"), patchRequest)693 <-responseChannel694 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-name"))695 response := <-responseChannel696 application := applicationModels.Application{}697 controllertest.GetResponseBody(response, &application)698 assert.Equal(t, anyNewRepo, application.Registration.Repository)699}700func TestModifyApplication_ConfigBranchSetToFallbackHack(t *testing.T) {701 // Setup702 appName := "any-name"703 _, controllerTestUtils, _, radixClient, _, _ := setupTest()704 rr := builders.ARadixRegistration().705 WithName(appName).706 WithConfigBranch("")707 radixClient.RadixV1().RadixRegistrations().Create(context.TODO(), rr.BuildRR(), metav1.CreateOptions{})708 // Test709 anyNewRepo := "https://github.com/repo/updated-version"710 patchRequest := applicationModels.ApplicationPatchRequest{711 Repository: &anyNewRepo,712 }713 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("PATCH", fmt.Sprintf("/api/v1/applications/%s", appName), patchRequest)714 <-responseChannel715 responseChannel = controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", appName))716 response := <-responseChannel717 application := applicationModels.Application{}718 controllertest.GetResponseBody(response, &application)719 assert.Equal(t, applicationconfig.ConfigBranchFallback, application.Registration.ConfigBranch)720}721func TestHandleTriggerPipeline_ForNonMappedAndMappedAndMagicBranchEnvironment_JobIsNotCreatedForUnmapped(t *testing.T) {722 // Setup723 commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest()724 anyAppName := "any-app"725 configBranch := "magic"726 rr := builders.ARadixRegistration().WithConfigBranch(configBranch)727 commonTestUtils.ApplyApplication(builders.728 ARadixApplication().729 WithRadixRegistration(rr).730 WithAppName(anyAppName).731 WithEnvironment("dev", "dev").732 WithEnvironment("prod", "release"),733 )734 // Test735 unmappedBranch := "feature"736 parameters := applicationModels.PipelineParametersBuild{Branch: unmappedBranch}737 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", anyAppName, v1.BuildDeploy), parameters)738 response := <-responseChannel739 assert.Equal(t, http.StatusBadRequest, response.Code)740 errorResponse, _ := controllertest.GetErrorResponse(response)741 expectedError := applicationModels.UnmatchedBranchToEnvironment(unmappedBranch)742 assert.Equal(t, (expectedError.(*radixhttp.Error)).Message, errorResponse.Message)743 // Mapped branch should start job744 parameters = applicationModels.PipelineParametersBuild{Branch: "dev"}745 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", anyAppName, v1.BuildDeploy), parameters)746 response = <-responseChannel747 assert.Equal(t, http.StatusOK, response.Code)748 // Magic branch should start job, even if it is not mapped749 parameters = applicationModels.PipelineParametersBuild{Branch: configBranch}750 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", anyAppName, v1.BuildDeploy), parameters)751 response = <-responseChannel752 assert.Equal(t, http.StatusOK, response.Code)753}754func TestHandleTriggerPipeline_ExistingAndNonExistingApplication_JobIsCreatedForExisting(t *testing.T) {755 // Setup756 _, controllerTestUtils, _, _, _, _ := setupTest()757 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", AnApplicationRegistration().758 withName("any-app").withConfigBranch("maincfg").Build())759 <-responseChannel760 // Test761 const pushCommitID = "4faca8595c5283a9d0f17a623b9255a0d9866a2e"762 parameters := applicationModels.PipelineParametersBuild{Branch: "master", CommitID: pushCommitID}763 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", "another-app", v1.BuildDeploy), parameters)764 response := <-responseChannel765 assert.Equal(t, http.StatusNotFound, response.Code)766 errorResponse, _ := controllertest.GetErrorResponse(response)767 assert.Equal(t, controllertest.AppNotFoundErrorMsg("another-app"), errorResponse.Message)768 parameters = applicationModels.PipelineParametersBuild{Branch: "", CommitID: pushCommitID}769 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", "any-app", v1.BuildDeploy), parameters)770 response = <-responseChannel771 assert.Equal(t, http.StatusBadRequest, response.Code)772 errorResponse, _ = controllertest.GetErrorResponse(response)773 expectedError := applicationModels.AppNameAndBranchAreRequiredForStartingPipeline()774 assert.Equal(t, (expectedError.(*radixhttp.Error)).Message, errorResponse.Message)775 parameters = applicationModels.PipelineParametersBuild{Branch: "maincfg", CommitID: pushCommitID}776 responseChannel = controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", "any-app", v1.BuildDeploy), parameters)777 response = <-responseChannel778 assert.Equal(t, http.StatusOK, response.Code)779 jobSummary := jobModels.JobSummary{}780 controllertest.GetResponseBody(response, &jobSummary)781 assert.Equal(t, "any-app", jobSummary.AppName)782 assert.Equal(t, "maincfg", jobSummary.Branch)783 assert.Equal(t, pushCommitID, jobSummary.CommitID)784}785func TestHandleTriggerPipeline_Deploy_JobHasCorrectParameters(t *testing.T) {786 _, controllerTestUtils, _, radixclient, _, _ := setupTest()787 appName := "an-app"788 parameters := applicationModels.PipelineParametersDeploy{789 ToEnvironment: "target",790 }791 <-controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", AnApplicationRegistration().withName(appName).Build())792 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", appName, v1.Deploy), parameters)793 <-responseChannel794 appNamespace := fmt.Sprintf("%s-app", appName)795 jobs, _ := getJobsInNamespace(radixclient, appNamespace)796 assert.Equal(t, jobs[0].Spec.Deploy.ToEnvironment, "target")797}798func TestHandleTriggerPipeline_Promote_JobHasCorrectParameters(t *testing.T) {799 _, controllerTestUtils, _, radixclient, _, _ := setupTest()800 appName := "an-app"801 parameters := applicationModels.PipelineParametersPromote{802 FromEnvironment: "origin",803 ToEnvironment: "target",804 DeploymentName: "a-deployment",805 }806 <-controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", AnApplicationRegistration().withName(appName).Build())807 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/pipelines/%s", appName, v1.Promote), parameters)808 <-responseChannel809 appNamespace := fmt.Sprintf("%s-app", appName)810 jobs, _ := getJobsInNamespace(radixclient, appNamespace)811 assert.Equal(t, jobs[0].Spec.Promote.FromEnvironment, "origin")812 assert.Equal(t, jobs[0].Spec.Promote.ToEnvironment, "target")813 assert.Equal(t, jobs[0].Spec.Promote.DeploymentName, "a-deployment")814}815func TestIsDeployKeyValid(t *testing.T) {816 // Setup817 commonTestUtils, controllerTestUtils, kubeclient, _, _, _ := setupTest()818 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().819 WithName("some-app").820 WithPublicKey("some-public-key").821 WithPrivateKey("some-private-key"))822 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().823 WithName("some-app-missing-key").824 WithPublicKey("").825 WithPrivateKey(""))826 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().827 WithName("some-app-missing-repository").828 WithCloneURL(""))829 // Tests830 t.Run("missing rr", func(t *testing.T) {831 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deploykey-valid", "some-nonexisting-app"))832 response := <-responseChannel833 assert.Equal(t, http.StatusNotFound, response.Code)834 })835 t.Run("missing repository", func(t *testing.T) {836 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deploykey-valid", "some-app-missing-repository"))837 response := <-responseChannel838 assert.Equal(t, http.StatusBadRequest, response.Code)839 errorResponse, _ := controllertest.GetErrorResponse(response)840 assert.Equal(t, "Clone URL is missing", errorResponse.Message)841 })842 t.Run("missing key", func(t *testing.T) {843 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deploykey-valid", "some-app-missing-key"))844 response := <-responseChannel845 assert.Equal(t, http.StatusBadRequest, response.Code)846 errorResponse, _ := controllertest.GetErrorResponse(response)847 assert.Equal(t, "Deploy key is missing", errorResponse.Message)848 })849 t.Run("valid key", func(t *testing.T) {850 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deploykey-valid", "some-app"))851 setStatusOfCloneJob(kubeclient, "some-app-app", true)852 response := <-responseChannel853 assert.Equal(t, http.StatusOK, response.Code)854 })855 t.Run("invalid key", func(t *testing.T) {856 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/deploykey-valid", "some-app"))857 setStatusOfCloneJob(kubeclient, "some-app-app", false)858 response := <-responseChannel859 assert.Equal(t, http.StatusBadRequest, response.Code)860 errorResponse, _ := controllertest.GetErrorResponse(response)861 assert.Equal(t, "Deploy key was invalid", errorResponse.Message)862 })863}864func TestDeleteApplication_ApplicationIsDeleted(t *testing.T) {865 // Setup866 _, controllerTestUtils, _, _, _, _ := setupTest()867 parameters := AnApplicationRegistration().868 withName("any-name").Build()869 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)870 <-responseChannel871 // Test872 responseChannel = controllerTestUtils.ExecuteRequest("DELETE", fmt.Sprintf("/api/v1/applications/%s", "any-non-existing"))873 response := <-responseChannel874 assert.Equal(t, http.StatusNotFound, response.Code)875 responseChannel = controllerTestUtils.ExecuteRequest("DELETE", fmt.Sprintf("/api/v1/applications/%s", "any-name"))876 response = <-responseChannel877 assert.Equal(t, http.StatusOK, response.Code)878 // Application should no longer exist879 responseChannel = controllerTestUtils.ExecuteRequest("DELETE", fmt.Sprintf("/api/v1/applications/%s", "any-name"))880 response = <-responseChannel881 assert.Equal(t, http.StatusNotFound, response.Code)882}883func TestGetApplication_WithAppAlias_ContainsAppAlias(t *testing.T) {884 // Setup885 commonTestUtils, controllerTestUtils, client, radixclient, promclient, secretproviderclient := setupTest()886 utils.ApplyDeploymentWithSync(client, radixclient, promclient, commonTestUtils, secretproviderclient, builders.ARadixDeployment().887 WithAppName("any-app").888 WithEnvironment("prod").889 WithComponents(890 builders.NewDeployComponentBuilder().891 WithName("frontend").892 WithPort("http", 8080).893 WithPublicPort("http").894 WithDNSAppAlias(true),895 builders.NewDeployComponentBuilder().896 WithName("backend")))897 // Test898 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s", "any-app"))899 response := <-responseChannel900 application := applicationModels.Application{}901 controllertest.GetResponseBody(response, &application)902 assert.NotNil(t, application.AppAlias)903 assert.Equal(t, "frontend", application.AppAlias.ComponentName)904 assert.Equal(t, "prod", application.AppAlias.EnvironmentName)905 assert.Equal(t, fmt.Sprintf("%s.%s", "any-app", appAliasDNSZone), application.AppAlias.URL)906}907func TestListPipeline_ReturnesAvailablePipelines(t *testing.T) {908 supportedPipelines := jobPipeline.GetSupportedPipelines()909 // Setup910 commonTestUtils, controllerTestUtils, _, _, _, _ := setupTest()911 commonTestUtils.ApplyRegistration(builders.ARadixRegistration().912 WithName("some-app").913 WithPublicKey("some-public-key").914 WithPrivateKey("some-private-key"))915 // Test916 responseChannel := controllerTestUtils.ExecuteRequest("GET", fmt.Sprintf("/api/v1/applications/%s/pipelines", "some-app"))917 response := <-responseChannel918 pipelines := make([]string, 0)919 controllertest.GetResponseBody(response, &pipelines)920 assert.Equal(t, len(supportedPipelines), len(pipelines))921}922func TestRegenerateDeployKey_WhenSecretProvided_GenerateNewDeployKeyAndSetSecret(t *testing.T) {923 // Setup924 _, controllerTestUtils, _, _, _, _ := setupTest()925 // Test926 appName := "any-name"927 origSharedSecret := "Orig shared secret"928 origDeployPublicKey := "Orig public key"929 parameters := AnApplicationRegistration().930 withName(appName).931 withRepository("https://github.com/Equinor/any-repo").932 withSharedSecret(origSharedSecret).933 withPrivateKey(origDeployPublicKey).934 withPublicKey("Orig private key").935 Build()936 appResponseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)937 <-appResponseChannel938 newSharedSecret := "new shared secret"939 regenerateParameters := AnRegenerateDeployKeyAndSecretDataBuilder().940 WithSharedSecret(newSharedSecret).941 Build()942 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/regenerate-deploy-key", appName), regenerateParameters)943 response := <-responseChannel944 deployKeyAndSecret := applicationModels.DeployKeyAndSecret{}945 controllertest.GetResponseBody(response, &deployKeyAndSecret)946 assert.Equal(t, http.StatusOK, response.Code)947 assert.NotEqual(t, origDeployPublicKey, deployKeyAndSecret.PublicDeployKey)948 assert.True(t, strings.Contains(deployKeyAndSecret.PublicDeployKey, "ssh-rsa "))949 assert.Equal(t, newSharedSecret, deployKeyAndSecret.SharedSecret)950}951func TestRegenerateDeployKey_WhenSecretNotProvided_Fails(t *testing.T) {952 // Setup953 _, controllerTestUtils, _, _, _, _ := setupTest()954 // Test955 appName := "any-name"956 parameters := AnApplicationRegistration().957 withName(appName).958 withRepository("https://github.com/Equinor/any-repo").959 withSharedSecret("Orig shared secret").960 withPrivateKey("Orig public key").961 withPublicKey("Orig private key").962 Build()963 appResponseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)964 <-appResponseChannel965 newSharedSecret := ""966 regenerateParameters := AnRegenerateDeployKeyAndSecretDataBuilder().967 WithSharedSecret(newSharedSecret).968 Build()969 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/regenerate-deploy-key", appName), regenerateParameters)970 response := <-responseChannel971 deployKeyAndSecret := applicationModels.DeployKeyAndSecret{}972 controllertest.GetResponseBody(response, &deployKeyAndSecret)973 assert.NotEqual(t, http.StatusOK, response.Code)974 assert.Empty(t, deployKeyAndSecret.PublicDeployKey)975 assert.Empty(t, deployKeyAndSecret.SharedSecret)976}977func TestRegenerateDeployKey_WhenApplicationNotExist_Fail(t *testing.T) {978 // Setup979 _, controllerTestUtils, _, _, _, _ := setupTest()980 // Test981 parameters := AnApplicationRegistration().982 withName("any-name").983 withRepository("https://github.com/Equinor/any-repo").984 Build()985 appResponseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", "/api/v1/applications", parameters)986 <-appResponseChannel987 regenerateParameters := AnRegenerateDeployKeyAndSecretDataBuilder().988 WithSharedSecret("new shared secret").989 Build()990 appName := "any-non-existing-name"991 responseChannel := controllerTestUtils.ExecuteRequestWithParameters("POST", fmt.Sprintf("/api/v1/applications/%s/regenerate-deploy-key", appName), regenerateParameters)992 response := <-responseChannel993 deployKeyAndSecret := applicationModels.DeployKeyAndSecret{}994 controllertest.GetResponseBody(response, &deployKeyAndSecret)995 assert.Equal(t, http.StatusNotFound, response.Code)996 assert.Empty(t, deployKeyAndSecret.PublicDeployKey)997 assert.Empty(t, deployKeyAndSecret.SharedSecret)998}999func setStatusOfCloneJob(kubeclient kubernetes.Interface, appNamespace string, succeededStatus bool) {1000 timeout := time.After(1 * time.Second)1001 tick := time.Tick(200 * time.Millisecond)1002 for {1003 select {1004 case <-timeout:1005 return...

Full Screen

Full Screen

sh.go

Source:sh.go Github

copy

Full Screen

...8type IUSHR struct{ common.NoOperandsInstruction }9type LSHL struct{ common.NoOperandsInstruction }10type LSHR struct{ common.NoOperandsInstruction }11type LUSHR struct{ common.NoOperandsInstruction }12func (this *ISHL) Execute(frame *rtda.Frame) {13 stack := frame.OperandStack()14 v2 := stack.PopInt()15 v1 := stack.PopInt()16 // 32bit 最大位移17 s := uint32(v2) & 0x1f18 result := v1 << s19 stack.PushInt(result)20}21func (this *ISHR) Execute(frame *rtda.Frame) {22 stack := frame.OperandStack()23 v2 := stack.PopInt()24 v1 := stack.PopInt()25 // 32bit 最大位移26 s := uint32(v2) & 0x1f27 result := v1 >> s28 stack.PushInt(result)29}30func (this *IUSHR) Execute(frame *rtda.Frame) {31 stack := frame.OperandStack()32 v2 := stack.PopInt()33 v1 := stack.PopInt()34 s := uint32(v2) & 0x1f35 result := int32(uint32(v1) >> s)36 stack.PushInt(result)37}38func (this *LSHL) Execute(frame *rtda.Frame) {39 stack := frame.OperandStack()40 v2 := stack.PopInt()41 v1 := stack.PopLong()42 s := uint32(v2) & 0x3f43 result := v1 << s44 stack.PushLong(result)45}46func (this *LSHR) Execute(frame *rtda.Frame) {47 stack := frame.OperandStack()48 v2 := stack.PopInt()49 v1 := stack.PopLong()50 s := uint64(v2) & 0x3f51 result := v1 >> s52 stack.PushLong(result)53}54func (this *LUSHR) Execute(frame *rtda.Frame) {55 stack := frame.OperandStack()56 v2 := stack.PopInt()57 v1 := stack.PopLong()58 s := uint64(v2) & 0x3f59 result := int64(uint64(v1) >> s)60 stack.PushLong(result)61}

Full Screen

Full Screen

bitwise.go

Source:bitwise.go Github

copy

Full Screen

...9type IXOR struct{ common.NoOperandsInstruction }10type LAND struct{ common.NoOperandsInstruction }11type LOR struct{ common.NoOperandsInstruction }12type LXOR struct{ common.NoOperandsInstruction }13func (this *IAND) Execute(frame *rtda.Frame) {14 stack := frame.OperandStack()15 v2 := stack.PopInt()16 v1 := stack.PopInt()17 result := v1 & v218 stack.PushInt(result)19}20func (this *IOR) Execute(frame *rtda.Frame) {21 stack := frame.OperandStack()22 v2 := stack.PopInt()23 v1 := stack.PopInt()24 result := v1 | v225 stack.PushInt(result)26}27func (this *IXOR) Execute(frame *rtda.Frame) {28 stack := frame.OperandStack()29 v2 := stack.PopInt()30 v1 := stack.PopInt()31 result := v1 ^ v232 stack.PushInt(result)33}34func (this *LAND) Execute(frame *rtda.Frame) {35 stack := frame.OperandStack()36 v2 := stack.PopLong()37 v1 := stack.PopLong()38 result := v1 & v239 stack.PushLong(result)40}41func (this *LOR) Execute(frame *rtda.Frame) {42 stack := frame.OperandStack()43 v2 := stack.PopLong()44 v1 := stack.PopLong()45 result := v1 | v246 stack.PushLong(result)47}48func (this *LXOR) Execute(frame *rtda.Frame) {49 stack := frame.OperandStack()50 v2 := stack.PopLong()51 v1 := stack.PopLong()52 result := v1 ^ v253 stack.PushLong(result)54}...

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1func main() {2 v1 := &v1{}3 v1.Execute()4}5func main() {6 v2 := &v2{}7 v2.Execute()8}

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v1.Execute()4}5import (6func main() {7 v2.Execute()8}9import (10func main() {11 v3.Execute()12}13import "fmt"14func Execute() {15 fmt.Println("Execute v1")16}17import "fmt"18func Execute() {19 fmt.Println("Execute v2")20}21import "fmt"22func Execute() {23 fmt.Println("Execute v3")24}25Now, we will change the import statement in 2.go from v1 to v2 and execute the following command:26Now, we will change the import statement in 3.go from v2 to v3 and execute the following command:

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v1.Execute()4 fmt.Println("2.go")5}6import (7func main() {8 v1.Execute()9 fmt.Println("3.go")10}11import (12func main() {13 v1.Execute()14 fmt.Println("4.go")15}16import (17func main() {18 v1.Execute()19 fmt.Println("5.go")20}21import (22func main() {23 v1.Execute()24 fmt.Println("6.go")25}26import (27func main() {28 v1.Execute()29 fmt.Println("7.go")30}31import (32func main() {33 v1.Execute()34 fmt.Println("8.go")35}36import (37func main() {38 v1.Execute()39 fmt.Println("9.go")40}41import (42func main() {43 v1.Execute()44 fmt.Println("10.go")45}46import (47func main() {48 v1.Execute()49 fmt.Println("11.go")50}51import (52func main() {53 v1.Execute()54 fmt.Println("12.go")

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v1.Execute()4 v2.Execute()5}6import (7func main() {8 v2.Execute()9}

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("This is the main method")4 v1.Execute()5}6import (7func Execute() {8 fmt.Println("This is the v1 method")9}10import (11func main() {12 fmt.Println("This is the main method")13 v3.Execute()14}15import (16func Execute() {17 fmt.Println("This is the v3 method")18}19import (20func main() {21 fmt.Println("This is the main method")22 v4.Execute()23}24import (25func Execute() {26 fmt.Println("This is the v4 method")27}28import (29func main() {30 fmt.Println("This is the main method")31 v5.Execute()32}33import (34func Execute() {35 fmt.Println("This is the v5 method")36}37import (38func main() {39 fmt.Println("This is the main method")40 v6.Execute()41}42import (43func Execute() {44 fmt.Println("This is the v6 method")45}46import (47func main() {48 fmt.Println("This is the main method")49 v7.Execute()50}

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v1.Execute()4 fmt.Println("Hello World")5}6import (7func Execute() {8 v2.Execute()9 fmt.Println("Hello World")10}11import "fmt"12func Execute() {13 fmt.Println("Hello World")14}15import (16func main() {17 v3.Execute()18 fmt.Println("Hello World")19}20import "fmt"21func Execute() {22 fmt.Println("Hello World")23}24import (25func main() {26 v4.Execute()27 fmt.Println("Hello World")28}29import "fmt"30func Execute() {31 fmt.Println("Hello World")32}33import (34func main() {35 v5.Execute()36 fmt.Println("Hello World")37}38import "fmt"39func Execute() {40 fmt.Println("Hello World")41}42import (43func main() {44 v6.Execute()45 fmt.Println("Hello World")46}47import "fmt"48func Execute() {49 fmt.Println("Hello World")50}51import (

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3v1.Execute()4}5import (6func main() {7v2.Execute()8}9import (10func main() {11v3.Execute()12}13import (14func main() {15v4.Execute()16}17import (18func main() {19v5.Execute()20}21import (22func main() {23v6.Execute()24}25import (26func main() {27v7.Execute()28}29import (30func main() {

Full Screen

Full Screen

Execute

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 v1 := new(v1)4 v1.Execute()5}6import (7func main() {8 v1 := new(v1)9 v2 := new(v2)10 adapter := new(Adapter)11 v2.Execute()12 adapter.Execute(v1)13}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testkube automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful