forked from mosajjal/sniproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdns_test.go
60 lines (55 loc) · 1.42 KB
/
dns_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
package main
import (
"net"
"testing"
"github.com/mosajjal/dnsclient"
)
func Test_reverse(t *testing.T) {
tests := []struct {
name string
s string
want string
}{
{name: "test1", s: "abc", want: "cba"},
{name: "test2", s: "a", want: "a"},
{name: "test3", s: "aab", want: "baa"},
{name: "test4", s: "zzZ", want: "Zzz"},
{name: "test5", s: "ab2", want: "2ba"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := reverse(tt.s); got != tt.want {
t.Errorf("reverse() = %v, want %v", got, tt.want)
}
})
}
}
func TestDNSClient_lookupDomain4(t *testing.T) {
tmp, err := dnsclient.New("udp://1.1.1.1:53", true, "")
if err != nil {
t.Errorf("failed to set up DNS client")
}
dnsc := DNSClient{C: tmp}
tests := []struct {
client DNSClient
name string
domain string
want net.IP
wantErr bool
}{
{client: dnsc, name: "test1", domain: "ident.me", want: net.IPv4(49, 12, 234, 183), wantErr: false},
{client: dnsc, name: "test1", domain: "ifconfig.me", want: net.IPv4(34, 160, 111, 145), wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := tt.client.lookupDomain4(tt.domain)
if (err != nil) != tt.wantErr {
t.Errorf("DNSClient.lookupDomain4() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !got.Equal(tt.want) {
t.Errorf("DNSClient.lookupDomain4() = %v, want %v", got, tt.want)
}
})
}
}