| 102 | } |
| 103 | |
| 104 | func TestHookUnbindAll(t *testing.T) { |
| 105 | h := Hook[*Event]{} |
| 106 | |
| 107 | h.UnbindAll() // should do nothing and not panic |
| 108 | |
| 109 | h.BindFunc(func(e *Event) error { return nil }) |
| 110 | h.BindFunc(func(e *Event) error { return nil }) |
| 111 | |
| 112 | if total := len(h.handlers); total != 2 { |
| 113 | t.Fatalf("Expected %d handlers before UnbindAll, found %d", 2, total) |
| 114 | } |
| 115 | |
| 116 | h.UnbindAll() |
| 117 | |
| 118 | if total := len(h.handlers); total != 0 { |
| 119 | t.Fatalf("Expected no handlers after UnbindAll, found %d", total) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | func TestHookTriggerErrorPropagation(t *testing.T) { |
| 124 | err := errors.New("test") |