Mock watcher that just blocks

This commit is contained in:
Asim 2016-04-26 18:32:43 +01:00
parent decb70b97c
commit f7c57fd4f4
2 changed files with 29 additions and 1 deletions

View File

@ -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 {

View File

@ -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)
}
}