Skip to content

Commit cd48e50

Browse files
committed
Fix tests
1 parent 939bdf3 commit cd48e50

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

internal/actionwait/wait_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package actionwait
66
import (
77
"context"
88
"errors"
9+
"strings"
910
"sync/atomic"
1011
"testing"
1112
"time"
@@ -25,8 +26,10 @@ func TestWaitForStatus_ValidationErrors(t *testing.T) {
2526
t.Parallel()
2627
// Subtests parallelized; each uses its own context with timeout.
2728
cases := map[string]Options[struct{}]{
28-
"missing timeout": {SuccessStates: []Status{"ok"}},
29-
"missing success": {Timeout: time.Second},
29+
"missing timeout": {SuccessStates: []Status{"ok"}},
30+
"missing success": {Timeout: time.Second},
31+
"negative consecutive": {Timeout: time.Second, SuccessStates: []Status{"ok"}, ConsecutiveSuccess: -1},
32+
"negative progress interval": {Timeout: time.Second, SuccessStates: []Status{"ok"}, ProgressInterval: -time.Second},
3033
}
3134

3235
for name, opts := range cases {
@@ -289,3 +292,33 @@ func TestWaitForStatus_ProgressSinkDisabled(t *testing.T) {
289292
t.Fatalf("expected zero progress sink calls, got %d", progressCalls)
290293
}
291294
}
295+
296+
func TestWaitForStatus_UnexpectedStateErrorMessage(t *testing.T) {
297+
t.Parallel()
298+
ctx := makeCtx(t)
299+
_, err := WaitForStatus(ctx, func(context.Context) (FetchResult[int], error) {
300+
return FetchResult[int]{Status: "UNKNOWN"}, nil
301+
}, Options[int]{
302+
Timeout: 200 * time.Millisecond,
303+
SuccessStates: []Status{"OK"},
304+
TransitionalStates: []Status{"PENDING", "IN_PROGRESS"},
305+
Interval: FixedInterval(fastFixedInterval),
306+
})
307+
if err == nil {
308+
t.Fatal("expected unexpected state error")
309+
}
310+
unexpectedErr, ok := err.(*UnexpectedStateError)
311+
if !ok { //nolint:errorlint // direct type assertion adequate in tests
312+
t.Fatalf("expected UnexpectedStateError, got %T", err)
313+
}
314+
errMsg := unexpectedErr.Error()
315+
if !strings.Contains(errMsg, "UNKNOWN") {
316+
t.Errorf("error message should contain status 'UNKNOWN', got: %s", errMsg)
317+
}
318+
if !strings.Contains(errMsg, "allowed:") {
319+
t.Errorf("error message should list allowed states, got: %s", errMsg)
320+
}
321+
if !strings.Contains(errMsg, "PENDING") {
322+
t.Errorf("error message should contain allowed state 'PENDING', got: %s", errMsg)
323+
}
324+
}

0 commit comments

Comments
 (0)