This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 267
/
Copy pathconfig_test.go
82 lines (74 loc) · 2.04 KB
/
config_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
package main
import (
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLinterConfigUnmarshalJSON(t *testing.T) {
source := `{
"Command": "/bin/custom",
"PartitionStrategy": "directories"
}`
var config StringOrLinterConfig
err := json.Unmarshal([]byte(source), &config)
require.NoError(t, err)
assert.Equal(t, "/bin/custom", config.Command)
assert.Equal(t, functionName(partitionPathsAsDirectories), functionName(config.PartitionStrategy))
}
func TestFindDefaultConfigFile(t *testing.T) {
tmpdir, cleanup := setupTempDir(t)
defer cleanup()
mkDir(t, tmpdir, "contains")
mkDir(t, tmpdir, "contains", "foo")
mkDir(t, tmpdir, "contains", "foo", "bar")
mkDir(t, tmpdir, "contains", "double")
mkDir(t, tmpdir, "lacks")
mkFile(t, filepath.Join(tmpdir, "contains"), defaultConfigPath, "{}")
mkFile(t, filepath.Join(tmpdir, "contains", "double"), defaultConfigPath, "{}")
var testcases = []struct {
dir string
expected string
found bool
}{
{
dir: tmpdir,
expected: "",
found: false,
},
{
dir: filepath.Join(tmpdir, "contains"),
expected: filepath.Join(tmpdir, "contains", defaultConfigPath),
found: true,
},
{
dir: filepath.Join(tmpdir, "contains", "foo"),
expected: filepath.Join(tmpdir, "contains", defaultConfigPath),
found: true,
},
{
dir: filepath.Join(tmpdir, "contains", "foo", "bar"),
expected: filepath.Join(tmpdir, "contains", defaultConfigPath),
found: true,
},
{
dir: filepath.Join(tmpdir, "contains", "double"),
expected: filepath.Join(tmpdir, "contains", "double", defaultConfigPath),
found: true,
},
{
dir: filepath.Join(tmpdir, "lacks"),
expected: "",
found: false,
},
}
for _, testcase := range testcases {
require.NoError(t, os.Chdir(testcase.dir))
configFile, found, err := findDefaultConfigFile()
assert.Equal(t, testcase.expected, configFile)
assert.Equal(t, testcase.found, found)
assert.NoError(t, err)
}
}