support wildcard source transition
All checks were successful
Lint / golangci-lint (push) Successful in 9m42s
Machine Tests / test (push) Successful in 33s

This commit is contained in:
Matthew Rich 2024-05-16 17:28:49 -07:00
parent d126067c56
commit 51b3a21aca
2 changed files with 9 additions and 1 deletions

View File

@ -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)

View File

@ -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()