-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmime_test.go
62 lines (50 loc) · 1.4 KB
/
mime_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
56
57
58
59
60
61
62
package mango
import (
"testing"
)
func TestMimeType(t *testing.T) {
test := func(value, expected string) {
found := MimeType(value, "")
if found != expected {
t.Error("Expected", value, "to have mime type:", expected, "got:", found)
}
}
test(".css", "text/css")
test(".js", "application/javascript")
}
func TestMimeTypeFallback(t *testing.T) {
value := "bogus"
expected := "fallback/value"
found := MimeType(value, expected)
if found != expected {
t.Error("Expected", value, "to have fallback mime type:", expected, "got:", found)
}
}
func TestAddingMimeTypes(t *testing.T) {
value := ".new"
expected := "new/type"
fallback := "fallback/type"
found := MimeType(value, fallback)
if found != fallback {
t.Error("Expected", value, "to have fallback mime type:", fallback, "got:", found)
}
MimeTypes[".new"] = "new/type"
found = MimeType(value, fallback)
if found != expected {
t.Error("Expected", value, "to have new mime type:", expected, "got:", found)
}
}
func TestRemovingMimeTypes(t *testing.T) {
value := ".jpg"
expected := "image/jpeg"
fallback := "fallback/type"
found := MimeType(value, fallback)
if found != expected {
t.Error("Expected", value, "to have mime type:", expected, "got:", found)
}
delete(MimeTypes, ".jpg")
found = MimeType(value, fallback)
if found != fallback {
t.Error("Expected", value, "to have fallback mime type:", fallback, "got:", found)
}
}