From 7ad55da975901452b6119104de0247eeae247926 Mon Sep 17 00:00:00 2001 From: Daniel Brotsky Date: Sun, 27 Dec 2015 00:29:45 -0800 Subject: [PATCH] Carefully work through footer messaging. - Made a careful choice about what to show in each environment. - Added tests. --- client/template.go | 38 ++++++++++------------- client/template_test.go | 46 ++++++++++++++++++++++++++++ client/testdata/TestErrorPage0.html | 2 +- client/testdata/TestHomePage0.html | 2 +- client/testdata/TestSolverPage0.html | 2 +- client/testdata/TestSolverPage1.html | 2 +- 6 files changed, 67 insertions(+), 25 deletions(-) diff --git a/client/template.go b/client/template.go index f166076..2234031 100644 --- a/client/template.go +++ b/client/template.go @@ -335,10 +335,10 @@ application footer // bottom of all pages. func applicationFooter() string { appName := os.Getenv(applicationNameEnvVar) + appEnv := os.Getenv(applicationEnvEnvVar) appVersion := os.Getenv(applicationVersionEnvVar) appInstance := os.Getenv(applicationInstanceEnvVar) appBuild := os.Getenv(applicationBuildEnvVar) - appEnv := os.Getenv(applicationEnvEnvVar) if appName == "" { appName = brandName @@ -348,30 +348,26 @@ func applicationFooter() string { appEnv = "local" } - if appVersion == "" { - if appEnv == "dev" { - appVersion = " " - } else { - appVersion = " " - } - } else { + if appVersion != "" { appVersion = " " + appVersion } - if len(appBuild) >= 7 { - appBuild = " " + appBuild[:7] - } else { - appBuild = "" + appBuild = appBuild[:7] } - if appInstance == "" { - appInstance = " " - } else { - if appEnv == "prd" { - appInstance = " <" + appInstance + ">" - } else { - appInstance = " <" + appEnv + appBuild + ">" - } + if appInstance != "" { + appInstance = " (dyno " + appInstance + ")" + } + + switch appEnv { + case "local": + return "[" + appName + " local]" + case "dev": + return "[" + appName + " CI/CD]" + case "stg": + return "[" + appName + appVersion + " <" + appBuild + ">]" + case "prd": + return "[" + appName + appVersion + " <" + appBuild + ">" + appInstance + "]" } - return "[" + appName + appVersion + appInstance + "]" + return "[" + appName + " ]" } diff --git a/client/template_test.go b/client/template_test.go index 846d3d2..9bdb705 100644 --- a/client/template_test.go +++ b/client/template_test.go @@ -83,6 +83,52 @@ func TestSolverPage(t *testing.T) { /* +footer + +*/ + +type footerTestcase struct { + name, version, instance, build, env string + footer string +} + +func TestApplicationFooter(t *testing.T) { + testcases := []footerTestcase{ + {"", "", "", "", "", + "[" + brandName + " local]"}, + {"susen-staging-pr-30", + "v29", + "", + "ca0fd7123f918d1b6d3e65f3de47d52db09ae068", + "dev", + "[susen-staging-pr-30 CI/CD]"}, + {"susen-staging", + "v29", + "1vac4117-c29f-4312-521e-ba4d8638c1ac", + "ca0fd7123f918d1b6d3e65f3de47d52db09ae068", + "stg", + "[susen-staging v29 ]"}, + {"susen-production", + "v22", + "1vac4117-c29f-4312-521e-ba4d8638c1ac", + "ca0fd7123f918d1b6d3e65f3de47d52db09ae068", + "prd", + "[susen-production v22 (dyno 1vac4117-c29f-4312-521e-ba4d8638c1ac)]"}, + } + for i, tc := range testcases { + os.Setenv(applicationNameEnvVar, tc.name) + os.Setenv(applicationVersionEnvVar, tc.version) + os.Setenv(applicationInstanceEnvVar, tc.instance) + os.Setenv(applicationBuildEnvVar, tc.build) + os.Setenv(applicationEnvEnvVar, tc.env) + if footer := applicationFooter(); footer != tc.footer { + t.Errorf("Case %d: got %q, expected %q", i, footer, tc.footer) + } + } +} + +/* + helpers */ diff --git a/client/testdata/TestErrorPage0.html b/client/testdata/TestErrorPage0.html index 956ebb5..4734276 100644 --- a/client/testdata/TestErrorPage0.html +++ b/client/testdata/TestErrorPage0.html @@ -9,6 +9,6 @@

Error Page

Sorry, a server error has occurred while generating this page. The English description of the error is:

Test Error 0

To report this error, click here. When reporting your error, please include the following build info:

-

[Sūsen <dev build> <local>]

+

[Sūsen local]

diff --git a/client/testdata/TestHomePage0.html b/client/testdata/TestHomePage0.html index 79ffc37..b37bc66 100644 --- a/client/testdata/TestHomePage0.html +++ b/client/testdata/TestHomePage0.html @@ -40,7 +40,7 @@

Solve a Puzzle

diff --git a/client/testdata/TestSolverPage0.html b/client/testdata/TestSolverPage0.html index 04ba1bf..0563f66 100644 --- a/client/testdata/TestSolverPage0.html +++ b/client/testdata/TestSolverPage0.html @@ -132,7 +132,7 @@

Puzzle Solver

diff --git a/client/testdata/TestSolverPage1.html b/client/testdata/TestSolverPage1.html index 583d467..e8fb808 100644 --- a/client/testdata/TestSolverPage1.html +++ b/client/testdata/TestSolverPage1.html @@ -422,7 +422,7 @@

Puzzle Solver