internal/httpd/notfound_test.go

28e72be7ab6bc96868893853fd8d210c3656960f
gitbay/internal/httpd/notfound_test.go

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}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form