-
Notifications
You must be signed in to change notification settings - Fork 8
/
transitionRule_test.go
71 lines (64 loc) · 1.8 KB
/
transitionRule_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
package stateful
import (
"github.com/stretchr/testify/assert"
"testing"
)
func transitionruletestA(_ TransitionArguments) (State, error) {
return nil, nil
}
func transitionruletestB(_ TransitionArguments) (State, error) {
return nil, nil
}
func transitionruletestC(_ TransitionArguments) (State, error) {
return nil, nil
}
func TestTransitionRule_IsAllowedToRun(t *testing.T) {
transitionRule := TransitionRule{
SourceStates: States{
DefaultState("transitionTest_a"),
DefaultState("transitionTest_b"),
},
}
assert.True(t, transitionRule.IsAllowedToRun(DefaultState("transitionTest_a")))
assert.True(t, transitionRule.IsAllowedToRun(DefaultState("transitionTest_b")))
assert.False(t, transitionRule.IsAllowedToRun(DefaultState("transitionTest_c")))
}
func TestTransitionRule_IsAllowedToTransfer(t *testing.T) {
transitionRule := TransitionRule{
DestinationStates: States{
DefaultState("transitionTest_a"),
DefaultState("transitionTest_b"),
},
}
assert.True(t, transitionRule.IsAllowedToTransfer(DefaultState("transitionTest_a")))
assert.True(t, transitionRule.IsAllowedToTransfer(DefaultState("transitionTest_b")))
assert.False(t, transitionRule.IsAllowedToTransfer(DefaultState("transitionTest_c")))
}
func TestTransitionRules_Find(t *testing.T) {
transitionRules := TransitionRules{
TransitionRule{
Transition: transitionruletestA,
},
TransitionRule{
Transition: transitionruletestB,
},
}
assert.Equal(
t,
TransitionRule{
Transition: transitionruletestA,
}.Transition.GetID(),
transitionRules.Find(transitionruletestA).Transition.GetID(),
)
assert.Equal(
t,
TransitionRule{
Transition: transitionruletestB,
}.Transition.GetID(),
transitionRules.Find(transitionruletestB).Transition.GetID(),
)
assert.Nil(
t,
transitionRules.Find(transitionruletestC),
)
}