git » chasquid » commit 6867859

courier: Make the SMTP test not use the network

author Alberto Bertogli
2017-07-16 12:24:40 UTC
committer Alberto Bertogli
2017-07-16 12:24:40 UTC
parent 5426be5aecad077d977bdc1c3a59e8a59028a43c

courier: Make the SMTP test not use the network

One of the SMTP tests was doing an external DNS lookup for a
non-existing host, which is reasonably harmless but makes the test less
hermetic.

This patch changes the non-existing host for an invalid address, which
has the same effect but avoids the network lookup.

This is a hack; ideally we would be able to override the resolver, but
Go does not implement that yet, and changing the code is not worth the
additional complexity.

internal/courier/smtp_test.go +5 -1

diff --git a/internal/courier/smtp_test.go b/internal/courier/smtp_test.go
index 7edef1e..c51d691 100644
--- a/internal/courier/smtp_test.go
+++ b/internal/courier/smtp_test.go
@@ -84,7 +84,11 @@ func TestSMTP(t *testing.T) {
 
 	// Put a non-existing host first, so we check that if the first host
 	// doesn't work, we try with the rest.
-	fakeMX["to"] = []string{"nonexistinghost", host}
+	// The host we use is invalid, to avoid having to do an actual network
+	// lookup whick makes the test more hermetic. This is a hack, ideally we
+	// would be able to override the default resolver, but Go does not
+	// implement that yet.
+	fakeMX["to"] = []string{":::", host}
 	*smtpPort = port
 
 	s, tmpDir := newSMTP(t)