-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdns_test.go
53 lines (47 loc) · 1.38 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
package main
import (
"net"
"testing"
)
func TestResolveFqdnWithDnsAddresses_Success(t *testing.T) {
fqdn := "example.com."
dnsa := []string{"8.8.8.8", "8.8.4.4"}
ip, ttl, err := resolveFqdn(fqdn, dnsa, nil)
if err != nil {
t.Errorf("Error resolving FQDN: %v", err)
}
t.Logf("Resolved IP: %s, TTL: %d", ip, ttl)
}
func TestResolveFqdnWithDnsAddresses_Failure(t *testing.T) {
fqdn := "example.5368235687."
dnsa := []string{"222.222.222.222", "8.8.8.8", "8.8.4.4"}
ip, ttl, err := resolveFqdn(fqdn, dnsa, nil)
if err == nil {
t.Errorf("Succeded, but should have failed: %v", err)
}
t.Logf("Resolved IP: %s, TTL: %d", ip, ttl)
}
func TestResolveFqdnWithoutDnsAddresses(t *testing.T) {
fqdn := "example.com."
ip, ttl, err := resolveFqdn(fqdn, nil, nil)
if err != nil {
t.Errorf("Error resolving FQDN: %v", err)
}
t.Logf("Resolved IP: %s, TTL: %d", ip, ttl)
}
func TestResolveFqdWrongFqdn(t *testing.T) {
fqdn := ".com"
_, _, err := resolveFqdn(fqdn, nil, nil)
if err == nil {
t.Errorf("Expected error due to erroneous FQDN, but didn't get it")
}
}
func TestResolveFqdnWithCustomResolver(t *testing.T) {
fqdn := "example.com."
dnsa := []string{"8.8.8.8", "8.8.4.4"}
mockResolver := func(f string, dnsa []string) (net.IP, uint32, error) {
return net.ParseIP("1.1.1.1"), 600, nil
}
ip, ttl, _ := resolveFqdn(fqdn, dnsa, mockResolver)
t.Logf("Resolved IP: %s, TTL: %d", ip, ttl)
}