gitee.com/liuxuezhan/go-micro-v1.18.0@v1.0.0/registry/memory/watcher_test.go (about)

     1  package memory
     2  
     3  import (
     4  	"testing"
     5  
     6  	"gitee.com/liuxuezhan/go-micro-v1.18.0/registry"
     7  )
     8  
     9  func TestWatcher(t *testing.T) {
    10  	w := &Watcher{
    11  		id:   "test",
    12  		res:  make(chan *registry.Result),
    13  		exit: make(chan bool),
    14  	}
    15  
    16  	go func() {
    17  		w.res <- &registry.Result{}
    18  	}()
    19  
    20  	_, err := w.Next()
    21  	if err != nil {
    22  		t.Fatal("unexpected err", err)
    23  	}
    24  
    25  	w.Stop()
    26  
    27  	if _, err := w.Next(); err == nil {
    28  		t.Fatal("expected error on Next()")
    29  	}
    30  }