Skip to content

Commit

Permalink
Merge pull request #34 from uselagoon/identify-alternativenames
Browse files Browse the repository at this point in the history
test: add a test for autogenerated prefixes
  • Loading branch information
shreddedbacon authored May 20, 2022
2 parents 01485b3 + 48b4004 commit d95d006
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 13 deletions.
41 changes: 28 additions & 13 deletions cmd/identify_ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,18 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable,
}
// get the first route from the list of routes
if len(autogenRoutes.Routes) > 0 {
rangeVal := len(autogenRoutes.Routes) - 1
autogen = append(autogen, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[0].Domain))
for i := 1; i <= rangeVal; i++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
for i := 0; i < len(autogenRoutes.Routes); i++ {
autogen = append(autogen, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
if i == 0 {
primary = fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain)
} else {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].Domain))
}
for a := 0; a < len(autogenRoutes.Routes[i].AlternativeNames); a++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].AlternativeNames[a]))
autogen = append(autogen, fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[i].AlternativeNames[a]))
}
}
primary = fmt.Sprintf("%s%s", prefix, autogenRoutes.Routes[0].Domain)
}

// handle routes from the .lagoon.yml and the API specifically
Expand All @@ -80,11 +85,16 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable,
if primary != "" {
remainders = append(remainders, primary)
}
rangeVal := len(mainRoutes.Routes) - 1
for i := 1; i <= rangeVal; i++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain))
for i := 0; i < len(mainRoutes.Routes); i++ {
if i == 0 {
primary = fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain)
} else {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].Domain))
}
for a := 0; a < len(mainRoutes.Routes[i].AlternativeNames); a++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[i].AlternativeNames[a]))
}
}
primary = fmt.Sprintf("%s%s", prefix, mainRoutes.Routes[0].Domain)
}

if activeEnv || standbyEnv {
Expand All @@ -98,11 +108,16 @@ func generateRoutes(lagoonEnvVars []lagoon.EnvironmentVariable,
if primary != "" {
remainders = append(remainders, primary)
}
rangeVal := len(activeStanbyRoutes.Routes) - 1
for i := 1; i <= rangeVal; i++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain))
for i := 0; i < len(activeStanbyRoutes.Routes); i++ {
if i == 0 {
primary = fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain)
} else {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].Domain))
}
for a := 0; a < len(activeStanbyRoutes.Routes[i].AlternativeNames); a++ {
remainders = append(remainders, fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[i].AlternativeNames[a]))
}
}
primary = fmt.Sprintf("%s%s", prefix, activeStanbyRoutes.Routes[0].Domain)
}
}

Expand Down
33 changes: 33 additions & 0 deletions cmd/identify_ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,39 @@ func TestIdentifyRoute(t *testing.T) {
wantRemain: []string{},
wantautoGen: []string{"https://node-example-project-no-ingress.example.com"},
},
{
name: "test12 no custom ingress",
args: args{
alertContact: "alertcontact",
statusPageID: "statuspageid",
projectName: "example-project",
environmentName: "no-ingress",
environmentType: "production",
buildType: "branch",
standbyEnvironment: "no-ingress",
lagoonVersion: "v2.7.x",
branch: "main2",
projectVars: `[{"name":"LAGOON_SYSTEM_ROUTER_PATTERN","value":"${service}-${project}-${environment}.example.com","scope":"internal_system"}]`,
envVars: `[]`,
secretPrefix: "fastly-api-",
lagoonYAML: "test-resources/template-ingress/prefixes-lagoon.yml",
templatePath: "test-resources/template-ingress/output",
},
want: "https://node-example-project-no-ingress.example.com",
wantRemain: []string{
"https://www.node-example-project-no-ingress.example.com",
"https://en.node-example-project-no-ingress.example.com",
"https://de.node-example-project-no-ingress.example.com",
"https://fi.node-example-project-no-ingress.example.com",
},
wantautoGen: []string{
"https://node-example-project-no-ingress.example.com",
"https://www.node-example-project-no-ingress.example.com",
"https://en.node-example-project-no-ingress.example.com",
"https://de.node-example-project-no-ingress.example.com",
"https://fi.node-example-project-no-ingress.example.com",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
18 changes: 18 additions & 0 deletions cmd/test-resources/template-ingress/prefixes-lagoon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
docker-compose-yaml: test-resources/template-ingress/docker-compose.yml

routes:
autogenerate:
prefixes:
- www
- en
- de
- fi

environment_variables:
git_sha: "true"

environments:
main:
routes:
- node:
- example.com

0 comments on commit d95d006

Please sign in to comment.