Fix tests by adding mocks for additional Watch calls

Signed-off-by: Alexandre Beslic <abronan@docker.com>
This commit is contained in:
Alexandre Beslic 2015-10-08 11:20:04 -07:00
parent fa5cd27d82
commit ab249c4756
1 changed files with 5 additions and 2 deletions

View File

@ -69,8 +69,11 @@ func TestWatch(t *testing.T) {
s := d.store.(*libkvmock.Mock) s := d.store.(*libkvmock.Mock)
mockCh := make(chan []*store.KVPair) mockCh := make(chan []*store.KVPair)
// The first watch will fail. // The first watch will fail on those three calls
s.On("Exists", "path/"+discoveryPath).Return(false, errors.New("test error"))
s.On("Put", "path/"+discoveryPath, mock.Anything, mock.Anything).Return(errors.New("test error"))
s.On("WatchTree", "path/"+discoveryPath, mock.Anything).Return(mockCh, errors.New("test error")).Once() s.On("WatchTree", "path/"+discoveryPath, mock.Anything).Return(mockCh, errors.New("test error")).Once()
// The second one will succeed. // The second one will succeed.
s.On("WatchTree", "path/"+discoveryPath, mock.Anything).Return(mockCh, nil).Once() s.On("WatchTree", "path/"+discoveryPath, mock.Anything).Return(mockCh, nil).Once()
expected := discovery.Entries{ expected := discovery.Entries{
@ -89,7 +92,7 @@ func TestWatch(t *testing.T) {
assert.EqualError(t, <-errCh, "test error") assert.EqualError(t, <-errCh, "test error")
// We have to drain the error channel otherwise Watch will get stuck. // We have to drain the error channel otherwise Watch will get stuck.
go func() { go func() {
for _ = range errCh { for range errCh {
} }
}() }()