This repository has been archived by the owner on Mar 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexecutor_test.go
89 lines (78 loc) · 1.69 KB
/
executor_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
package runn_test
import (
"errors"
"os/exec"
"testing"
"github.com/stretchr/testify/require"
"github.com/typical-go/runn"
)
type RunnerImplementationWithError struct{}
func (i RunnerImplementationWithError) Run() error { return errors.New("some-runner-error") }
type RunnerImplementationNoError struct{}
func (i RunnerImplementationNoError) Run() error { return nil }
func TestExecutor_All(t *testing.T) {
testcases := []struct {
stopWhenError bool
stmts []interface{}
err error
}{
{
false,
[]interface{}{
errors.New("error1"),
RunnerImplementationWithError{},
errors.New("error2"),
exec.Command("wrong-command", "bad-argument"),
},
errors.New("error1; some-runner-error; error2; exec: \"wrong-command\": executable file not found in $PATH"),
},
{
true,
[]interface{}{
errors.New("error1"),
errors.New("unreachable-error"),
},
errors.New("error1"),
},
{
true,
[]interface{}{
RunnerImplementationWithError{},
errors.New("unreachable-error"),
},
errors.New("some-runner-error"),
},
{
true,
[]interface{}{
exec.Command("wrong-command", "bad-argument"),
errors.New("unreachable-error"),
},
errors.New("exec: \"wrong-command\": executable file not found in $PATH"),
},
{
false,
[]interface{}{},
nil,
},
{
false,
[]interface{}{
RunnerImplementationNoError{},
nil,
exec.Command("echo", "hello", "world"),
},
nil,
},
}
for _, tt := range testcases {
err := runn.Executor{
StopWhenError: tt.stopWhenError,
}.Execute(tt.stmts...)
if tt.err == nil {
require.NoError(t, err)
} else {
require.EqualError(t, err, tt.err.Error())
}
}
}