dyndns-server/nameserver_test.go

68 lines
1.1 KiB
Go

package main
import (
"net"
"testing"
"github.com/foxcpp/go-mockdns"
)
func TestRequiresRRUpdate(t *testing.T) {
tests := []struct {
name string
record string
addr net.IP
expRes bool
}{
{
"nonexistent record",
"invalid.example.org",
net.ParseIP("1.1.1.1"),
true,
},
{
"ipv4 update required",
"ipv4.example.org",
net.ParseIP("1.1.1.1"),
true,
},
{
"ipv4 up to date",
"ipv4.example.org",
net.ParseIP("2.2.2.2"),
false,
},
{
"ipv6 up to date",
"ipv6.example.org",
net.ParseIP("1:1:1:1:1:1:1:1"),
true,
},
{
"ipv6 up to date",
"ipv6.example.org",
net.ParseIP("2:2:2:2:2:2:2:2"),
false,
},
}
// setup mock resolver
resolver := mockdns.Resolver{
Zones: map[string]mockdns.Zone{
"ipv4.example.org.": {
A: []string{"2.2.2.2"},
},
"ipv6.example.org.": {
AAAA: []string{"2:2:2:2:2:2:2:2"},
},
},
}
for _, tc := range tests {
res := requiresRRUpdate(tc.record, tc.addr, &resolver)
if tc.expRes != res {
t.Errorf("%s: has=%v, wanted=%v", tc.name, res, tc.expRes)
}
}
}