-
Notifications
You must be signed in to change notification settings - Fork 338
/
item_test.go
71 lines (61 loc) · 1.95 KB
/
item_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package rxgo
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/goleak"
)
func Test_SendItems_Variadic(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 3)
go SendItems(context.Background(), ch, CloseChannel, 1, 2, 3)
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 2, 3), HasNoError())
}
func Test_SendItems_VariadicWithError(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 3)
go SendItems(context.Background(), ch, CloseChannel, 1, errFoo, 3)
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 3), HasError(errFoo))
}
func Test_SendItems_Slice(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 3)
go SendItems(context.Background(), ch, CloseChannel, []int{1, 2, 3})
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 2, 3), HasNoError())
}
func Test_SendItems_SliceWithError(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 3)
go SendItems(context.Background(), ch, CloseChannel, []interface{}{1, errFoo, 3})
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 3), HasError(errFoo))
}
func Test_Item_SendBlocking(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 1)
defer close(ch)
Of(5).SendBlocking(ch)
assert.Equal(t, 5, (<-ch).V)
}
func Test_Item_SendContext_True(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 1)
defer close(ch)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
assert.True(t, Of(5).SendContext(ctx, ch))
}
func Test_Item_SendContext_False(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 1)
defer close(ch)
ctx, cancel := context.WithCancel(context.Background())
cancel()
assert.False(t, Of(5).SendContext(ctx, ch))
}
func Test_Item_SendNonBlocking(t *testing.T) {
defer goleak.VerifyNone(t)
ch := make(chan Item, 1)
defer close(ch)
assert.True(t, Of(5).SendNonBlocking(ch))
assert.False(t, Of(5).SendNonBlocking(ch))
}