-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchannel-send_test.go
105 lines (90 loc) · 2.06 KB
/
channel-send_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
© 2023–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
ISC License
*/
package parl
import (
"testing"
"github.com/haraldrudell/parl/perrors"
)
func TestChannelSend(t *testing.T) {
var errCh = make(chan error, 1)
var err0 error
var didSend, isNilChannel, isClosedChannel bool
var err error
// successful send
didSend, isNilChannel, isClosedChannel, err = ChannelSend(errCh, err0)
if !didSend {
t.Error("didSend false")
}
if isNilChannel {
t.Error("isNilChannel true")
}
if isClosedChannel {
t.Error("isClosedChannel true")
}
if err != nil {
t.Errorf("ChannelSend err: %s", perrors.Short(err))
}
}
func TestChannelSendNil(t *testing.T) {
var errCh chan error
var err0 error
var didSend, isNilChannel, isClosedChannel bool
var err error
// nil send
didSend, isNilChannel, isClosedChannel, err = ChannelSend(errCh, err0)
if didSend {
t.Error("didSend true")
}
if !isNilChannel {
t.Error("isNilChannel false")
}
if isClosedChannel {
t.Error("isClosedChannel true")
}
if err == nil {
t.Error("ChannelSend missing err")
}
}
func TestChannelSendClosed(t *testing.T) {
var errCh = make(chan error, 1)
var err0 error
var didSend, isNilChannel, isClosedChannel bool
var err error
// closed send
close(errCh)
didSend, isNilChannel, isClosedChannel, err = ChannelSend(errCh, err0)
if didSend {
t.Error("didSend true")
}
if isNilChannel {
t.Error("isNilChannel true")
}
if !isClosedChannel {
t.Error("isClosedChannel false")
}
if err == nil {
t.Error("ChannelSend missing err")
}
}
func TestChannelSendNonBlocking(t *testing.T) {
var errCh = make(chan error)
var err0 error
var didSend, isNilChannel, isClosedChannel bool
var err error
// non-blocking send
didSend, isNilChannel, isClosedChannel, err = ChannelSend(errCh, err0, SendNonBlocking)
if didSend {
t.Error("didSend true")
}
if isNilChannel {
t.Error("isNilChannel true")
}
if isClosedChannel {
t.Error("isClosedChannel true")
}
if err != nil {
t.Errorf("ChannelSend err: %s", perrors.Short(err))
}
}