forked from warpfork/pogo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathshell_test.go
104 lines (93 loc) · 2.44 KB
/
shell_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
102
103
104
package gosh
import (
"bytes"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestMergineOptss(t *testing.T) {
Convey("Merging command templates", t, func() {
one := Opts{
Args: []string{"one"},
Env: Env{
"one": "one",
},
}
two := Opts{
Args: []string{"two"},
Env: Env{
"two": "two",
},
}
three := one.Merge(two)
Convey("Args should join", func() {
So(three.Args, ShouldResemble, []string{"one", "two"})
})
Convey("Args on the parents should be unchanged", FailureContinues, func() {
So(one.Args, ShouldResemble, []string{"one"})
So(two.Args, ShouldResemble, []string{"two"})
})
Convey("Env should join", func() {
So(three.Env, ShouldResemble, Env{"one": "one", "two": "two"})
})
Convey("Env on the parents should be unchanged", FailureContinues, func() {
So(one.Env, ShouldResemble, Env{"one": "one"})
So(two.Env, ShouldResemble, Env{"two": "two"})
})
})
}
func TestInvocationBehaviors(t *testing.T) {
// still presumes exec as the backing invoker, regretably
Convey("Given a command that will succeed", t, func() {
cmd := Opts{
Args: []string{"echo", "success"},
}
Convey("RunAndReport should have no comment", func() {
Gosh(cmd).RunAndReport()
})
})
Convey("Given a command that will exit with 12", t, func() {
cmd := Opts{
Args: []string{"bash", "-c", "echo failuremessage 1>&2; exit 12"},
}
Convey("RunAndReport should panic; error should include output", func() {
defer func() {
err := recover()
So(err, ShouldNotBeNil)
So(err, ShouldHaveSameTypeAs, FailureExitCode{})
errExit := err.(FailureExitCode)
So(errExit.Message, ShouldEqual, "failuremessage\n")
}()
Gosh(cmd).RunAndReport()
})
})
}
func TestExecIntegration(t *testing.T) {
Convey("Given a command template", t, func() {
cmd := Opts{
Args: []string{"true"},
}
Convey("We should be able to invoke it", func() {
p := ExecLauncher(cmd)
Convey("It should return", func() {
So(p.GetExitCode(), ShouldEqual, 0)
})
})
})
Convey("Given a command template with outputs", t, func() {
var buf bytes.Buffer
cmd := Opts{
Args: []string{"echo", "msg"},
Out: &buf,
}
Convey("We should be able to invoke it", func() {
p := ExecLauncher(cmd)
Convey("It should return", func() {
So(p.GetExitCode(), ShouldEqual, 0)
})
Convey("It should emit output", func() {
p.Wait()
So(buf.String(), ShouldEqual, "msg\n")
})
})
})
}