-
Notifications
You must be signed in to change notification settings - Fork 338
/
item_test.go
54 lines (45 loc) · 1.42 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
package rxgo
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_SendItems_Variadic(t *testing.T) {
ch := make(chan Item, 3)
go SendItems(ch, CloseChannel, 1, 2, 3)
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 2, 3), HasNoError())
}
func Test_SendItems_VariadicWithError(t *testing.T) {
ch := make(chan Item, 3)
go SendItems(ch, CloseChannel, 1, errFoo, 3)
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 3), HasError(errFoo))
}
func Test_SendItems_Slice(t *testing.T) {
ch := make(chan Item, 3)
go SendItems(ch, CloseChannel, []int{1, 2, 3})
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 2, 3), HasNoError())
}
func Test_SendItems_SliceWithError(t *testing.T) {
ch := make(chan Item, 3)
go SendItems(ch, CloseChannel, []interface{}{1, errFoo, 3})
Assert(context.Background(), t, FromChannel(ch), HasItems(1, 3), HasError(errFoo))
}
func Test_Item_SendBlocking(t *testing.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) {
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_SendNonBlocking(t *testing.T) {
ch := make(chan Item, 1)
defer close(ch)
assert.True(t, Of(5).SendNonBlocking(ch))
assert.False(t, Of(5).SendNonBlocking(ch))
}