2017-06-13 11:56:07 +00:00
|
|
|
package enry
|
2016-07-13 17:05:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2017-05-29 08:05:16 +00:00
|
|
|
"fmt"
|
2017-09-30 13:11:48 +00:00
|
|
|
"testing"
|
2016-07-13 17:05:09 +00:00
|
|
|
|
2017-05-29 08:05:16 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2016-07-13 17:05:09 +00:00
|
|
|
)
|
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestIsVendor(t *testing.T) {
|
2017-05-29 08:05:16 +00:00
|
|
|
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},
|
|
|
|
}
|
2016-07-13 17:05:09 +00:00
|
|
|
|
2017-05-29 08:05:16 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
is := IsVendor(test.path)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2017-05-29 08:05:16 +00:00
|
|
|
}
|
2016-07-13 17:05:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestIsDocumentation(t *testing.T) {
|
2017-05-29 08:05:16 +00:00
|
|
|
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)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2017-05-29 08:05:16 +00:00
|
|
|
}
|
2016-07-13 17:05:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestIsImage(t *testing.T) {
|
2018-10-03 18:37:03 +00:00
|
|
|
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)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2018-10-03 18:37:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestGetMimeType(t *testing.T) {
|
2018-10-03 18:54:11 +00:00
|
|
|
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 {
|
2019-02-05 21:54:14 +00:00
|
|
|
is := GetMIMEType(test.path, test.lang)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2018-10-03 18:54:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestIsConfiguration(t *testing.T) {
|
2017-05-29 08:05:16 +00:00
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
path string
|
|
|
|
expected bool
|
|
|
|
}{
|
|
|
|
{name: "TestIsConfiguration_1", path: "foo", expected: false},
|
|
|
|
{name: "TestIsConfiguration_2", path: "foo.ini", expected: true},
|
2017-06-12 11:42:20 +00:00
|
|
|
{name: "TestIsConfiguration_3", path: "/test/path/foo.json", expected: true},
|
2017-05-29 08:05:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
is := IsConfiguration(test.path)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2017-05-29 08:05:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-13 17:05:09 +00:00
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestIsBinary(t *testing.T) {
|
2017-05-29 08:05:16 +00:00
|
|
|
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},
|
|
|
|
}
|
2016-07-13 17:05:09 +00:00
|
|
|
|
2017-05-29 08:05:16 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
is := IsBinary(test.data)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, is, test.expected, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2017-05-29 08:05:16 +00:00
|
|
|
}
|
2016-07-13 17:05:09 +00:00
|
|
|
}
|
2017-09-30 13:11:48 +00:00
|
|
|
|
2018-12-27 10:55:34 +00:00
|
|
|
func TestIsDotFile(t *testing.T) {
|
2017-10-18 04:18:52 +00:00
|
|
|
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)
|
2018-12-27 10:55:34 +00:00
|
|
|
assert.Equal(t, test.expected, is, fmt.Sprintf("%v: is = %v, expected: %v", test.name, is, test.expected))
|
2017-10-18 04:18:52 +00:00
|
|
|
}
|
|
|
|
}
|