-
Notifications
You must be signed in to change notification settings - Fork 2
/
testing_test.go
48 lines (43 loc) · 1.05 KB
/
testing_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
package selina_test
import (
"reflect"
"testing"
"github.com/licaonfee/selina"
)
func TestSliceAsChannel(t *testing.T) {
data := []string{"foo", "bar", "baz"}
c := selina.SliceAsChannel(data, true)
got := []string{}
for v := range c {
got = append(got, v)
}
if !reflect.DeepEqual(got, data) {
t.Fatalf("SliceAsChannel() got = %v , want = %v", got, data)
}
}
func TestSliceAsChannelRaw(t *testing.T) {
data := [][]byte{[]byte("foo"), []byte("bar"), []byte("baz")}
c := selina.SliceAsChannelRaw(data, true)
got := [][]byte{}
for v := range c {
got = append(got, v)
}
if !reflect.DeepEqual(got, data) {
t.Fatalf("SliceAsChannelRaw() got = %v , want = %v", got, data)
}
}
func TestChannelAsSlice(t *testing.T) {
want := []string{"foo", "bar", "baz"}
input := make(chan []byte, 3)
for _, v := range want {
input <- []byte(v)
}
close(input)
got := []string{}
for _, r := range selina.ChannelAsSlice(input) {
got = append(got, string(r))
}
if !reflect.DeepEqual(got, want) {
t.Fatalf("ChannelAsSlice() got = %v, want = %v", got, want)
}
}