@@ -6,6 +6,7 @@ package actionwait
6
6
import (
7
7
"context"
8
8
"errors"
9
+ "strings"
9
10
"sync/atomic"
10
11
"testing"
11
12
"time"
@@ -25,8 +26,10 @@ func TestWaitForStatus_ValidationErrors(t *testing.T) {
25
26
t .Parallel ()
26
27
// Subtests parallelized; each uses its own context with timeout.
27
28
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 },
30
33
}
31
34
32
35
for name , opts := range cases {
@@ -289,3 +292,33 @@ func TestWaitForStatus_ProgressSinkDisabled(t *testing.T) {
289
292
t .Fatalf ("expected zero progress sink calls, got %d" , progressCalls )
290
293
}
291
294
}
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