diff --git a/transition.go b/transition.go index c5687ab..2c50ce6 100644 --- a/transition.go +++ b/transition.go @@ -25,7 +25,7 @@ func NewTransition(trigger string, source State, dest State) Transitioner { func (r *Transition) Run(m Modeler) error { currentState := m.InspectState() - if currentState == r.source { + if currentState == r.source || r.source == "*" { res := m.ChangeState(r.dest) if res == currentState { r.Notify(EXITSTATEEVENT, currentState, r.dest) diff --git a/transition_test.go b/transition_test.go index ce3b0d5..50da08c 100644 --- a/transition_test.go +++ b/transition_test.go @@ -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) { c := setupSubscriber() s := setupTransition()