-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_type_test.go
71 lines (63 loc) · 1.6 KB
/
media_type_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
63
64
65
66
67
68
69
70
71
package main
import (
"bytes"
"fmt"
"testing"
)
var mediaTypesBuiltin = map[string]string{
".avif": "image/avif",
".css": "text/css; charset=utf-8",
".gif": "image/gif",
".htm": "text/html; charset=utf-8",
".html": "text/html; charset=utf-8",
".jpeg": "image/jpeg",
".jpg": "image/jpeg",
".js": "text/javascript; charset=utf-8",
".json": "application/json",
".mjs": "text/javascript; charset=utf-8",
".pdf": "application/pdf",
".png": "image/png",
".svg": "image/svg+xml",
".wasm": "application/wasm",
".webp": "image/webp",
".xml": "text/xml; charset=utf-8",
}
var mediaTypesExtensions = map[string]string{
".xorby": "application/xorby",
".xml": "application/xml",
}
func TestMediaTypeBuiltins(t *testing.T) {
for ext, expect := range mediaTypesBuiltin {
fpath := fmt.Sprintf("/some/file/path%s", ext)
actual := MediaType(fpath)
if expect != actual {
t.Errorf("expected [%s] to map to [%s] got [%s]",
fpath, expect, actual)
}
}
}
func TestExtendMediaTypesValidTSV(t *testing.T) {
buf := &bytes.Buffer{}
for ext, media_type := range mediaTypesExtensions {
if buf.Len() == 0 {
buf.WriteString("# this is a comment\n")
} else {
buf.WriteString("\n")
}
buf.WriteString(ext)
buf.WriteString("\t")
buf.WriteString(media_type)
}
err := ExtendMediaTypes(buf)
if err != nil {
t.Error("unable to extend media types: ", err)
}
for ext, expect := range mediaTypesExtensions {
fpath := fmt.Sprintf("/some/file/path%s", ext)
actual := MediaType(fpath)
if expect != actual {
t.Errorf("expected [%s] to map to [%s] got [%s]",
fpath, expect, actual)
}
}
}