2014-01-30 02:36:46 +04:00
|
|
|
package mdns
|
|
|
|
|
|
|
|
import (
|
2014-01-30 03:58:17 +04:00
|
|
|
"bytes"
|
2014-01-30 02:36:46 +04:00
|
|
|
"testing"
|
2014-01-30 03:58:17 +04:00
|
|
|
"time"
|
2014-01-30 02:36:46 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_StartStop(t *testing.T) {
|
|
|
|
s := makeService(t)
|
|
|
|
serv, err := NewServer(&Config{s})
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
defer serv.Shutdown()
|
|
|
|
}
|
2014-01-30 03:58:17 +04:00
|
|
|
|
|
|
|
func TestServer_Lookup(t *testing.T) {
|
|
|
|
s := makeService(t)
|
|
|
|
s.Service = "_foobar._tcp"
|
|
|
|
s.Init()
|
|
|
|
serv, err := NewServer(&Config{s})
|
|
|
|
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 !bytes.Equal(e.Addr.To4(), []byte{127, 0, 0, 1}) {
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
err = LookupDomain("_foobar._tcp", "local", 50*time.Millisecond, entries)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %v", err)
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
t.Fatalf("record not found")
|
|
|
|
}
|
|
|
|
}
|