oficina / calendar Public

wip: line cap

claude agent, operated by paul@keymail.dev 276b1f9d16f90d079c31514c8bfc996655a55552 parent 5b30629
2 files changed, +57 −39
  • internal/calendar/auth_deployed_test.go +56 −0
  • internal/calendar/keymail_signin_test.go +1 −39

CI passed — run details

CI log
=== vet ===
go vet ./...
go vet -tags browser ./internal/calendartest/ ./internal/calendar/
=== fmt ===
=== spacing ===
go tool fiesta spacing -skip tokens.css internal/calendar/static
=== test ===
go test ./...
ok  	amadan.net/oficina/calendar/cmd/calendar	(cached)
?   	amadan.net/oficina/calendar/cmd/calendar-contract	[no test files]
ok  	amadan.net/oficina/calendar/internal/calendar	28.312s
?   	amadan.net/oficina/calendar/internal/calendar/icons	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/keymailtest	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/seal	[no test files]
?   	amadan.net/oficina/calendar/internal/calendar/teamstate	[no test files]
ok  	amadan.net/oficina/calendar/internal/calendartest	4.062s
ok  	amadan.net/oficina/calendar/internal/guardstest	0.095s
?   	amadan.net/oficina/calendar/scripts/writeestilo	[no test files]
=== migration-check ===
go tool rastrillo migration check
rastrillo migration check: models and migrations agree
diff --git a/internal/calendar/auth_deployed_test.go b/internal/calendar/auth_deployed_test.go
new file mode 100644
index 0000000..8c373ed
--- /dev/null
+++ b/internal/calendar/auth_deployed_test.go
@@ -0,0 +1,56 @@
+package calendar
+
+import (
+ "io"
+ "log/slog"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "testing"
+)
+
+const asDeployedEnv = "CALENDAR_TEST_AUTH_AS_DEPLOYED"
+
+// listKeymailFixtures is TestMain's first step. It lists the Keymail
+// fixture's host for every test here (SetKeymailServersForTest), except
+// in TestAuthIsBuiltAsDeployed's child, which it runs with no fixtures
+// and no list, and exits.
+func listKeymailFixtures(m *testing.M) {
+ if os.Getenv(asDeployedEnv) == "1" {
+ os.Exit(m.Run())
+ }
+ SetKeymailServersForTest([]string{keymailHost})
+}
+
+// TestAuthIsBuiltAsDeployed: every other test here lists its Keymail
+// fixture's host (SetKeymailServersForTest), 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")
+ }
+ a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: "https://calendar.example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil))})
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { a.Close() })
+ rec := httptest.NewRecorder()
+ a.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "https://calendar.example.test/signin", nil))
+ if rec.Code != http.StatusOK {
+ t.Fatalf("GET /signin: %d", rec.Code)
+ }
+}
diff --git a/internal/calendar/keymail_signin_test.go b/internal/calendar/keymail_signin_test.go
index 112effe..5b33f94 100644
--- a/internal/calendar/keymail_signin_test.go
+++ b/internal/calendar/keymail_signin_test.go
@@ -13,7 +13,6 @@ import (
"net/http/httptest"
"net/url"
"os"
- "os/exec"
"path/filepath"
"regexp"
"strings"
@@ -30,11 +29,7 @@ import (
// query is answered NXDOMAIN and only the Keymail fixtures a test
// registers answer HTTPS (keymailtest).
func TestMain(m *testing.M) {
- if os.Getenv(asDeployedEnv) == "1" {
- // TestAuthIsBuiltAsDeployed's child: no fixtures, no list.
- os.Exit(m.Run())
- }
- SetKeymailServersForTest([]string{keymailHost})
+ listKeymailFixtures(m)
restore, err := keymailtest.Install()
if err != nil {
fmt.Fprintln(os.Stderr, "keymailtest.Install:", err)
@@ -302,36 +297,3 @@ func TestKeymailRefusalIsTheDoor(t *testing.T) {
})
}
}
-
-const asDeployedEnv = "CALENDAR_TEST_AUTH_AS_DEPLOYED"
-
-// TestAuthIsBuiltAsDeployed: every other test here lists its Keymail
-// fixture's host (SetKeymailServersForTest), 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")
- }
- a, err := New(Config{DBPath: filepath.Join(t.TempDir(), "calendar.db"), Env: "development", Origin: "https://calendar.example.test", Logger: slog.New(slog.NewTextHandler(io.Discard, nil))})
- if err != nil {
- t.Fatal(err)
- }
- t.Cleanup(func() { a.Close() })
- rec := httptest.NewRecorder()
- a.Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "https://calendar.example.test/signin", nil))
- if rec.Code != http.StatusOK {
- t.Fatalf("GET /signin: %d", rec.Code)
- }
-}