package e2e import ( "context" "io" "net/http" "os/exec" "strings" "testing" "github.com/barerepo/server/internal/store" ) // get reads a page and returns its status, content type and body. func get(t *testing.T, url string) (int, string, string) { t.Helper() resp, err := http.Get(url) if err != nil { t.Fatal(err) } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) return resp.StatusCode, resp.Header.Get("Content-Type"), string(body) } // Chapter 39.4 tells a reader to paste these urls into a feed reader, so all three must answer. func TestEveryPublicFeedInChapter39Answers(t *testing.T) { if _, err := exec.LookPath("git"); err != nil { t.Skip("git is not installed") } ctx := context.Background() in := newInstance(t) john := in.account("john") seed(t, in, john, "john", "johnbot") if err := in.db.Record(ctx, store.Event{Kind: store.ThreadOpened, Actor: "lisa", Repo: "john/johnbot", Number: 47, Title: "the log page is slow"}); err != nil { t.Fatal(err) } for _, path := range []string{"/john.atom", "/john/johnbot.atom", "/john/johnbot/threads.atom"} { code, ctype, body := get(t, in.http.URL+path) if code != http.StatusOK { t.Errorf("%s answered %d, and chapter 39.4 hands this url out", path, code) continue } if !strings.HasPrefix(ctype, "application/atom+xml") { t.Errorf("%s came back as %q, which no feed reader will take", path, ctype) } if !strings.Contains(body, "