-
Notifications
You must be signed in to change notification settings - Fork 12
/
util_test.go
64 lines (54 loc) · 1.18 KB
/
util_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
package fastdns
import (
"runtime"
"testing"
)
func TestEncodeDomain(t *testing.T) {
var cases = []struct {
Domain string
QName string
}{
{"phus.lu", "\x04phus\x02lu\x00"},
{"splunk.phus.lu", "\x06splunk\x04phus\x02lu\x00"},
}
for _, c := range cases {
if got, want := string(EncodeDomain(nil, c.Domain)), c.QName; got != want {
t.Errorf("EncodeDomain(%v) error got=%#v want=%#v", c.Domain, got, want)
}
}
}
func TestListen(t *testing.T) {
if runtime.GOOS != "linux" {
return
}
_, err := listen("udp", ":65537")
if err == nil {
t.Errorf("listen(:65537) at shall return error but empty")
}
var addr = ":19841"
for i := 1; i <= 64; i++ {
_, err := listen("udp", addr)
if err != nil {
t.Errorf("listen(%+v) at %d times got error: %+v", addr, i, err)
}
}
}
func TestTastset(t *testing.T) {
if runtime.GOOS != "linux" {
return
}
err := taskset(1023)
if err == nil {
t.Errorf("taskset(65537) shall return error but empty")
}
err = taskset(0)
if err != nil {
t.Errorf("taskset(0) error: %+v", err)
}
}
func BenchmarkEncodeDomain(b *testing.B) {
dst := make([]byte, 0, 256)
for i := 0; i < b.N; i++ {
dst = EncodeDomain(dst[:0], "hk.phus.lu")
}
}