@@ -600,3 +600,55 @@ users:
600600 }
601601 }
602602}
603+
604+ func TestWaitUntilTimeout (t * testing.T ) {
605+ tests := []struct {
606+ desc string
607+ timeout time.Duration
608+ execFunc ExecFunc
609+ timeoutFunc TimeoutFunc
610+ expectedErr error
611+ }{
612+ {
613+ desc : "execFunc returns error" ,
614+ timeout : 1 * time .Second ,
615+ execFunc : func () error {
616+ return fmt .Errorf ("execFunc error" )
617+ },
618+ timeoutFunc : func () error {
619+ return fmt .Errorf ("timeout error" )
620+ },
621+ expectedErr : fmt .Errorf ("execFunc error" ),
622+ },
623+ {
624+ desc : "execFunc timeout" ,
625+ timeout : 1 * time .Second ,
626+ execFunc : func () error {
627+ time .Sleep (2 * time .Second )
628+ return nil
629+ },
630+ timeoutFunc : func () error {
631+ return fmt .Errorf ("timeout error" )
632+ },
633+ expectedErr : fmt .Errorf ("timeout error" ),
634+ },
635+ {
636+ desc : "execFunc completed successfully" ,
637+ timeout : 1 * time .Second ,
638+ execFunc : func () error {
639+ return nil
640+ },
641+ timeoutFunc : func () error {
642+ return fmt .Errorf ("timeout error" )
643+ },
644+ expectedErr : nil ,
645+ },
646+ }
647+
648+ for _ , test := range tests {
649+ err := WaitUntilTimeout (test .timeout , test .execFunc , test .timeoutFunc )
650+ if err != nil && (err .Error () != test .expectedErr .Error ()) {
651+ t .Errorf ("unexpected error: %v, expected error: %v" , err , test .expectedErr )
652+ }
653+ }
654+ }
0 commit comments