-
Notifications
You must be signed in to change notification settings - Fork 219
/
Copy pathdefault_test.go
68 lines (65 loc) · 2.3 KB
/
default_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
package config
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestMachineVolumes(t *testing.T) {
t.Setenv("env1", "/test1")
t.Setenv("env2", "/test2")
for _, tc := range []struct {
msg string
volumes []string
output []string
assert func(err error, in, out []string, msg string)
}{
{
volumes: []string{},
output: []string{},
assert: func(err error, in, out []string, msg string) {
assert.Equal(t, in, out)
assert.Nil(t, err, msg)
},
},
{
volumes: []string{"/foobar:/foobar", "/foobar1:/foobardest:ro", "$env1:/env1", "$env1:$env1", "$env2:$env1"},
output: []string{"/foobar:/foobar", "/foobar1:/foobardest:ro", "/test1:/env1", "/test1:/test1", "/test2:/test1"},
assert: func(err error, in, out []string, msg string) {
assert.Equal(t, in, out)
assert.Nil(t, err, msg)
},
},
{
volumes: []string{"/foobar:/foobar", "/foobar1:/foobardest:ro", "$env1:/env1", "$env1:$env1", "$env3:$env1"},
output: []string{"/foobar:/foobar", "/foobar1:/foobardest:ro", "/test1:/env1", "/test1:/test1", "/test2:/test1"},
assert: func(err error, in, out []string, msg string) {
assert.EqualError(t, err, "invalid machine volume $env3:$env1, fields must container data", msg)
},
},
{
volumes: []string{"/foobar:/foobar", "/foobar1:/foobardest:ro", "$env1:/env1", "$env1:$env4", "$env1:$env1"},
output: []string{"/foobar:/foobar", "/foobar1:/foobardest:ro", "/test1:/env1", "/test1:/test1", "/test2:/test1"},
assert: func(err error, in, out []string, msg string) {
assert.EqualError(t, err, "invalid machine volume $env1:$env4, fields must container data", msg)
},
},
{
msg: "This is broken",
volumes: []string{"/foobar:/foobar:ro:badopt"},
output: []string{"/foobar:/foobar:ro"},
assert: func(err error, in, out []string, msg string) {
assert.EqualError(t, err, "invalid machine volume /foobar:/foobar:ro:badopt, 2 or 3 fields required", msg)
},
},
{
msg: "This is broken2",
volumes: []string{"/foobar"},
output: []string{"/foobar:/foobar:ro"},
assert: func(err error, in, out []string, msg string) {
assert.EqualError(t, err, "invalid machine volume /foobar, 2 or 3 fields required", msg)
},
},
} {
output, err := machineVolumes(tc.volumes)
tc.assert(err, tc.output, output, tc.msg)
}
}