package main import ( "context" "crypto/ecdh" "crypto/rand" "encoding/base64" "encoding/json" "net/http" "net/http/httptest" "path/filepath" "strings" "testing" "amadan.net/rastrillo/rastrillo/db" "amadan.net/rastrillo/rastrillo/migrate" "amadan.net/rastrillo/rastrillo/sessions" "amadan.net/rastrillo/aviso" ) func newApp(t *testing.T) (http.Handler, *aviso.Service) { t.Helper() d, err := db.Open(filepath.Join(t.TempDir(), "example.db"), nil) if err != nil { t.Fatal(err) } t.Cleanup(func() { d.Close() }) if _, err := migrate.Apply(context.Background(), d, migrate.Merge(sessions.Schema, aviso.Schema)); err != nil { t.Fatal(err) } key, _ := aviso.GenerateKey() svc, err := aviso.New(aviso.Config{DB: d.Writer(), PrivateKey: key, Contact: "mailto:ops@example.test", Origin: "http://localhost:8080"}) if err != nil { t.Fatal(err) } return handler(svc, "http://localhost:8080"), svc } func get(t *testing.T, h http.Handler, path string) *httptest.ResponseRecorder { t.Helper() w := httptest.NewRecorder() h.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil)) return w } // Every seam answers: the page, the two embedded JS files, the // worker at root scope, the key, and a subscribe that lands as "dev". func TestEverySeamIsWired(t *testing.T) { h, svc := newApp(t) for path, want := range map[string]string{ "/": "