micro/registry/memory/watcher_test.go
ben-toogood 51b4ab0abc
registry/memory: watcher bug fixes (#1740)
* registry/memory: watcher bugfixes

* registry/memory: fix nil watcher bug

* registry/memory: fix watcher test
2020-06-25 11:02:35 +01:00

36 lines
543 B
Go

package memory
import (
"testing"
"github.com/micro/go-micro/v2/registry"
)
func TestWatcher(t *testing.T) {
w := &Watcher{
id: "test",
res: make(chan *registry.Result),
exit: make(chan bool),
wo: registry.WatchOptions{
Domain: registry.WildcardDomain,
},
}
go func() {
w.res <- &registry.Result{
Service: &registry.Service{Name: "foo"},
}
}()
_, err := w.Next()
if err != nil {
t.Fatal("unexpected err", err)
}
w.Stop()
if _, err := w.Next(); err == nil {
t.Fatal("expected error on Next()")
}
}