forked from linkerd/linkerd2
/
test_helper.go
44 lines (35 loc) · 1.06 KB
/
test_helper.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 destination
import (
"context"
)
// implements the updateListener interface
type collectUpdateListener struct {
added []*updateAddress
removed []*updateAddress
noEndpointsCalled bool
noEndpointsExists bool
context context.Context
stopCh chan struct{}
}
func (c *collectUpdateListener) Update(add, remove []*updateAddress) {
c.added = append(c.added, add...)
c.removed = append(c.removed, remove...)
}
func (c *collectUpdateListener) ClientClose() <-chan struct{} {
return c.context.Done()
}
func (c *collectUpdateListener) ServerClose() <-chan struct{} {
return c.stopCh
}
func (c *collectUpdateListener) Stop() {
close(c.stopCh)
}
func (c *collectUpdateListener) NoEndpoints(exists bool) {
c.noEndpointsCalled = true
c.noEndpointsExists = exists
}
func (c *collectUpdateListener) SetServiceId(id *serviceId) {}
func newCollectUpdateListener() (*collectUpdateListener, context.CancelFunc) {
ctx, cancelFn := context.WithCancel(context.Background())
return &collectUpdateListener{context: ctx}, cancelFn
}