-
Notifications
You must be signed in to change notification settings - Fork 1
/
close-channel_test.go
55 lines (48 loc) · 1.22 KB
/
close-channel_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
/*
© 2022–present Harald Rudell <[email protected]> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
import "testing"
func TestCloseChannel(t *testing.T) {
var value = 3
var doDrain = true
var ch chan int
var err, errp error
var n int
var isNilChannel, isCloseOfClosedChannel bool
// close of nil channel should return isNilChannel true
ch = nil
isNilChannel, isCloseOfClosedChannel, n, err = CloseChannel(ch, &errp)
if !isNilChannel {
t.Error("isNilChannel false")
}
_ = err
_ = n
_ = isCloseOfClosedChannel
// n should return number of items when draining
ch = make(chan int, 1)
ch <- value
isNilChannel, isCloseOfClosedChannel, n, err = CloseChannel(ch, &errp, doDrain)
if n != 1 {
t.Errorf("n bad %d exp %d", n, 1)
}
_ = isNilChannel
_ = err
_ = isCloseOfClosedChannel
// close of closed channel should set isCloseOfClosedChannel, err, errp
ch = make(chan int)
close(ch)
isNilChannel, isCloseOfClosedChannel, n, err = CloseChannel(ch, &errp)
if !isCloseOfClosedChannel {
t.Error("isCloseOfClosedChannel false")
}
if err == nil {
t.Error("isCloseOfClosedChannel err nil")
}
if errp == nil {
t.Error("isCloseOfClosedChannel errp nil")
}
_ = isNilChannel
_ = n
}