Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jun 4, 2024
1 parent 51daae4 commit 6de3de7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions donegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,25 +727,31 @@ func TestWithTimeoutCause(t *testing.T) {
func TestCancelWithCause(t *testing.T) {
t.Parallel()
var errTest = errors.New("test error")
t.Run("Timeout", func(t *testing.T) {
ctx, _ := WithTimeout(context.Background(), 1*time.Millisecond)
var errTest2 = errors.New("test error2")

if err := Wait(ctx); err != nil {
t.Run("Cancel with cause", func(t *testing.T) {
ctx, _ := WithCancel(context.Background())

if err := CancelWithCause(ctx, errTest); err != nil {
t.Error(err)
}

if !errors.Is(context.Cause(ctx), context.DeadlineExceeded) {
t.Errorf("got %v, want %v", context.Cause(ctx), context.DeadlineExceeded)
if !errors.Is(context.Cause(ctx), errTest) {
t.Errorf("got %v, want %v", context.Cause(ctx), errTest)
}
})

t.Run("Cancel with cause", func(t *testing.T) {
t.Run("Cancel with cause2", func(t *testing.T) {
ctx, _ := WithCancel(context.Background())

if err := CancelWithCause(ctx, errTest); err != nil {
t.Error(err)
}

if err := CancelWithCause(ctx, errTest2); err != nil {
t.Error(err)
}

if !errors.Is(context.Cause(ctx), errTest) {
t.Errorf("got %v, want %v", context.Cause(ctx), errTest)
}
Expand Down

0 comments on commit 6de3de7

Please sign in to comment.