-
Notifications
You must be signed in to change notification settings - Fork 51
/
utils_test.go
151 lines (133 loc) · 4.37 KB
/
utils_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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package enry
import (
"bytes"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsVendor(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{name: "TestIsVendor_1", path: "foo/bar", expected: false},
{name: "TestIsVendor_2", path: "foo/vendor/foo", expected: true},
{name: "TestIsVendor_3", path: ".sublime-project", expected: true},
{name: "TestIsVendor_4", path: "leaflet.draw-src.js", expected: true},
{name: "TestIsVendor_5", path: "foo/bar/MochiKit.js", expected: true},
{name: "TestIsVendor_6", path: "foo/bar/dojo.js", expected: true},
{name: "TestIsVendor_7", path: "foo/env/whatever", expected: true},
{name: "TestIsVendor_8", path: "foo/.imageset/bar", expected: true},
{name: "TestIsVendor_9", path: "Vagrantfile", expected: true},
}
for _, test := range tests {
is := IsVendor(test.path)
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestIsDocumentation(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{name: "TestIsDocumentation_1", path: "foo", expected: false},
{name: "TestIsDocumentation_2", path: "README", expected: true},
}
for _, test := range tests {
is := IsDocumentation(test.path)
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestIsImage(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{name: "TestIsImage_1", path: "invalid.txt", expected: false},
{name: "TestIsImage_2", path: "image.png", expected: true},
{name: "TestIsImage_3", path: "image.jpg", expected: true},
{name: "TestIsImage_4", path: "image.jpeg", expected: true},
{name: "TestIsImage_5", path: "image.gif", expected: true},
}
for _, test := range tests {
is := IsImage(test.path)
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestGetMimeType(t *testing.T) {
tests := []struct {
name string
path string
lang string
expected string
}{
{name: "TestGetMimeType_1", path: "text.txt", lang: "", expected: "text/plain"},
{name: "TestGetMimeType_2", path: "file.go", lang: "Go", expected: "text/x-go"},
{name: "TestGetMimeType_3", path: "image.png", lang: "", expected: "image/png"},
}
for _, test := range tests {
is := GetMIMEType(test.path, test.lang)
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestIsConfiguration(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{name: "TestIsConfiguration_1", path: "foo", expected: false},
{name: "TestIsConfiguration_2", path: "foo.ini", expected: true},
{name: "TestIsConfiguration_3", path: "/test/path/foo.json", expected: true},
}
for _, test := range tests {
is := IsConfiguration(test.path)
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestIsBinary(t *testing.T) {
tests := []struct {
name string
data []byte
expected bool
}{
{name: "TestIsBinary_1", data: []byte("foo"), expected: false},
{name: "TestIsBinary_2", data: []byte{0}, expected: true},
{name: "TestIsBinary_3", data: bytes.Repeat([]byte{'o'}, 8000), expected: false},
}
for _, test := range tests {
is := IsBinary(test.data)
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestIsDotFile(t *testing.T) {
tests := []struct {
name string
path string
expected bool
}{
{name: "TestIsDotFile_1", path: "foo/bar/./", expected: false},
{name: "TestIsDotFile_2", path: "./", expected: false},
}
for _, test := range tests {
is := IsDotFile(test.path)
assert.Equal(t, test.expected, is, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
}
}
func TestGetColor(t *testing.T) {
tests := []struct {
name string
language string
expected string
}{
{name: "TestGetColor_1", language: "Go", expected: "#00ADD8"},
{name: "TestGetColor_2", language: "SomeRandom", expected: "#cccccc"},
}
for _, test := range tests {
color := GetColor(test.language)
assert.Equal(t, test.expected, color, fmt.Sprintf("%v: is = %v, expected: %v", test.name, color, test.expected))
}
}