-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfs_test.go
55 lines (47 loc) · 1.08 KB
/
fs_test.go
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
49
50
51
52
53
54
55
package lungo
import (
"net/http"
"net/http/httptest"
"reflect"
"testing"
)
func TestFileServer(t *testing.T) {
var tests = []struct {
dir string
path string
contentType string
}{
{
dir: ".github/",
path: "/labeler.yml",
contentType: "application/x-yaml",
},
{
dir: ".github/",
path: "labeler.yml",
contentType: "application/x-yaml",
},
{
dir: "./",
path: "labeler.yml",
contentType: "",
},
}
for _, testcase := range tests {
req, err := http.NewRequest("GET", testcase.path, nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
h := FileHandler(testcase.dir)
h.ServeHTTP(&Context{
Request: req,
Response: rr,
})
header := rr.Header()
ct := header.Get(HeaderContentType)
if ct != testcase.contentType && ct != MIMETextPlainCharsetUTF8 {
t.Errorf("Test %s: Expected HTTP Content-Type to be either `%v` or `%v` (type string), Received `%v` (type %v)", t.Name(), testcase.contentType, "text/plain; charset=utf-8", ct, reflect.TypeOf(ct))
}
}
}