carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "bytes"
5 "strings"
6 "testing"
7)
8
9func TestOverviewRendersMixedAndPartialObservedVersions(t *testing.T) {
10 deployment := DeploymentStatus{
11 RouteCount: 3, ReportableCount: 3, ReportedCount: 2, UnknownCount: 1,
12 Versions: []DeploymentVersion{{Version: "v1", Count: 1}, {Version: "v2", Count: 1}},
13 }
14 p := page{
15 Detail: &AppView{},
16 Account: &Account{},
17 StatusCopy: approvedStatusCopy,
18 Overview: OverviewStats{Deployment: deployment, Verdict: "unknown", VerdictLabel: "Can't tell right now"},
19 }
20 var out bytes.Buffer
21 if err := templates.ExecuteTemplate(&out, "app_overview", p); err != nil {
22 t.Fatal(err)
23 }
24 body := out.String()
25 for _, want := range []string{
26 "Observed versions", "2 of 3 instances report a version.",
27 "<code>v1</code>", "<code>v2</code>", "Some instances have not reported a version.",
28 } {
29 if !strings.Contains(body, want) {
30 t.Errorf("missing %q", want)
31 }
32 }
33}
34
35func TestReleasesRendersApprovedCandidateText(t *testing.T) {
36 p := page{
37 Detail: &AppView{},
38 Account: &Account{},
39 StatusCopy: approvedStatusCopy,
40 ReleaseSummary: ReleaseSummary{NextVersion: "v9"},
41 }
42 var out bytes.Buffer
43 if err := templates.ExecuteTemplate(&out, "app_releases", p); err != nil {
44 t.Fatal(err)
45 }
46 if !strings.Contains(out.String(), "Candidate for promotion: v9.") {
47 t.Fatal("release summary did not render the approved candidate text")
48 }
49}
50
51func TestStaticOnlyPagesDoNotClaimAMissingVersionReport(t *testing.T) {
52 deployment := DeploymentStatus{RouteCount: 1}
53 p := page{
54 Detail: &AppView{},
55 Account: &Account{},
56 StatusCopy: approvedStatusCopy,
57 Overview: OverviewStats{Deployment: deployment, Verdict: "ok", VerdictLabel: "All good"},
58 ReleaseSummary: ReleaseSummary{Deployment: deployment},
59 }
60 for _, name := range []string{"app_overview", "app_releases"} {
61 var out bytes.Buffer
62 if err := templates.ExecuteTemplate(&out, name, p); err != nil {
63 t.Fatal(err)
64 }
65 body := out.String()
66 if !strings.Contains(body, "<p>—</p>") || strings.Contains(body, approvedStatusCopy.NoInstances) || strings.Contains(body, approvedStatusCopy.NoVersion) {
67 t.Errorf("%s rendered the wrong non-reportable state", name)
68 }
69 }
70}
71