From 3703f301db36adf3b8119a0e76feaa13be448367 Mon Sep 17 00:00:00 2001 From: Ankit Bhardwaj Date: Tue, 7 Nov 2023 17:00:00 +0530 Subject: [PATCH] INFRA-2265 | Ankit Bhardwaj | Add test for get deployment portal url function --- main_test.go | 21 +++++++++++++++++++++ resource.go | 15 +++++++-------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/main_test.go b/main_test.go index 7f2d03e..a34611f 100644 --- a/main_test.go +++ b/main_test.go @@ -174,3 +174,24 @@ func TestTemplates_AuroraDb_CompareWithOutput(t *testing.T) { } } } + +func Test_getDeploymentPortalUrl(t *testing.T) { + for _, manifestFile := range manifestFiles { + fmt.Println(manifestFile) + testActions, err := setActions(true, false, false) + if err != nil { + fmt.Printf("\nErr: %v", err) + t.Error(err) + } + manifest, err := parseManifest(filepath.Join(testDataDir, manifestFile+".json"), testActions) + if err != nil { + fmt.Printf("\nFailed to Parse Manifest Err: %v", err) + t.Error(err) + } + actualURL := getDeploymentPortalUrl(manifest) + expectedURL := fmt.Sprintf("https://%sdeployment-portal-backend.cmd.navi-tech.in/api/manifest/status/env/%s/name/%s", InfraVerticals[manifest.InfraVertical], manifest.Environment, manifest.Name) + if actualURL != expectedURL { + t.Errorf("Mismatch output \n diff: %s", textDiff(actualURL, expectedURL)) + } + } +} diff --git a/resource.go b/resource.go index 3d572f1..75f37f2 100644 --- a/resource.go +++ b/resource.go @@ -20,22 +20,21 @@ const TemplatesDir = "templates" const InitScript = "./deploy.sh" const deploymentPortalUrl = "deployment-portal-backend.cmd.navi-tech.in" -func getInfraVertical(manifest *Manifest) string { - return InfraVerticals[manifest.InfraVertical] +func getInfraVertical(vertical string) string { + return InfraVerticals[vertical] } -func getDeploymentPortalHostUrl() string { +func getDeploymentPortalHostUrl(vertical string) string { env := os.Getenv("TESTING_ENV") if env == "dev" { return "http://localhost:8080" } - return fmt.Sprintf("https://%s", deploymentPortalUrl) + return fmt.Sprintf("https://%s%s", getInfraVertical(vertical), deploymentPortalUrl) } func getDeploymentPortalUrl(manifest *Manifest) string { - return fmt.Sprintf("%s%s/api/manifest/status/env/%s/name/%s", - getInfraVertical(manifest), - getDeploymentPortalHostUrl(), + return fmt.Sprintf("%s/api/manifest/status/env/%s/name/%s", + getDeploymentPortalHostUrl(manifest.InfraVertical), manifest.Environment, manifest.Name) } @@ -143,7 +142,7 @@ func sendResourceDeploymentStatus(manifest *Manifest) { return } defer resp.Body.Close() - if resp.StatusCode != 202 { + if resp.StatusCode != 202 && resp.StatusCode != 404 { log.Panicf("\nFailed to set deployment Status of Resources, Response Code: %v", resp.StatusCode) } }