~james/core

core/gitutil/readme_test.go -rw-r--r-- 1.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 14 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package gitutil

import "testing"

func TestIsReadmeFile(t *testing.T) {
	const (
		fileMode = "100644"
		execMode = "100755"
		dirMode  = "040000"
	)

	cases := []struct {
		name string
		mode string
		want bool
	}{
		{"README.md", fileMode, true},
		{"ReadMe.MD", fileMode, true},
		{"readme", fileMode, true},
		{"README", execMode, true},

		// regression: a directory named "readme" must not be picked up
		// as the README blob; tree handlers used to fetch it and 503.
		{"readme", dirMode, false},
		{"README.md", dirMode, false},

		// readme is matched by convention, not by renderable format;
		// unsupported markup falls through to plaintext in GetFormat.
		{"README.rst", fileMode, true},
		{"README.foo", fileMode, true},

		{"README.Music.md", fileMode, false},
		{"readme-old", fileMode, false},
		{"readme_legacy", fileMode, false},
		{"notreadme.md", fileMode, false},
		{"READMEISH", fileMode, false},
		{"README.md", "", false},
		{"README.md", "120000", false}, // symlink
	}

	for _, c := range cases {
		t.Run(c.name+"/"+c.mode, func(t *testing.T) {
			if got := IsReadmeFile(c.name, c.mode); got != c.want {
				t.Errorf("IsReadmeFile(%q, %q) = %v, want %v", c.name, c.mode, got, c.want)
			}
		})
	}
}