support wildcard source transition
This commit is contained in:
parent
d126067c56
commit
51b3a21aca
@ -25,7 +25,7 @@ func NewTransition(trigger string, source State, dest State) Transitioner {
|
|||||||
|
|
||||||
func (r *Transition) Run(m Modeler) error {
|
func (r *Transition) Run(m Modeler) error {
|
||||||
currentState := m.InspectState()
|
currentState := m.InspectState()
|
||||||
if currentState == r.source {
|
if currentState == r.source || r.source == "*" {
|
||||||
res := m.ChangeState(r.dest)
|
res := m.ChangeState(r.dest)
|
||||||
if res == currentState {
|
if res == currentState {
|
||||||
r.Notify(EXITSTATEEVENT, currentState, r.dest)
|
r.Notify(EXITSTATEEVENT, currentState, r.dest)
|
||||||
|
@ -38,6 +38,14 @@ func TestTransitionExecution(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTransitionWildcard(t *testing.T) {
|
||||||
|
tr := NewTransition("open", "*", "opened")
|
||||||
|
assert.NotNil(t, tr)
|
||||||
|
m := setupModel("closed")
|
||||||
|
assert.Nil(t, tr.Run(m))
|
||||||
|
assert.Equal(t, "opened", string(m.InspectState()))
|
||||||
|
}
|
||||||
|
|
||||||
func TestTransitionSubscribe(t *testing.T) {
|
func TestTransitionSubscribe(t *testing.T) {
|
||||||
c := setupSubscriber()
|
c := setupSubscriber()
|
||||||
s := setupTransition()
|
s := setupTransition()
|
||||||
|
Loading…
Reference in New Issue
Block a user