blob: c2e49ab5089f8e7190a6c6060cc2728dcf02b557 (
plain)
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
|
package matchers_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/matchers"
)
var _ = Describe("BeClosedMatcher", func() {
Context("when passed a channel", func() {
It("should do the right thing", func() {
openChannel := make(chan bool)
Expect(openChannel).ShouldNot(BeClosed())
var openReaderChannel <-chan bool
openReaderChannel = openChannel
Expect(openReaderChannel).ShouldNot(BeClosed())
closedChannel := make(chan bool)
close(closedChannel)
Expect(closedChannel).Should(BeClosed())
var closedReaderChannel <-chan bool
closedReaderChannel = closedChannel
Expect(closedReaderChannel).Should(BeClosed())
})
})
Context("when passed a send-only channel", func() {
It("should error", func() {
openChannel := make(chan bool)
var openWriterChannel chan<- bool
openWriterChannel = openChannel
success, err := (&BeClosedMatcher{}).Match(openWriterChannel)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
closedChannel := make(chan bool)
close(closedChannel)
var closedWriterChannel chan<- bool
closedWriterChannel = closedChannel
success, err = (&BeClosedMatcher{}).Match(closedWriterChannel)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
})
})
Context("when passed something else", func() {
It("should error", func() {
var nilChannel chan bool
success, err := (&BeClosedMatcher{}).Match(nilChannel)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
success, err = (&BeClosedMatcher{}).Match(nil)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
success, err = (&BeClosedMatcher{}).Match(7)
Expect(success).Should(BeFalse())
Expect(err).Should(HaveOccurred())
})
})
})
|