-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathserver_test.go
75 lines (67 loc) · 1.47 KB
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MIT
package mdns
import (
"fmt"
"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)
}
if err := serv.Shutdown(); err != nil {
t.Fatalf("err: %v", err)
}
}
func TestServer_Lookup(t *testing.T) {
serv, err := NewServer(&Config{Zone: makeServiceWithServiceName(t, "_foobar._tcp")})
if err != nil {
t.Fatalf("err: %v", err)
}
defer func() {
if err := serv.Shutdown(); err != nil {
t.Fatalf("err: %v", err)
}
}()
entries := make(chan *ServiceEntry, 1)
errCh := make(chan error, 1)
defer close(errCh)
go func() {
select {
case e := <-entries:
if e.Name != "hostname._foobar._tcp.local." {
errCh <- fmt.Errorf("Entry has the wrong name: %+v", e)
return
}
if e.Port != 80 {
errCh <- fmt.Errorf("Entry has the wrong port: %+v", e)
return
}
if e.Info != "Local web server" {
errCh <- fmt.Errorf("Entry as the wrong Info: %+v", e)
return
}
errCh <- nil
case <-time.After(80 * time.Millisecond):
errCh <- fmt.Errorf("Timed out waiting for response")
}
}()
params := &QueryParam{
Service: "_foobar._tcp",
Domain: "local",
Timeout: 50 * time.Millisecond,
Entries: entries,
DisableIPv6: true,
}
err = Query(params)
if err != nil {
t.Fatalf("err: %v", err)
}
err = <-errCh
if err != nil {
t.Fatalf("err: %v", err)
}
}