...
1 package matchers_test
2
3 import (
4 . "github.com/onsi/ginkgo/v2"
5 . "github.com/onsi/gomega"
6 . "github.com/onsi/gomega/matchers"
7 )
8
9 var _ = Describe("BeClosedMatcher", func() {
10 When("passed a channel", func() {
11 It("should do the right thing", func() {
12 openChannel := make(chan bool)
13 Expect(openChannel).ShouldNot(BeClosed())
14
15 var openReaderChannel <-chan bool
16 openReaderChannel = openChannel
17 Expect(openReaderChannel).ShouldNot(BeClosed())
18
19 closedChannel := make(chan bool)
20 close(closedChannel)
21
22 Expect(closedChannel).Should(BeClosed())
23
24 var closedReaderChannel <-chan bool
25 closedReaderChannel = closedChannel
26 Expect(closedReaderChannel).Should(BeClosed())
27 })
28 })
29
30 When("passed a send-only channel", func() {
31 It("should error", func() {
32 openChannel := make(chan bool)
33 var openWriterChannel chan<- bool
34 openWriterChannel = openChannel
35
36 success, err := (&BeClosedMatcher{}).Match(openWriterChannel)
37 Expect(success).Should(BeFalse())
38 Expect(err).Should(HaveOccurred())
39
40 closedChannel := make(chan bool)
41 close(closedChannel)
42
43 var closedWriterChannel chan<- bool
44 closedWriterChannel = closedChannel
45
46 success, err = (&BeClosedMatcher{}).Match(closedWriterChannel)
47 Expect(success).Should(BeFalse())
48 Expect(err).Should(HaveOccurred())
49
50 })
51 })
52
53 When("passed something else", func() {
54 It("should error", func() {
55 var nilChannel chan bool
56
57 success, err := (&BeClosedMatcher{}).Match(nilChannel)
58 Expect(success).Should(BeFalse())
59 Expect(err).Should(HaveOccurred())
60
61 success, err = (&BeClosedMatcher{}).Match(nil)
62 Expect(success).Should(BeFalse())
63 Expect(err).Should(HaveOccurred())
64
65 success, err = (&BeClosedMatcher{}).Match(7)
66 Expect(success).Should(BeFalse())
67 Expect(err).Should(HaveOccurred())
68 })
69 })
70 })
71
View as plain text