-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
44 lines (37 loc) · 957 Bytes
/
main_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
// Path: main_test.go
// Test the HTTP server by starting it and querying it
// for custom.bar and custom.foo, then verifying that their
// custom mime-types match the ones defined in mime.go.
package main
import (
"log"
"net/http"
"net/http/httptest"
"testing"
)
func TestServeFile(t *testing.T) {
log.Println("Testing file serving ...")
ts := httptest.NewServer(http.HandlerFunc(serveFile))
defer ts.Close()
if err := addMimeTypes(); err != nil {
t.Fatal(err)
}
for _, tt := range []struct {
path, want string
}{
{"/custom.bar", "application/json"},
{"/custom.foo", "foo/bar"},
} {
log.Println("Testing", tt.path, "...")
res, err := http.Get(ts.URL + tt.path)
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()
if got := res.Header.Get("Content-Type"); got != tt.want {
t.Errorf("Content-Type: got %q, want %q", got, tt.want)
} else {
log.Printf("Content-Type: got %q, want %q", got, tt.want)
}
}
}