-
Notifications
You must be signed in to change notification settings - Fork 1
/
actor_test.go
73 lines (67 loc) · 1.36 KB
/
actor_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
package commander
import (
"fmt"
"github.com/WindomZ/testify/assert"
"testing"
)
func TestActor_IncludeKeys(t *testing.T) {
var a actor
var pass bool
a.addIncludeKeys([]string{"a", "b", "c"})
for _, key := range a.getIncludeKeys() {
pass = false
for _, k := range []string{"a", "b", "c"} {
if key == k {
pass = true
}
}
if !pass {
assert.FailNow(t, fmt.Sprintf("Error: %v", a.getIncludeKeys()))
}
}
}
func TestActor_ExcludeKeys(t *testing.T) {
var a actor
var pass bool
a.addExcludeKeys([]string{"a", "b", "c"})
for _, key := range a.getExcludeKeys() {
pass = false
for _, k := range []string{"a", "b", "c"} {
if key == k {
pass = true
}
}
if !pass {
assert.FailNow(t, fmt.Sprintf("Error: %v", a.getExcludeKeys()))
}
}
}
func TestActor_Action(t *testing.T) {
var result bool
var a actor
a.Action(func(c Context) {
result = true
assert.Equal(t, c.MustBool("a"), true)
assert.Equal(t, c.MustBool("b"), true)
assert.Equal(t, c.MustBool("c"), true)
assert.Equal(t, c.MustBool("d"), false)
}, []string{"a", "b", "c"})
a.run(newContext(nil, newDocoptMap(
map[string]interface{}{
"a": true,
"b": true,
"c": false,
},
),
))
assert.Equal(t, result, false)
a.run(newContext(nil, newDocoptMap(
map[string]interface{}{
"a": true,
"b": true,
"c": true,
},
),
))
assert.Equal(t, result, true)
}