proxy/config tests: avoid multiple calls to done

If the callback is called multiple times the wait group will be
over-decremented.
This commit is contained in:
Justin SB 2021-02-15 15:23:21 -05:00
parent 1ed3607a86
commit 6ac76e184e

View File

@ -152,8 +152,9 @@ func newSvcHandler(t *testing.T, svcs []*v1.Service, done func()) ServiceHandler
shm := &ServiceHandlerMock{
state: make(map[types.NamespacedName]*v1.Service),
}
var callDoneOnce sync.Once
shm.process = func(services []*v1.Service) {
defer done()
defer callDoneOnce.Do(done)
if !reflect.DeepEqual(services, svcs) {
t.Errorf("Unexpected services: %#v, expected: %#v", services, svcs)
}
@ -165,8 +166,9 @@ func newEpsHandler(t *testing.T, eps []*v1.Endpoints, done func()) EndpointsHand
ehm := &EndpointsHandlerMock{
state: make(map[types.NamespacedName]*v1.Endpoints),
}
var callDoneOnce sync.Once
ehm.process = func(endpoints []*v1.Endpoints) {
defer done()
defer callDoneOnce.Do(done)
if !reflect.DeepEqual(eps, endpoints) {
t.Errorf("Unexpected endpoints: %#v, expected: %#v", endpoints, eps)
}