MCPcopy
hub / github.com/caddyserver/caddy / TestFileMatcher

Function TestFileMatcher

modules/caddyhttp/fileserver/matcher_test.go:41–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestFileMatcher(t *testing.T) {
42 // Windows doesn't like colons in files names
43 isWindows := runtime.GOOS == "windows"
44 if !isWindows {
45 filename := "with:in-name.txt"
46 f, err := os.Create("./testdata/" + filename)
47 if err != nil {
48 t.Fail()
49 return
50 }
51 t.Cleanup(func() {
52 os.Remove("./testdata/" + filename)
53 })
54 f.WriteString(filename)
55 f.Close()
56 }
57
58 for i, tc := range []testCase{
59 {
60 path: "/foo.txt",
61 expectedPath: "/foo.txt",
62 expectedType: "file",
63 matched: true,
64 },
65 {
66 path: "/foo.txt/",
67 expectedPath: "/foo.txt",
68 expectedType: "file",
69 matched: true,
70 },
71 {
72 path: "/foo.txt?a=b",
73 expectedPath: "/foo.txt",
74 expectedType: "file",
75 matched: true,
76 },
77 {
78 path: "/foodir",
79 expectedPath: "/foodir/",
80 expectedType: "directory",
81 matched: true,
82 },
83 {
84 path: "/foodir/",
85 expectedPath: "/foodir/",
86 expectedType: "directory",
87 matched: true,
88 },
89 {
90 path: "/foodir/foo.txt",
91 expectedPath: "/foodir/foo.txt",
92 expectedType: "file",
93 matched: true,
94 },
95 {
96 path: "/missingfile.php",
97 matched: false,
98 },

Callers

nothing calls this directly

Calls 3

fileMatcherTestFunction · 0.85
CleanupMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected