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 "testing"
4
5func TestObservedDeploymentUsesOwnedRouteReports(t *testing.T) {
6 routes := []RouteView{
7 {Host: "edge.example", Account: "bab", Channel: "edge", Version: "v2"},
8 {Host: "custom.example", Account: "bab", Channel: "production", Version: "v2"},
9 {Host: "canary.example", Account: "bab", Channel: "canary/live", Version: "v3"},
10 {Host: "unknown.example", Account: "bab", Channel: "edge"},
11 {Host: "foreign.example", Account: "other", Channel: "stable", Version: "secret"},
12 }
13 d := observedDeployment(routes, "bab")
14 if d.RouteCount != 4 || d.ReportableCount != 4 || d.ReportedCount != 3 || d.UnknownCount != 1 {
15 t.Fatalf("counts = %+v, want 4 routes, 3 reported, 1 unknown", d)
16 }
17 if !d.HasRoutes() || !d.HasReportedVersion() || !d.Mixed() || d.UniformVersion() != "" {
18 t.Fatalf("shape = %+v, want a mixed observed deployment", d)
19 }
20 if len(d.Versions) != 2 || d.Versions[0] != (DeploymentVersion{Version: "v2", Count: 2}) ||
21 d.Versions[1] != (DeploymentVersion{Version: "v3", Count: 1}) {
22 t.Fatalf("versions = %+v, want deterministic v2:2, v3:1", d.Versions)
23 }
24}
25
26func TestObservedDeploymentSeparatesNoRoutesFromUnknownReports(t *testing.T) {
27 empty := observedDeployment(nil, "bab")
28 if empty.HasRoutes() || empty.HasReportedVersion() {
29 t.Fatalf("no routes = %+v", empty)
30 }
31 unknown := observedDeployment([]RouteView{
32 {Host: "sleeping.example", Account: "bab", Kind: "instance", Hibernate: true},
33 {Host: "service.example", Account: "bab", Kind: "service"},
34 {Host: "alias.example", Account: "bab", Platform: true, Version: "alias-version"},
35 }, "bab")
36 if !unknown.HasRoutes() || unknown.HasReportedVersion() || unknown.RouteCount != 2 || unknown.ReportableCount != 1 || unknown.UnknownCount != 1 {
37 t.Fatalf("unknown route reports = %+v", unknown)
38 }
39}
40
41func TestObservedDeploymentDoesNotCallStaticTargetObserved(t *testing.T) {
42 d := observedDeployment([]RouteView{
43 {Host: "site.example", Account: "bab", Kind: "static", Channel: "edge", Version: "stale-registry-value"},
44 {Host: "site.bab.oncarlos.com", Account: "bab", Platform: true},
45 }, "bab")
46 if d.RouteCount != 1 || d.ReportableCount != 0 || d.ReportedCount != 0 || d.UnknownCount != 0 || len(d.Versions) != 0 {
47 t.Fatalf("static deployment = %+v", d)
48 }
49}
50