-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_dns_test.go
42 lines (37 loc) · 909 Bytes
/
check_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
package healthz
import (
"context"
"fmt"
"net/http"
"testing"
"github.com/stretchr/testify/require"
)
func TestCheckDNS(t *testing.T) {
var tests = []struct {
address string
network string
expectError bool
}{
{"www.google.com", "ip4", false},
{"www.google.com", "ip6", false},
{"error.jasonhancock.com", "ip4", true},
{"jasonhancock.com", "ip4", false},
{"jasonhancock.com", "ip6", true},
}
for _, tt := range tests {
t.Run(fmt.Sprintf("%s-%s", tt.address, tt.network), func(t *testing.T) {
c := NewCheckDNS(tt.network, tt.address)
result := c.Check(context.Background())
if tt.expectError {
require.Error(t, result.Error)
} else {
require.NoError(t, result.Error)
}
})
}
}
func ExampleCheckDNS() {
checker := NewChecker()
checker.AddCheck("dns-www.google.com", NewCheckDNS("ip4", "www.google.com"))
http.ListenAndServe(":8080", checker)
}