(t *testing.T)
| 119 | } |
| 120 | |
| 121 | func TestRunWithTimeout(t *testing.T) { |
| 122 | t.Run("returns function result before timeout", func(t *testing.T) { |
| 123 | errExpected := errors.New("boom") |
| 124 | err := runWithTimeout("test-hook", 50*time.Millisecond, func() error { |
| 125 | return errExpected |
| 126 | }) |
| 127 | if !errors.Is(err, errExpected) { |
| 128 | t.Fatalf("expected %v, got %v", errExpected, err) |
| 129 | } |
| 130 | }) |
| 131 | |
| 132 | t.Run("returns timeout error when function blocks too long", func(t *testing.T) { |
| 133 | err := runWithTimeout("slow-hook", 20*time.Millisecond, func() error { |
| 134 | time.Sleep(80 * time.Millisecond) |
| 135 | return nil |
| 136 | }) |
| 137 | var timeoutErr *HookTimeoutError |
| 138 | if !errors.As(err, &timeoutErr) { |
| 139 | t.Fatalf("expected HookTimeoutError, got %v", err) |
| 140 | } |
| 141 | if timeoutErr.Hook != "slow-hook" { |
| 142 | t.Fatalf("expected hook name slow-hook, got %q", timeoutErr.Hook) |
| 143 | } |
| 144 | }) |
| 145 | } |
| 146 | |
| 147 | func TestCappedStringWriter(t *testing.T) { |
| 148 | t.Run("captures full output under limit", func(t *testing.T) { |
nothing calls this directly
no test coverage detected