forked from libp2p/zeroconf
-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils_test.go
53 lines (47 loc) · 1.16 KB
/
utils_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
package zeroconf
import (
"testing"
"github.com/miekg/dns"
)
func TestUnescapeDns(t *testing.T) {
names := []string{
"example.com.",
"Bryan’s iPad.local.", // 3 byte unicode char
"4 byte unicode 𐍈.",
}
for _, name := range names {
msg := make([]byte, 100)
_, err := dns.PackDomainName(name, msg, 0, nil, false)
if err != nil {
t.Fatalf("failed to pack [%v]: %v", name, err)
}
domain, _, err := dns.UnpackDomainName(msg, 0)
if err != nil {
t.Fatalf("failed to pack [%v]: %v", name, err)
}
got := unescapeDns(domain)
if got != name {
t.Fatalf("expected [%v], got [%v]", name, got)
}
}
}
func TestUnescapeDDD(t *testing.T) {
got, expected := unescapeDDD(`\226\128\153`), `’`
if got != expected {
t.Fatalf("expected [%v], got [%v]", expected, got)
}
}
func TestEnsureSuffix(t *testing.T) {
got := ensureSuffix("foo", ".local")
expected := "foo.local"
if got != expected {
t.Fatalf("expected [%v], got [%v]", expected, got)
}
}
func TestEnsureSuffixAlreadyPresent(t *testing.T) {
got := ensureSuffix("foo.local", ".local")
expected := "foo.local"
if got != expected {
t.Fatalf("expected [%v], got [%v]", expected, got)
}
}