internal/httpd/crumbs_test.go
34 lines · 1071 bytes
1package httpd
2
3import (
4 "testing"
5
6 "gitbay.org/gitbay/internal/store"
7)
8
9// TestCrumbsLinkDirectoriesToTree: on a blob or blame page the parent
10// crumbs are directories, so they link to the tree; only the leaf keeps the
11// page's kind. They used to carry the page's kind throughout, and
12// /blob/<ref>/<dir> is a 404 (#103).
13func TestCrumbsLinkDirectoriesToTree(t *testing.T) {
14 p := repoPage{Repo: store.Repo{OwnerName: "krz", Name: "gitbay"}, Ref: "main"}
15 for _, kind := range []string{"blob", "blame", "tree"} {
16 cs := crumbs(p, kind, "internal/control/control.go")
17 want := []string{
18 "/krz/gitbay/tree/main/internal",
19 "/krz/gitbay/tree/main/internal/control",
20 "/krz/gitbay/" + kind + "/main/internal/control/control.go",
21 }
22 if len(cs) != len(want) {
23 t.Fatalf("%s: %d crumbs, want %d", kind, len(cs), len(want))
24 }
25 for i, c := range cs {
26 if c.URL != want[i] {
27 t.Errorf("%s crumb %d: %s, want %s", kind, i, c.URL, want[i])
28 }
29 }
30 }
31 if cs := crumbs(p, "tree", ""); len(cs) != 0 {
32 t.Errorf("root: %d crumbs, want none", len(cs))
33 }
34}