forked from kgateway-dev/kgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentity_test.go
44 lines (34 loc) · 893 Bytes
/
identity_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
package leaderelector_test
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/kgateway-dev/kgateway/pkg/bootstrap/leaderelector"
)
var _ = Describe("Identity", func() {
var (
electedChan chan struct{}
identity leaderelector.Identity
)
BeforeEach(func() {
electedChan = make(chan struct{})
identity = leaderelector.NewIdentity(electedChan)
})
AfterEach(func() {
select {
case <-electedChan:
// channel is closed, do nothing
default:
// channel is still open, close it
close(electedChan)
}
})
It("IsLeader always returns false, then true after channel is closed", func() {
Consistently(func(g Gomega) {
g.Expect(identity.IsLeader()).To(BeFalse())
}).ShouldNot(HaveOccurred())
close(electedChan)
Consistently(func(g Gomega) {
g.Expect(identity.IsLeader()).To(BeTrue())
}).ShouldNot(HaveOccurred())
})
})