MCPcopy
hub / github.com/looplab/fsm / TestBeforeEventWithoutTransition

Function TestBeforeEventWithoutTransition

fsm_test.go:308–334  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

306}
307
308func 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
336func TestCancelBeforeGenericEvent(t *testing.T) {
337 fsm := NewFSM(

Callers

nothing calls this directly

Calls 4

EventMethod · 0.95
CurrentMethod · 0.95
NewFSMFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…