git » spf » commit f2d70d2

tests: Avoid unkeyed fields in net.MX construction

author Alberto Bertogli
2020-05-22 21:28:00 UTC
committer Alberto Bertogli
2020-05-22 21:32:25 UTC
parent 9418f6137726c5d2ee3cd45e9fd3fccb6bc437ef

tests: Avoid unkeyed fields in net.MX construction

This patch adds a small helper function to avoid relying on unkeyed
fields when creating net.MX structs for testing purposes.

spf_test.go +8 -4
yml_test.go +1 -1

diff --git a/spf_test.go b/spf_test.go
index 7f47dac..e7ab6d8 100644
--- a/spf_test.go
+++ b/spf_test.go
@@ -66,7 +66,7 @@ func TestBasic(t *testing.T) {
 
 	dns.ip["d1111"] = []net.IP{ip1111}
 	dns.ip["d1110"] = []net.IP{ip1110}
-	dns.mx["d1110"] = []*net.MX{{"d1110", 5}, {"nothing", 10}}
+	dns.mx["d1110"] = []*net.MX{mx("d1110", 5), mx("nothing", 10)}
 	dns.addr["1.1.1.1"] = []string{"lalala.", "xx.domain.", "d1111."}
 	dns.ip["lalala"] = []net.IP{ip1111}
 	dns.ip["xx.domain"] = []net.IP{ip1111}
@@ -117,7 +117,7 @@ func TestIPv6(t *testing.T) {
 
 	dns.ip["d6666"] = []net.IP{ip6666}
 	dns.ip["d6660"] = []net.IP{ip6660}
-	dns.mx["d6660"] = []*net.MX{{"d6660", 5}, {"nothing", 10}}
+	dns.mx["d6660"] = []*net.MX{mx("d6660", 5), mx("nothing", 10)}
 	dns.addr["2001:db8::68"] = []string{"sonlas6.", "domain.", "d6666."}
 	dns.ip["domain"] = []net.IP{ip1111}
 	dns.ip["sonlas6"] = []net.IP{ip6666}
@@ -254,7 +254,7 @@ func TestDNSTemporaryErrors(t *testing.T) {
 	// Domain "tmperr" will fail resolution with a temporary error.
 	dns.errors["tmperr"] = dnsError
 	dns.errors["1.1.1.1"] = dnsError
-	dns.mx["tmpmx"] = []*net.MX{{"tmperr", 10}}
+	dns.mx["tmpmx"] = []*net.MX{mx("tmperr", 10)}
 	trace = t.Logf
 
 	cases := []struct {
@@ -288,7 +288,7 @@ func TestDNSPermanentErrors(t *testing.T) {
 	// Domain "tmperr" will fail resolution with a temporary error.
 	dns.errors["tmperr"] = dnsError
 	dns.errors["1.1.1.1"] = dnsError
-	dns.mx["tmpmx"] = []*net.MX{{"tmperr", 10}}
+	dns.mx["tmpmx"] = []*net.MX{mx("tmperr", 10)}
 	trace = t.Logf
 
 	cases := []struct {
@@ -397,3 +397,7 @@ func TestMacrosV4(t *testing.T) {
 		}
 	}
 }
+
+func mx(host string, pref uint16) *net.MX {
+	return &net.MX{Host: host, Pref: pref}
+}
diff --git a/yml_test.go b/yml_test.go
index 8f22d16..aa059eb 100644
--- a/yml_test.go
+++ b/yml_test.go
@@ -175,7 +175,7 @@ func testRFC(t *testing.T, fname string) {
 				}
 				if record.MX != nil {
 					dns.mx[domain] = append(dns.mx[domain],
-						&net.MX{record.MX.Host, record.MX.Prio})
+						mx(record.MX.Host, record.MX.Prio))
 				}
 				for _, s := range record.PTR {
 					// domain in this case is of the form: