mdns/server_test.go
Red Daly e39d11792c Refactor mdns.MDNSService API in zone.go.
- Change API for constructing an MDNSService: use NewMDNSService func instead of
  creating an MDNSService struct and calling its Init method.
- Allow full specification of the host name and IP addresses of an MDNSService
  instead of relying on the net package to infer them from the OS.
- Remove deprecated Addr member of MDNSService.
- Modify tests to comply with new API.
2014-10-16 10:38:12 -07:00

59 lines
1.0 KiB
Go

package mdns
import (
"testing"
"time"
)
func TestServer_StartStop(t *testing.T) {
s := makeService(t)
serv, err := NewServer(&Config{Zone: s})
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")})
if err != nil {
t.Fatalf("err: %v", err)
}
defer serv.Shutdown()
entries := make(chan *ServiceEntry, 1)
found := false
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")
}
}()
params := &QueryParam{
Service: "_foobar._tcp",
Domain: "local",
Timeout: 50 * time.Millisecond,
Entries: entries,
}
err = Query(params)
if err != nil {
t.Fatalf("err: %v", err)
}
if !found {
t.Fatalf("record not found")
}
}