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 ` 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)) } } }