| 1 | package main |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestBuildTemplates(t *testing.T) { |
| 6 | tmpls, err := buildTemplates() |
| 7 | if err != nil { |
| 8 | t.Fatalf("buildTemplates: %v", err) |
| 9 | } |
| 10 | for _, name := range []string{"index.html", "repo.html", "tree.html", "blob.html", "log.html", "commit.html", "refs.html", "404.html"} { |
| 11 | if _, ok := tmpls[name]; !ok { |
| 12 | t.Errorf("missing template: %s", name) |
| 13 | } |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | func TestParseArchiveName(t *testing.T) { |
| 18 | cases := []struct { |
| 19 | in string |
| 20 | ref string |
| 21 | format string |
| 22 | ok bool |
| 23 | }{ |
| 24 | {"main.tar.gz", "main", "tar.gz", true}, |
| 25 | {"v1.0.0.zip", "v1.0.0", "zip", true}, |
| 26 | {"abc.tgz", "abc", "tar.gz", true}, |
| 27 | {"main", "", "", false}, |
| 28 | } |
| 29 | for _, c := range cases { |
| 30 | ref, format, ok := parseArchiveName(c.in) |
| 31 | if ok != c.ok || ref != c.ref || format != c.format { |
| 32 | t.Errorf("%q → (%q, %q, %v), want (%q, %q, %v)", c.in, ref, format, ok, c.ref, c.format, c.ok) |
| 33 | } |
| 34 | } |
| 35 | } |