mdns/server_test.go

62 lines
1.1 KiB
Go
Raw Normal View History

2014-01-29 14:36:46 -08:00
package mdns
import (
"testing"
2014-01-29 15:58:17 -08:00
"time"
2014-01-29 14:36:46 -08:00
)
func TestServer_StartStop(t *testing.T) {
s := makeService(t)
serv, err := NewServer(&Config{Zone: s})
2014-01-29 14:36:46 -08:00
if err != nil {
t.Fatalf("err: %v", err)
}
defer serv.Shutdown()
}
2014-01-29 15:58:17 -08:00
func TestServer_Lookup(t *testing.T) {
s := makeService(t)
s.Service = "_foobar._tcp"
s.Init()
serv, err := NewServer(&Config{Zone: s})
2014-01-29 15:58:17 -08:00
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)
2014-01-29 15:58:17 -08:00
if err != nil {
t.Fatalf("err: %v", err)
}
if !found {
t.Fatalf("record not found")
}
}