Skip to content

Commit

Permalink
Carefully work through footer messaging.
Browse files Browse the repository at this point in the history
- Made a careful choice about what to show in each environment.
- Added tests.
  • Loading branch information
brotskydotcom committed Dec 27, 2015
1 parent ef0cd11 commit 7ad55da
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
38 changes: 17 additions & 21 deletions client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -348,30 +348,26 @@ func applicationFooter() string {
appEnv = "local"
}

if appVersion == "" {
if appEnv == "dev" {
appVersion = " <CI latest>"
} else {
appVersion = " <dev build>"
}
} else {
if appVersion != "" {
appVersion = " " + appVersion
}

if len(appBuild) >= 7 {
appBuild = " " + appBuild[:7]
} else {
appBuild = ""
appBuild = appBuild[:7]
}

if appInstance == "" {
appInstance = " <local>"
} 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 + " <??>]"
}
46 changes: 46 additions & 0 deletions client/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ca0fd71>]"},
{"susen-production",
"v22",
"1vac4117-c29f-4312-521e-ba4d8638c1ac",
"ca0fd7123f918d1b6d3e65f3de47d52db09ae068",
"prd",
"[susen-production v22 <ca0fd71> (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
*/
Expand Down
2 changes: 1 addition & 1 deletion client/testdata/TestErrorPage0.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ <h1>Error Page</h1>
<p>Sorry, a server error has occurred while generating this page. The English description of the error is:</p>
<blockquote><em>Test Error 0</em></blockquote>
<p>To report this error, <a href="/bugreport.html">click here</a>. When reporting your error, please include the following build info:</p>
<p>[Sūsen &lt;dev build&gt; &lt;local&gt;]</p>
<p>[Sūsen local]</p>
</body>
</html>
2 changes: 1 addition & 1 deletion client/testdata/TestHomePage0.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ <h3>Solve a Puzzle</h3>
</div>
</div>
<div class="footer">
<p>[Sūsen &lt;dev build&gt; &lt;local&gt;]</p>
<p>[Sūsen local]</p>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion client/testdata/TestSolverPage0.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ <h1>Puzzle Solver</h1>
</div>
</div>
<div class="footer">
<p>[Sūsen &lt;dev build&gt; &lt;local&gt;]</p>
<p>[Sūsen local]</p>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion client/testdata/TestSolverPage1.html
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ <h1>Puzzle Solver</h1>
</div>
</div>
<div class="footer">
<p>[Sūsen &lt;dev build&gt; &lt;local&gt;]</p>
<p>[Sūsen local]</p>
</div>
</body>
</html>

0 comments on commit 7ad55da

Please sign in to comment.