package console import ( "net/http/httptest" "net/url" "reflect" "strings" "testing" ) func TestDeploymentTargetsKeepObservationSeparate(t *testing.T) { view := &AppView{ Channels: []ChannelView{{Name: "edge", Version: "new"}, {Name: "stable", Err: "unavailable"}, {Name: "empty"}}, Routes: []RouteView{ {Account: "ours", Channel: "edge", Version: "alias", Platform: true}, {Account: "ours", Channel: "edge", Version: "new", Kind: "static"}, {Account: "ours", Channel: "edge", Version: "old", Kind: "service"}, {Account: "ours", Channel: "edge", Version: "old"}, {Account: "ours", Channel: "edge", Version: "new"}, {Account: "ours", Channel: "edge", Version: "old"}, {Account: "ours", Channel: "edge"}, {Account: "ours", Channel: "canary/custom", Version: "custom"}, {Account: "ours", Version: "running"}, {Account: "theirs", Channel: "foreign", Version: "secret"}, }, } want := []deploymentTarget{ {Channel: "canary/custom", Total: 1, Versions: []deploymentObservedVersion{{Version: "custom", Count: 1}}}, {Channel: "edge", Target: "new", Total: 6, Unknown: 3, Versions: []deploymentObservedVersion{{Version: "new", Count: 1}, {Version: "old", Count: 2}}}, {Channel: "empty"}, {Channel: "stable", TargetErr: "unavailable", Total: 1, Versions: []deploymentObservedVersion{{Version: "running", Count: 1}}}, } if got := assembleDeploymentTargets(view, "ours"); !reflect.DeepEqual(got, want) { t.Fatalf("targets = %#v, want %#v", got, want) } } func TestDeploymentRoutesAndHistory(t *testing.T) { fx := newConsoleFixture(t) c := signInPaul(t, fx) status, _, body := get(t, c, fx.u("/apps/kass/deployments")) if status != 200 { t.Fatalf("deployments status = %d", status) } for _, want := range []string{`/apps/kass/releases#version-v1`, `/apps/kass/instances?channel=stable`, `/apps/kass/deployments" aria-current="page">`} { if !strings.Contains(body, want) { t.Errorf("deployments missing %q", want) } } _, _, history := get(t, c, fx.u("/apps/kass/releases")) if !strings.Contains(history, `id="version-v1"`) { t.Error("history has no target version anchor") } assertNonMember404(t, fx, "/apps/kass/deployments") } func TestReleaseBackTabOnlyAcceptsLocalDestinations(t *testing.T) { for _, value := range []string{"releases", "deployments", "", "https://other.example/", "../settings", "//other.example"} { r := httptest.NewRequest("POST", "/", strings.NewReader(url.Values{"back": {value}}.Encode())) r.Header.Set("Content-Type", "application/x-www-form-urlencoded") want := "" if value == "releases" || value == "deployments" { want = value } if got := releaseBackTab(r); got != want { t.Errorf("back %q = %q, want %q", value, got, want) } } } func TestDeploymentsDoNotDependOnReleaseListing(t *testing.T) { fx := newConsoleFixture(t) c := signInPaul(t, fx) fx.srv.cfg.Releases = listFailStore{fx.rel} status, _, body := get(t, c, fx.u("/apps/kass/deployments")) if status != 200 || strings.Contains(body, "Could not list this app") { t.Fatalf("deployments depended on release listing: status %d, body %s", status, body) } _, _, history := get(t, c, fx.u("/apps/kass/releases")) if !strings.Contains(history, "Could not list this app") { t.Fatal("fixture did not fail the release listing") } }