test: add unit test for TestEnsureDomainsResolveSameIPv4
This commit is contained in:
parent
906bf65d47
commit
b53fd2689c
38
pkg/dns/dns_test.go
Normal file
38
pkg/dns/dns_test.go
Normal 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user