INFRA-2265 | Ankit Bhardwaj | Add test for get deployment portal url function

This commit is contained in:
Ankit Bhardwaj
2023-11-07 17:00:00 +05:30
parent 6d857ae405
commit 3703f301db
2 changed files with 28 additions and 8 deletions

View File

@@ -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))
}
}
}

View File

@@ -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)
}
}