internal/httpd/notfound_test.go

8dcfa45a8ac03a5ff9c36828274d05acadcf846c
gitbay/internal/httpd/notfound_test.go history · blame · raw

26 lines · 833 bytes

 1package httpd
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8// A path no route matches renders the 404 page, the same one a missing
 9// record gets, instead of net/http's plain-text body (#232).
10func TestUnmatchedPathRendersNotFoundPage(t *testing.T) {
11	h := plainServer().Handler()
12	// One and two segment paths are owner and repository routes, which
13	// need a store; these fall past every pattern.
14	for _, p := range []string{"/krz/gitbay/mrs/315/files", "/krz/gitbay/nothing/at/all"} {
15		w := get(t, h, p, nil)
16		if w.Code != 404 {
17			t.Errorf("%s: status %d", p, w.Code)
18		}
19		if ct := w.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/html") {
20			t.Errorf("%s: content type %q", p, ct)
21		}
22		if !strings.Contains(w.Body.String(), "Page not found") {
23			t.Errorf("%s: body is not the 404 page:\n%s", p, w.Body.String())
24		}
25	}
26}