-
Notifications
You must be signed in to change notification settings - Fork 4
/
config_test.go
101 lines (78 loc) · 2.31 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"os"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseConfig_CliCmds(t *testing.T) {
args := []string{"foo", "bar"}
cliCmds = argSlice(args)
defer func() { cliCmds = nil }()
c, err := parseConfig()
require.NoError(t, err)
assert.Equal(t, args, c.Build)
}
func TestParseConfig_NoSnagFile(t *testing.T) {
wd, tmpDir := tmpDirectory(t)
defer os.RemoveAll(tmpDir)
chdir(t, tmpDir)
defer os.Chdir(wd)
_, err := parseConfig()
require.Error(t, err)
assert.Equal(t, `could not find ".snag.yml" in your current directory`, err.Error())
}
func TestParseConfig_FunkyYml(t *testing.T) {
wd, tmpDir := tmpDirectory(t)
defer os.RemoveAll(tmpDir)
chdir(t, tmpDir)
defer os.Chdir(wd)
writeSnagFile(t, "I like to thing I'm yaml")
_, err := parseConfig()
require.Error(t, err)
rx := regexp.MustCompile(`^could not parse snag file: .+`)
assert.Regexp(t, rx, err.Error())
}
func TestParseConfig_ScriptAndBuild(t *testing.T) {
wd, tmpDir := tmpDirectory(t)
defer os.RemoveAll(tmpDir)
chdir(t, tmpDir)
defer os.Chdir(wd)
writeSnagFile(t, "verbose: true\nbuild:\n - echo 'hello'\nscript:\n - echo 'hello'")
_, err := parseConfig()
require.Error(t, err)
assert.Equal(t, "cannot use 'script' and 'build' together. The 'script' tag is deprecated, please use 'build' instead.", err.Error())
}
func TestParseConfig_Script(t *testing.T) {
wd, tmpDir := tmpDirectory(t)
defer os.RemoveAll(tmpDir)
chdir(t, tmpDir)
defer os.Chdir(wd)
writeSnagFile(t, "verbose: true\nscript:\n - echo 'hello'")
c, err := parseConfig()
require.NoError(t, err)
assert.Equal(t, []string{"echo 'hello'"}, c.Build)
}
func TestParseConfig_EmptyBuild(t *testing.T) {
wd, tmpDir := tmpDirectory(t)
defer os.RemoveAll(tmpDir)
chdir(t, tmpDir)
defer os.Chdir(wd)
writeSnagFile(t, "verbose: true")
_, err := parseConfig()
require.Error(t, err)
assert.Equal(t, "you must specify at least 1 command.", err.Error())
}
func TestParseConfig_Verbose(t *testing.T) {
verbose = true
defer func() { verbose = false }()
wd, tmpDir := tmpDirectory(t)
defer os.RemoveAll(tmpDir)
chdir(t, tmpDir)
defer os.Chdir(wd)
writeSnagFile(t, "build:\n - echo 'hello'")
c, err := parseConfig()
require.NoError(t, err)
assert.True(t, c.Verbose, "verbosity was not set correctly")
}