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
|
package build_test
import (
"testing"
"github.com/stretchr/testify/assert"
"phabricator.wikimedia.org/source/blubber/build"
)
func TestRun(t *testing.T) {
i := build.Run{"echo %s %s", []string{"foo bar", "baz"}}
assert.Equal(t, []string{`echo "foo bar" "baz"`}, i.Compile())
}
func TestRunWithInnerAndOuterArguments(t *testing.T) {
i := build.Run{"useradd -d %s -u %s", []string{"/foo", "666", "bar"}}
assert.Equal(t, []string{`useradd -d "/foo" -u "666" "bar"`}, i.Compile())
}
func TestRunAll(t *testing.T) {
i := build.RunAll{[]build.Run{
{"echo %s", []string{"foo"}},
{"cat %s", []string{"/bar"}},
{"baz", []string{}},
}}
assert.Equal(t, []string{`echo "foo" && cat "/bar" && baz`}, i.Compile())
}
func TestCopy(t *testing.T) {
i := build.Copy{[]string{"source1", "source2"}, "dest"}
assert.Equal(t, []string{`"source1"`, `"source2"`, `"dest"`}, i.Compile())
}
func TestCopyFrom(t *testing.T) {
i := build.CopyFrom{"foo", build.Copy{[]string{"source1", "source2"}, "dest"}}
assert.Equal(t, []string{"foo", `"source1"`, `"source2"`, `"dest"`}, i.Compile())
}
func TestEnv(t *testing.T) {
i := build.Env{map[string]string{
"fooname": "foovalue",
"barname": "barvalue",
"quxname": "quxvalue",
}}
assert.Equal(t, []string{
`barname="barvalue"`,
`fooname="foovalue"`,
`quxname="quxvalue"`,
}, i.Compile())
}
func TestVolume(t *testing.T) {
i := build.Volume{"/foo/dir"}
assert.Equal(t, []string{`"/foo/dir"`}, i.Compile())
}
|