@@ -428,3 +428,55 @@ func TestGetRootPath(t *testing.T) {
428428 }
429429 }
430430}
431+
432+ func TestWaitUntilTimeout (t * testing.T ) {
433+ tests := []struct {
434+ desc string
435+ timeout time.Duration
436+ execFunc ExecFunc
437+ timeoutFunc TimeoutFunc
438+ expectedErr error
439+ }{
440+ {
441+ desc : "execFunc returns error" ,
442+ timeout : 1 * time .Second ,
443+ execFunc : func () error {
444+ return fmt .Errorf ("execFunc error" )
445+ },
446+ timeoutFunc : func () error {
447+ return fmt .Errorf ("timeout error" )
448+ },
449+ expectedErr : fmt .Errorf ("execFunc error" ),
450+ },
451+ {
452+ desc : "execFunc timeout" ,
453+ timeout : 1 * time .Second ,
454+ execFunc : func () error {
455+ time .Sleep (2 * time .Second )
456+ return nil
457+ },
458+ timeoutFunc : func () error {
459+ return fmt .Errorf ("timeout error" )
460+ },
461+ expectedErr : fmt .Errorf ("timeout error" ),
462+ },
463+ {
464+ desc : "execFunc completed successfully" ,
465+ timeout : 1 * time .Second ,
466+ execFunc : func () error {
467+ return nil
468+ },
469+ timeoutFunc : func () error {
470+ return fmt .Errorf ("timeout error" )
471+ },
472+ expectedErr : nil ,
473+ },
474+ }
475+
476+ for _ , test := range tests {
477+ err := WaitUntilTimeout (test .timeout , test .execFunc , test .timeoutFunc )
478+ if err != nil && (err .Error () != test .expectedErr .Error ()) {
479+ t .Errorf ("unexpected error: %v, expected error: %v" , err , test .expectedErr )
480+ }
481+ }
482+ }
0 commit comments