-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpublicip_test.go
38 lines (33 loc) · 940 Bytes
/
publicip_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
package publicip
import (
"testing"
"github.com/miekg/dns"
)
func TestGetAddress(t *testing.T) {
_, err := GetIP()
if err != nil {
t.Errorf("Error: %s\n", err)
}
}
func TestGenerateClientError(t *testing.T) {
config := dns.ClientConfig{Servers: []string{"0.0.0.0"}, Port: "53"}
dnsClient := new(dns.Client)
message := new(dns.Msg)
message.SetQuestion("myip.opendns.com.", dns.TypeA)
message.RecursionDesired = false
_, err := doDNSLookup(config, dnsClient, message)
if err == nil {
t.Errorf("Expected error, got nil")
}
}
func TestGenerateLookupError(t *testing.T) {
config := dns.ClientConfig{Servers: []string{"208.67.220.220", "208.67.222.222"}, Port: "53"}
dnsClient := new(dns.Client)
message := new(dns.Msg)
message.SetQuestion("notmyip.opendns.com.", dns.TypeA)
message.RecursionDesired = false
_, err := doDNSLookup(config, dnsClient, message)
if err == nil {
t.Errorf("Expected error, got nil")
}
}