-
Notifications
You must be signed in to change notification settings - Fork 0
/
yasmim_test.go
88 lines (77 loc) · 2.11 KB
/
yasmim_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
package yasmim
import (
"github.com/stretchr/testify/assert"
"github.com/tsouza/yasmim/pkg/command"
"github.com/tsouza/yasmim/pkg/log"
"github.com/tsouza/yasmim/pkg/option"
"testing"
)
func TestCommands_Simple(t *testing.T) {
type testInputType struct { TestInput string }
type testOutputType struct { TestOutput string }
input := testInputType{ "input" }
output := testOutputType{}
err := newRunner(
func(define command.Define) {
define.Command("test").
Input(testInputType{}).
Output(testOutputType{}).
Handler(func(rt command.Runtime, log *log.Logger, in, out interface{}) error {
assert.NotPanics(t, func() {
input := in.(*testInputType)
output := out.(*testOutputType)
assert.Equal(t, "input", input.TestInput)
output.TestOutput = "output"
})
return nil
})
}).
Run("test", &input, &output)
assert.Empty(t, err)
assert.Equal(t, "output", output.TestOutput)
}
func TestCommands_Filters(t *testing.T) {
type testType struct {
Executed1 bool
Executed2 bool
Executed3 bool
}
input := testType{}
output := testType{}
err := newRunner(
func(define command.Define) {
define.Command("test-1").
Input(testType{}).
Output(testType{}).
Dependencies("test-2").
Handler(func(rt command.Runtime, log *log.Logger, in, out interface{}) error {
out.(*testType).Executed1 = true
return nil
})
},
func(define command.Define) {
define.Command("test-2").
Input(testType{}).
Output(testType{}).
Dependencies("test-3").
Handler(func(rt command.Runtime, log *log.Logger, in, out interface{}) error {
out.(*testType).Executed2 = true
return nil
})
},
func(define command.Define) {
define.Command("test-3").
Input(testType{}).
Output(testType{}).
Handler(func(rt command.Runtime, log *log.Logger, in, out interface{}) error {
out.(*testType).Executed3 = true
return nil
})
}).
With(option.Excludes("test-2")).
Run("test-1", &input, &output)
assert.Empty(t, err)
assert.True(t, output.Executed1)
assert.False(t, output.Executed2)
assert.False(t, output.Executed3)
}