diff --git a/.github/workflows/flake.yml b/.github/workflows/flake.yml index 44a56b1..5ba7b20 100644 --- a/.github/workflows/flake.yml +++ b/.github/workflows/flake.yml @@ -20,7 +20,7 @@ concurrency: cancel-in-progress: true jobs: - build: + flake: runs-on: ubuntu-latest timeout-minutes: 20 steps: diff --git a/internal/account/account_test.go b/internal/account/account_test.go index 9dffb63..2990f7f 100644 --- a/internal/account/account_test.go +++ b/internal/account/account_test.go @@ -429,35 +429,64 @@ func TestAccountDeleteAsksNothingWhenTheServerIsGone(t *testing.T) { } } -func TestAccountDeleteStopsWhenTheStoredLoginIsNoLongerValid(t *testing.T) { - deleted := false +func TestAccountDeleteStopsWhenTheProbeIsRefused(t *testing.T) { + tests := []struct { + name string + status int + body string + wantError string + }{ + { + name: "the login is no longer valid", + status: http.StatusUnauthorized, + body: "the login is no longer valid, log in again", + wantError: "no longer valid", + }, + { + name: "the server cannot answer", + status: http.StatusServiceUnavailable, + body: "the server could not list the fleets", + wantError: "could not list the fleets", + }, + { + name: "the version gate refuses", + status: http.StatusUpgradeRequired, + body: "update superstack to carry on", + wantError: "update superstack", + }, + } - mux := http.NewServeMux() + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + deleted := false + + mux := http.NewServeMux() - // What the server's own auth middleware answers for a revoked login. - mux.HandleFunc("GET /fleets", func(w http.ResponseWriter, r *http.Request) { - http.Error(w, "the login is no longer valid, log in again", http.StatusUnauthorized) - }) + mux.HandleFunc("GET /fleets", func(w http.ResponseWriter, r *http.Request) { + http.Error(w, test.body, test.status) + }) - mux.HandleFunc("DELETE /account", func(w http.ResponseWriter, r *http.Request) { - deleted = true - }) + mux.HandleFunc("DELETE /account", func(w http.ResponseWriter, r *http.Request) { + deleted = true + }) - session, out := apitest.LoggedInSession(t, mux) + session, out := apitest.LoggedInSession(t, mux) - session.In = strings.NewReader("y\n") + session.In = strings.NewReader("y\n") - err := Delete(session, nil) + err := Delete(session, nil) - if err == nil || !strings.Contains(err.Error(), "no longer valid") { - t.Fatalf("error = %v, want the server's own refusal", err) - } + if err == nil || !strings.Contains(err.Error(), test.wantError) { + t.Fatalf("error = %v, want the server's own refusal", err) + } - if out.String() != "" { - t.Errorf("output = %q, want the question never to be put", out.String()) - } + if out.String() != "" { + t.Errorf("output = %q, want the question never to be put", out.String()) + } - if deleted { - t.Error("the server saw the account deleted although the login was refused") + if deleted { + t.Error("the server saw the account deleted although the probe was refused") + } + }) } }