✅ Add tests for Unwrap method
This commit is contained in:
parent
4d92c7484d
commit
09b97e0b66
1 changed files with 28 additions and 0 deletions
|
|
@ -64,3 +64,31 @@ func TestWaitForErrorNoErr(t *testing.T) {
|
|||
err := we.WaitForError()
|
||||
be.Err(t, err, nil)
|
||||
}
|
||||
|
||||
func TestUnwrap(tt *testing.T) {
|
||||
tt.Run("two errors", func(t *testing.T) {
|
||||
we := new(waiterr.WaitErr)
|
||||
er1 := errors.New("error one")
|
||||
er2 := errors.New("error two")
|
||||
|
||||
we.Go(func() error { return er1 })
|
||||
we.Go(func() error { return nil })
|
||||
we.Go(func() error { return er2 })
|
||||
we.Go(func() error { return nil })
|
||||
|
||||
_ = we.Wait() // Ensure all goroutines complete
|
||||
|
||||
unwrapped := we.Unwrap()
|
||||
be.Equal(t, len(unwrapped), 2)
|
||||
be.True(t, (unwrapped[0] == er1 && unwrapped[1] == er2) || (unwrapped[0] == er2 && unwrapped[1] == er1))
|
||||
|
||||
})
|
||||
|
||||
tt.Run("no errors", func(t *testing.T) {
|
||||
weNoErr := new(waiterr.WaitErr)
|
||||
weNoErr.Go(func() error { return nil })
|
||||
weNoErr.Go(func() error { return nil })
|
||||
_ = weNoErr.Wait()
|
||||
be.Equal(t, weNoErr.Unwrap(), nil)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue