wip: re-review fixes
2 files changed,
+46
−6
internal/sheets/keymail_signin_test.go+32 −0internal/sheets/rhythm_browser_test.go+14 −6
CI passed — run details
CI log
amadan: .amadan/timeout: this job's budget is 15m0s (this runner allows up to 30m0s) === vet === CGO_ENABLED=0 go vet ./... CGO_ENABLED=0 go vet -tags browser ./internal/sheets/ === spacing === go tool fiesta spacing -skip 'vendor/*.css' -skip 'tokens.css' internal/sheets/static === fmt === === build === CGO_ENABLED=0 go build ./... === migrations === go tool rastrillo migration check rastrillo migration check: models and migrations agree === go-test === CGO_ENABLED=0 go test -count=1 ./... ? amadan.net/oficina/sheets/cmd/sheets [no test files] ? amadan.net/oficina/sheets/cmd/sheets-contract [no test files] ok amadan.net/oficina/sheets/internal/guardstest 0.165s ok amadan.net/oficina/sheets/internal/sheets 15.817s ok amadan.net/oficina/sheets/internal/sheets/calc 0.010s ok amadan.net/oficina/sheets/internal/sheets/format 0.003s ? amadan.net/oficina/sheets/internal/sheets/keymailtest [no test files] ok amadan.net/oficina/sheets/internal/sheets/live 0.053s ok amadan.net/oficina/sheets/internal/sheets/seal 0.002s ok amadan.net/oficina/sheets/internal/sheets/sealtest 0.003s ok amadan.net/oficina/sheets/internal/sheets/store 6.473s ok amadan.net/oficina/sheets/internal/sheets/teamstate 0.125s ok amadan.net/oficina/sheets/internal/sheets/xlsx 4.811s ? amadan.net/oficina/sheets/tools/gencorpus [no test files] === race === go test -race -count=1 ./internal/sheets/store/... ./internal/sheets/live/... ok amadan.net/oficina/sheets/internal/sheets/store 72.890s ok amadan.net/oficina/sheets/internal/sheets/live 1.067s
diff --git a/internal/sheets/keymail_signin_test.go b/internal/sheets/keymail_signin_test.go| index fbec938..9c68ff4 100644 |
| --- a/internal/sheets/keymail_signin_test.go |
| +++ b/internal/sheets/keymail_signin_test.go |
| @@ -7,6 +7,7 @@ import ( |
| "net/http/httptest" |
| "net/url" |
| "os" |
| + "os/exec" |
| "regexp" |
| "strings" |
| "testing" |
| @@ -20,6 +21,10 @@ import ( |
| // registers answer HTTPS (keymailtest). Before it, every POST /signin |
| // in this suite classified its address against the real network. |
| func TestMain(m *testing.M) { |
| + if os.Getenv(asDeployedEnv) == "1" { |
| + // TestAuthIsBuiltAsDeployed's child: no fixtures, no list. |
| + os.Exit(m.Run()) |
| + } |
| keymailTestServers = []string{keymailHost} |
| restore, err := keymailtest.Install() |
| if err != nil { |
| @@ -255,3 +260,30 @@ func TestKeymailRefusalIsTheDoor(t *testing.T) { |
| t.Fatal("anybody can show the refusal by visiting /signin?err=refused") |
| } |
| } |
| + |
| +const asDeployedEnv = "SHEETS_TEST_AUTH_AS_DEPLOYED" |
| + |
| +// TestAuthIsBuiltAsDeployed: every other test here lists its Keymail |
| +// fixture's host (keymailTestServers), so auth takes its listed-servers |
| +// path. A deployment lists none, and from rastrillo v0.45.0 that path |
| +// builds a public-address-only client from http.DefaultTransport. This |
| +// builds the app that way, in a child process with neither the list nor |
| +// keymailtest's transport, and opens the door. |
| +func TestAuthIsBuiltAsDeployed(t *testing.T) { |
| + if os.Getenv(asDeployedEnv) != "1" { |
| + cmd := exec.Command(os.Args[0], "-test.run=^TestAuthIsBuiltAsDeployed$", "-test.count=1") |
| + cmd.Env = append(os.Environ(), asDeployedEnv+"=1") |
| + if out, err := cmd.CombinedOutput(); err != nil { |
| + t.Fatalf("built as deployed: %v\n%s", err, out) |
| + } |
| + return |
| + } |
| + if keymailTestServers != nil { |
| + t.Fatal("the child lists Keymail servers; it is meant to be built as deployed") |
| + } |
| + app, _ := appWithRecorder(t) |
| + rec := do(t, app, httptest.NewRequest(http.MethodGet, "/signin", nil)) |
| + if rec.Code != http.StatusOK { |
| + t.Fatalf("GET /signin: %d", rec.Code) |
| + } |
| +} |
diff --git a/internal/sheets/rhythm_browser_test.go b/internal/sheets/rhythm_browser_test.go| index 1da6f0a..4be5bcf 100644 |
| --- a/internal/sheets/rhythm_browser_test.go |
| +++ b/internal/sheets/rhythm_browser_test.go |
| @@ -6,6 +6,7 @@ import ( |
| "context" |
| "fmt" |
| "net/http" |
| + "strings" |
| "testing" |
| "time" |
| @@ -40,9 +41,17 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| google := New(Config{DB: app.db, Auth: app.auth, Sealer: app.sealer, Origin: testOrigin, Admit: app.admit, |
| GoogleImport: googleimport.Config{ClientID: "123456789-client.apps.googleusercontent.com", APIKey: "AIzaPublicBrowserKey123456789", AppID: "123456789"}}) |
| - serving := http.Handler(productionHandler(t, app)) |
| - rig := harness.New(t, func(string) http.Handler { |
| - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { serving.ServeHTTP(w, r) }) |
| + // Both instances on one origin: a page asked for with |
| + // ?instance=google, and what it loads, are the Google one's. |
| + served, googleServed := productionHandler(t, app), productionHandler(t, google) |
| + rig := harness.New(t, func(origin string) http.Handler { |
| + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + if r.URL.Query().Get("instance") == "google" || strings.Contains(r.Header.Get("Referer"), "instance=google") { |
| + googleServed.ServeHTTP(w, r) |
| + return |
| + } |
| + served.ServeHTTP(w, r) |
| + }) |
| }) |
| // Each screen is loaded once, at a desktop width, and read there and |
| // again at a phone's. ready is a selector only that screen draws, the |
| @@ -85,7 +94,7 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| } |
| } |
| - audit("the sign-in door", "/signin", `input[name="address"]`, 1, nil) |
| + audit("the sign-in door", "/signin", `[estilo-signin-screen] input[name="address"]`, 1, nil) |
| var set []chromedp.Action[chromedp.Void] |
| for _, c := range cookies { |
| @@ -106,6 +115,5 @@ func TestEveryScreenKeepsTheRhythm(t *testing.T) { |
| audit("import", "/sheets/import", `main input[type=file]`, 2, nil) |
| audit("an import report", report, `[data-import-report]`, 3, nil) |
| - serving = productionHandler(t, google) |
| - audit("import, with Google Drive", "/sheets/import", `main [estilo-google-import], main section h2`, 3, nil) |
| + audit("import, with Google Drive", "/sheets/import?instance=google", `main [estilo-google-import]`, 3, nil) |
| } |