-
Notifications
You must be signed in to change notification settings - Fork 48
/
config_test.go
99 lines (76 loc) · 2.14 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
package config_test
import (
"io/ioutil"
"os"
"testing"
"github.com/bmizerany/assert"
"github.com/tj/robo/config"
)
var s = `
before:
- command: echo "global before"
after:
- command: echo "global after"
foo:
summary: Command foo.
before:
- command: echo "before"
command: echo "foo"
after:
- command: echo "after"
bar:
summary: Command bar.
command: echo "bar"
stage:
summary: Run commands against stage.
command: ssh {{.hosts.stage}} -t robo
prod:
summary: Run commands against prod.
command: ssh {{.hosts.prod}} -t robo
env: ["H={{.hosts.prod}}"]
templates:
list: testing
variables:
region:
euw: europe-west
hosts:
stage: bastion-stage
prod: bastion-prod
dns: "{{ .region.euw }}.{{ .hosts.prod }}"
command: "$(true && echo $?)"
`
func TestNewString(t *testing.T) {
c, err := config.NewString(s)
assert.Equal(t, nil, err)
assert.Equal(t, 4, len(c.Tasks))
assert.Equal(t, nil, c.Eval())
assert.Equal(t, `ssh bastion-stage -t robo`, c.Tasks["stage"].Command)
assert.Equal(t, `ssh bastion-prod -t robo`, c.Tasks["prod"].Command)
assert.Equal(t, `echo "global before"`, c.Before[0].Command)
assert.Equal(t, `echo "global after"`, c.After[0].Command)
assert.Equal(t, `foo`, c.Tasks["foo"].Name)
assert.Equal(t, `Command foo.`, c.Tasks["foo"].Summary)
assert.Equal(t, `echo "foo"`, c.Tasks["foo"].Command)
assert.Equal(t, `echo "before"`, c.Tasks["foo"].Before[0].Command)
assert.Equal(t, `echo "after"`, c.Tasks["foo"].After[0].Command)
assert.Equal(t, `Command bar.`, c.Tasks["bar"].Summary)
assert.Equal(t, `echo "bar"`, c.Tasks["bar"].Command)
assert.Equal(t, []string{"H=bastion-prod"}, c.Tasks["prod"].Env)
// test variables section interpolation
assert.Equal(t, "europe-west.bastion-prod", c.Variables["dns"])
assert.Equal(t, 0, c.Variables["command"])
assert.Equal(t, `testing`, c.Templates.List)
}
func TestNew(t *testing.T) {
b := []byte(s)
f, err := ioutil.TempFile("", "")
assert.Equal(t, nil, err)
file := f.Name()
defer os.Remove(file)
_, err = f.Write(b)
assert.Equal(t, nil, err)
f.Close()
c, err := config.New(file)
assert.Equal(t, nil, err)
assert.Equal(t, file, c.File)
}