main pico / pkg / apps / feeds / api_test.go
Antonio Mika  ·  2026-10-10
 1package feeds
 2
 3import (
 4	"log/slog"
 5	"net/http"
 6	"net/http/httptest"
 7	"testing"
 8
 9	"github.com/picosh/pico/pkg/db"
10	"github.com/picosh/pico/pkg/db/stub"
11)
12
13func TestRoutes(t *testing.T) {
14	t.Chdir("../../..")
15	cfg := NewConfig("feeds-test")
16	cfg.Logger = slog.New(slog.DiscardHandler)
17	web := &webRouter{cfg: cfg, db: stub.NewPostsDB(cfg.Logger, &db.User{ID: "user-1"})}
18	mux := web.mux()
19
20	for _, tt := range []struct {
21		url    string
22		status int
23	}{
24		{url: "/", status: http.StatusOK},
25		{url: "/main.css", status: http.StatusOK},
26		{url: "/keep-alive/missing", status: http.StatusNotFound},
27		{url: "/unsub/missing", status: http.StatusNotFound},
28		{url: "/missing", status: http.StatusNotFound},
29	} {
30		res := httptest.NewRecorder()
31		mux.ServeHTTP(res, httptest.NewRequest(http.MethodGet, "https://"+cfg.Domain+tt.url, nil))
32		if res.Code != tt.status {
33			t.Errorf("%s = %d, want %d", tt.url, res.Code, tt.status)
34		}
35	}
36}