Skip to content

Commit

Permalink
add WaitFor test
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhicks committed Oct 10, 2024
1 parent 816b9df commit c060b5c
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,60 @@ func TestPIDRemoved(t *testing.T) {
})
}
}

func TestWaitFor(t *testing.T) {
tests := []struct {
name string
ctx func(t *testing.T) context.Context
ch func(t *testing.T) chan int
exp int
expErr error
}{
{
name: "canceled with io error",
ctx: func(t *testing.T) context.Context {
ctx, cancel := context.WithCancelCause(context.Background())
cancel(io.ErrUnexpectedEOF)
return ctx
},
ch: func(t *testing.T) chan int {
return nil
},
exp: 0,
expErr: io.ErrUnexpectedEOF,
},
{
name: "canceled",
ctx: func(t *testing.T) context.Context {
ctx, cancel := context.WithCancel(context.Background())
cancel()
return ctx
},
ch: func(t *testing.T) chan int {
return nil
},
exp: 0,
expErr: context.Canceled,
},
{
name: "success",
ctx: func(t *testing.T) context.Context {
return context.Background()
},
ch: func(t *testing.T) chan int {
ch := make(chan int, 1)
ch <- 1
close(ch)
return ch
},
exp: 1,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
i, err := lu.WaitFor(tc.ctx(t), tc.ch(t))
jtest.Require(t, tc.expErr, err)
assert.Equal(t, tc.exp, i)
})
}
}

0 comments on commit c060b5c

Please sign in to comment.