-
Notifications
You must be signed in to change notification settings - Fork 22
/
discovery_test.go
73 lines (58 loc) · 1.47 KB
/
discovery_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
package airplay
import (
"log"
"net"
"testing"
"github.com/miekg/dns"
)
func rr(s string) dns.RR {
rr, err := dns.NewRR(s)
if err != nil {
log.Fatal(err)
}
return rr
}
func TestParse(t *testing.T) {
m := new(dns.Msg)
m.Answer = []dns.RR{
rr("example.com. 10 IN PTR GongoTV.example.com."),
}
m.Extra = []dns.RR{
rr("GongoTV.local. 10 IN A 192.0.2.1"),
rr("GongoTV.example.com. 120 IN SRV 0 0 7000 GongoTV.local."),
rr("GongoTV.example.com. 120 IN TXT \"deviceid=00:00:00:00:00:00\" \"model=AppleTV2,1\""),
}
d, _ := newDiscovery()
entry, err := d.parse(m)
if err != nil {
t.Fatalf("Unexpected error (%v)", err)
}
if !entry.ipv4.Equal(net.ParseIP("192.0.2.1")) {
t.Errorf("Unexpected entry.ipv4 (%s)", entry.ipv4)
}
if entry.port != 7000 {
t.Errorf("Unexpected entry.port (%d)", entry.port)
}
if len(entry.textRecords) != 2 {
t.Errorf("Unexpected entry.textRecords (%v)", entry.textRecords)
}
}
func TestParseErrorWithoutRequireRecords(t *testing.T) {
m := new(dns.Msg)
d, _ := newDiscovery()
if _, err := d.parse(m); err == nil {
t.Fatal("It should occurs [PTR not found] error")
}
m.Answer = []dns.RR{
rr("example.com. 10 IN PTR GongoTV.example.com."),
}
if _, err := d.parse(m); err == nil {
t.Fatal("It should occurs [SRV not found] error")
}
m.Extra = []dns.RR{
rr("GongoTV.example.com. 120 IN SRV 0 0 7000 GongoTV.local."),
}
if _, err := d.parse(m); err == nil {
t.Fatal("It should occurs [A not found] error")
}
}