test: add unit test for TestEnsureDomainsResolveSameIPv4

This commit is contained in:
decentral1se 2023-09-30 08:19:02 +02:00
parent 906bf65d47
commit b53fd2689c
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 38 additions and 0 deletions

38
pkg/dns/dns_test.go Normal file
View File

@ -0,0 +1,38 @@
package dns
import (
"fmt"
"testing"
)
func TestEnsureDomainsResolveSameIPv4(t *testing.T) {
tests := []struct {
domainName string
serverName string
shouldValidate bool
}{
// NOTE(d1): DNS records get checked, so use something we control. if
// you're here because of a failing test, try `dig +short <domain>` to
// ensure stuff matches first!
{"docs.coopcloud.tech", "coopcloud.tech", true},
{"docs.coopcloud.tech", "swarm.autonomic.zone", true},
// NOTE(d1): special case handling for "--local"
{"", "default", true},
{"", "local", true},
{"", "", false},
{"123", "", false},
}
for _, test := range tests {
_, err := EnsureDomainsResolveSameIPv4(test.domainName, test.serverName)
if err != nil && test.shouldValidate {
t.Fatal(err)
}
if err == nil && !test.shouldValidate {
t.Fatal(fmt.Errorf("should have failed but did not: %v", test))
}
}
}