| 306 | } |
| 307 | |
| 308 | func TestBeforeEventWithoutTransition(t *testing.T) { |
| 309 | beforeEvent := true |
| 310 | |
| 311 | fsm := NewFSM( |
| 312 | "start", |
| 313 | Events{ |
| 314 | {Name: "dontrun", Src: []string{"start"}, Dst: "start"}, |
| 315 | }, |
| 316 | Callbacks{ |
| 317 | "before_event": func(_ context.Context, e *Event) { |
| 318 | beforeEvent = true |
| 319 | }, |
| 320 | }, |
| 321 | ) |
| 322 | |
| 323 | err := fsm.Event(context.Background(), "dontrun") |
| 324 | if e, ok := err.(NoTransitionError); !ok && e.Err != nil { |
| 325 | t.Error("expected 'NoTransitionError' without custom error") |
| 326 | } |
| 327 | |
| 328 | if fsm.Current() != "start" { |
| 329 | t.Error("expected state to be 'start'") |
| 330 | } |
| 331 | if !beforeEvent { |
| 332 | t.Error("expected callback to be called") |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | func TestCancelBeforeGenericEvent(t *testing.T) { |
| 337 | fsm := NewFSM( |