INFRA-2265 | Ankit Bhardwaj | modify test case for get_deployment_url

This commit is contained in:
Ankit Bhardwaj
2023-11-07 19:12:59 +05:30
parent 3703f301db
commit abdeba7eaf
3 changed files with 91 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"bytes"
"fmt"
"github.com/stretchr/testify/assert"
"io/ioutil"
"log"
"os"
@@ -176,22 +177,57 @@ 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))
}
testCases := []struct {
name string
manifestFile string
expectedURL string
setEnv bool
}{
{
name: "Correct Lending Vertical URL should be generated",
manifestFile: "sample_infra_manifest",
expectedURL: "https://deployment-portal-backend.cmd.navi-tech.in/api/manifest/status/env/dev/name/foo",
setEnv: false,
},
{
name: "Correct Insurance Vertical URL should be generated",
manifestFile: "sample_infra_manifest_2",
expectedURL: "https://gi-deployment-portal-backend.cmd.navi-tech.in/api/manifest/status/env/dev/name/foo",
setEnv: false,
},
{
name: "Correct for localhost URL should be generated",
manifestFile: "sample_infra_manifest",
expectedURL: "http://localhost:8080/api/manifest/status/env/dev/name/foo",
setEnv: true,
},
{
name: "Correct Navi-pay Vertical URL should be generated",
manifestFile: "sample_infra_manifest_3",
expectedURL: "https://navi-pay-deployment-portal-backend.cmd.navi-tech.in/api/manifest/status/env/dev/name/foo",
setEnv: false,
},
{
name: "Correct Sa Vertical URL should be generated",
manifestFile: "sample_infra_manifest_4",
expectedURL: "https://sa-deployment-portal-backend.cmd.navi-tech.in/api/manifest/status/env/dev/name/foo",
setEnv: false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
if testCase.setEnv {
_ = os.Setenv("TESTING_ENV", "dev")
}
defer func() {
_ = os.Unsetenv("TESTING_ENV")
}()
testActions, err := setActions(true, false, false)
assert.NoError(t, err)
manifest, err := parseManifest(filepath.Join(testDataDir, testCase.manifestFile+".json"), testActions)
assert.NoError(t, err)
actualURL := getDeploymentPortalUrl(manifest)
assert.Equal(t, testCase.expectedURL, actualURL)
})
}
}

19
testdata/sample_infra_manifest_3.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"environment": "dev",
"cluster": "aps1.np.navi-gi.in",
"metadata": {
"repo": "navi-medici/test",
"language": "Java"
},
"deployment": {
"namespace": "dev-3p"
},
"extraResources": {
"environment": "dev"
},
"team": {
"name": "Infra"
},
"name": "foo",
"infraVertical": "navi-pay"
}

19
testdata/sample_infra_manifest_4.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"environment": "dev",
"cluster": "aps1.np.navi-gi.in",
"metadata": {
"repo": "navi-medici/test",
"language": "Java"
},
"deployment": {
"namespace": "dev-3p"
},
"extraResources": {
"environment": "dev"
},
"team": {
"name": "Infra"
},
"name": "foo",
"infraVertical": "sa"
}