mirror of
https://github.com/linka-cloud/grpc.git
synced 2025-06-22 17:22:26 +00:00
add registry base interface, mdns, noop implementations, add resolver, client
This commit is contained in:
61
registry/mdns/server_test.go
Normal file
61
registry/mdns/server_test.go
Normal file
@ -0,0 +1,61 @@
|
||||
package mdns
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestServer_StartStop(t *testing.T) {
|
||||
s := makeService(t)
|
||||
serv, err := NewServer(&Config{Zone: s, LocalhostChecking: true})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
defer serv.Shutdown()
|
||||
}
|
||||
|
||||
func TestServer_Lookup(t *testing.T) {
|
||||
serv, err := NewServer(&Config{Zone: makeServiceWithServiceName(t, "_foobar._tcp"), LocalhostChecking: true})
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
defer serv.Shutdown()
|
||||
|
||||
entries := make(chan *ServiceEntry, 1)
|
||||
found := false
|
||||
doneCh := make(chan struct{})
|
||||
go func() {
|
||||
select {
|
||||
case e := <-entries:
|
||||
if e.Name != "hostname._foobar._tcp.local." {
|
||||
t.Fatalf("bad: %v", e)
|
||||
}
|
||||
if e.Port != 80 {
|
||||
t.Fatalf("bad: %v", e)
|
||||
}
|
||||
if e.Info != "Local web server" {
|
||||
t.Fatalf("bad: %v", e)
|
||||
}
|
||||
found = true
|
||||
|
||||
case <-time.After(80 * time.Millisecond):
|
||||
t.Fatalf("timeout")
|
||||
}
|
||||
close(doneCh)
|
||||
}()
|
||||
|
||||
params := &QueryParam{
|
||||
Service: "_foobar._tcp",
|
||||
Domain: "local",
|
||||
Timeout: 50 * time.Millisecond,
|
||||
Entries: entries,
|
||||
}
|
||||
err = Query(params)
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
<-doneCh
|
||||
if !found {
|
||||
t.Fatalf("record not found")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user