50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package checker
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestJoinSubdomain(t *testing.T) {
|
|
cases := []struct {
|
|
sub, origin, want string
|
|
}{
|
|
{"", "example.com", "example.com."},
|
|
{"@", "example.com", "example.com."},
|
|
{"www", "example.com", "www.example.com."},
|
|
{"www.", "example.com.", "www.example.com."},
|
|
{"www.example.com", "example.com", "www.example.com."},
|
|
{"example.com", "example.com", "example.com."},
|
|
}
|
|
for _, c := range cases {
|
|
got := joinSubdomain(c.sub, c.origin)
|
|
if got != c.want {
|
|
t.Errorf("joinSubdomain(%q,%q) = %q, want %q", c.sub, c.origin, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestResolvers_Explicit(t *testing.T) {
|
|
got := resolvers("1.1.1.1, 8.8.8.8:5353 ,")
|
|
want := []string{"1.1.1.1:53", "8.8.8.8:5353"}
|
|
if !reflect.DeepEqual(got, want) {
|
|
t.Errorf("got %v, want %v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestResolvers_FallbackList(t *testing.T) {
|
|
// We don't trust /etc/resolv.conf to be absent in all CI environments,
|
|
// but the empty-input path must always return at least one resolver.
|
|
got := resolvers("")
|
|
if len(got) == 0 {
|
|
t.Fatal("expected at least one resolver")
|
|
}
|
|
}
|
|
|
|
func TestMaxAnswerRecords_Constant(t *testing.T) {
|
|
// Sanity check: don't silently lower the cap to something useless
|
|
// without updating tests / behaviour.
|
|
if maxAnswerRecords < 8 {
|
|
t.Errorf("maxAnswerRecords=%d is suspiciously low", maxAnswerRecords)
|
|
}
|
|
}
|