package console import "testing" func TestObservedDeploymentUsesOwnedRouteReports(t *testing.T) { routes := []RouteView{ {Host: "edge.example", Account: "bab", Channel: "edge", Version: "v2"}, {Host: "custom.example", Account: "bab", Channel: "production", Version: "v2"}, {Host: "canary.example", Account: "bab", Channel: "canary/live", Version: "v3"}, {Host: "unknown.example", Account: "bab", Channel: "edge"}, {Host: "foreign.example", Account: "other", Channel: "stable", Version: "secret"}, } d := observedDeployment(routes, "bab") if d.RouteCount != 4 || d.ReportableCount != 4 || d.ReportedCount != 3 || d.UnknownCount != 1 { t.Fatalf("counts = %+v, want 4 routes, 3 reported, 1 unknown", d) } if !d.HasRoutes() || !d.HasReportedVersion() || !d.Mixed() || d.UniformVersion() != "" { t.Fatalf("shape = %+v, want a mixed observed deployment", d) } if len(d.Versions) != 2 || d.Versions[0] != (DeploymentVersion{Version: "v2", Count: 2}) || d.Versions[1] != (DeploymentVersion{Version: "v3", Count: 1}) { t.Fatalf("versions = %+v, want deterministic v2:2, v3:1", d.Versions) } } func TestObservedDeploymentSeparatesNoRoutesFromUnknownReports(t *testing.T) { empty := observedDeployment(nil, "bab") if empty.HasRoutes() || empty.HasReportedVersion() { t.Fatalf("no routes = %+v", empty) } unknown := observedDeployment([]RouteView{ {Host: "sleeping.example", Account: "bab", Kind: "instance", Hibernate: true}, {Host: "service.example", Account: "bab", Kind: "service"}, {Host: "alias.example", Account: "bab", Platform: true, Version: "alias-version"}, }, "bab") if !unknown.HasRoutes() || unknown.HasReportedVersion() || unknown.RouteCount != 2 || unknown.ReportableCount != 1 || unknown.UnknownCount != 1 { t.Fatalf("unknown route reports = %+v", unknown) } } func TestObservedDeploymentDoesNotCallStaticTargetObserved(t *testing.T) { d := observedDeployment([]RouteView{ {Host: "site.example", Account: "bab", Kind: "static", Channel: "edge", Version: "stale-registry-value"}, {Host: "site.bab.oncarlos.com", Account: "bab", Platform: true}, }, "bab") if d.RouteCount != 1 || d.ReportableCount != 0 || d.ReportedCount != 0 || d.UnknownCount != 0 || len(d.Versions) != 0 { t.Fatalf("static deployment = %+v", d) } }