From f7c57fd4f48b704899efd3c22ef5a56b485b178a Mon Sep 17 00:00:00 2001 From: Asim Date: Tue, 26 Apr 2016 18:32:43 +0100 Subject: [PATCH] Mock watcher that just blocks --- registry/mock/mock.go | 2 +- registry/mock/mock_watcher.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 registry/mock/mock_watcher.go diff --git a/registry/mock/mock.go b/registry/mock/mock.go index b0548a2f..f034ba6f 100644 --- a/registry/mock/mock.go +++ b/registry/mock/mock.go @@ -88,7 +88,7 @@ func (m *mockRegistry) Deregister(s *registry.Service) error { } func (m *mockRegistry) Watch() (registry.Watcher, error) { - return nil, nil + return &mockWatcher{exit: make(chan bool)}, nil } func (m *mockRegistry) String() string { diff --git a/registry/mock/mock_watcher.go b/registry/mock/mock_watcher.go new file mode 100644 index 00000000..26580730 --- /dev/null +++ b/registry/mock/mock_watcher.go @@ -0,0 +1,28 @@ +package mock + +import ( + "errors" + + "github.com/micro/go-micro/registry" +) + +type mockWatcher struct { + exit chan bool +} + +func (m *mockWatcher) Next() (*registry.Result, error) { + // not implement so we just block until exit + select { + case <-m.exit: + return nil, errors.New("watcher stopped") + } +} + +func (m *mockWatcher) Stop() { + select { + case <-m.exit: + return + default: + close(m.exit) + } +}