-
Notifications
You must be signed in to change notification settings - Fork 0
/
mine_type_test.go
112 lines (92 loc) · 2.21 KB
/
mine_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package mime
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestGetMimeTypes_EmptyExtensions(t *testing.T) {
tests := map[string]string{
"blank": "",
"new line": "\n",
"tab": "\t",
"spaces": " ",
}
for name, ext := range tests {
t.Run(name, func(t *testing.T) {
res, err := GetMimeTypes(ext)
assert.Nil(t, res)
assert.ErrorIs(t, err, ErrBlankExt)
})
}
}
func TestGetExtensions_EmptyMimeTypes(t *testing.T) {
tests := map[string]string{
"blank": "",
"new line": "\n",
"tab": "\t",
"spaces": " ",
}
for name, mt := range tests {
t.Run(name, func(t *testing.T) {
res, err := GetExtensions(mt)
assert.Nil(t, res)
assert.ErrorIs(t, err, ErrBlankMimeType)
})
}
}
func TestGetMimeTypes_NotFound(t *testing.T) {
tests := map[string]string{
"uuid": "dae5b3d9-3c52-4716-9cc6-b6a05fa256a4",
"Jon Snow": "Jon Snow",
"time": time.Now().Format("02-Mar-2006 15:04:05"),
}
for name, mt := range tests {
t.Run(name, func(t *testing.T) {
res, err := GetMimeTypes(mt)
assert.Nil(t, res)
assert.ErrorIs(t, err, ErrMimeTypesNotFound)
})
}
}
func TestGetExtensions_NotFound(t *testing.T) {
tests := map[string]string{
"uuid": "00000000-0000-0000-0000-000000000000",
"Arya Stark": "Arya Stark",
"time": time.Now().Format("02-Mar-2006 15:04:05"),
}
for name, mt := range tests {
t.Run(name, func(t *testing.T) {
res, err := GetExtensions(mt)
assert.Nil(t, res)
assert.ErrorIs(t, err, ErrExtensionsNotFound)
})
}
}
func TestGetExtensions_OK(t *testing.T) {
tests := map[string][]string{
"application/pdf": {"pdf"},
"text/yaml": {"yaml", "yml"},
"text/css": {"css"},
"image/png": {"png"},
}
for name, exts := range tests {
t.Run(name, func(t *testing.T) {
res, err := GetExtensions(name)
assert.Nil(t, err)
assert.Equal(t, exts, res)
})
}
}
func TestGetMimeTypes_OK(t *testing.T) {
tests := map[string][]string{
".twig": {"text/x-twig"},
"tar.gz": {"application/x-compressed-tar"},
}
for name, exts := range tests {
t.Run(name, func(t *testing.T) {
res, err := GetMimeTypes(name)
assert.Nil(t, err)
assert.Equal(t, exts, res)
})
}
}