git » chasquid » commit 933b979

smtpsrv: Don't hard-code ports in tests

author Alberto Bertogli
2019-11-30 11:38:13 UTC
committer Alberto Bertogli
2019-11-30 11:38:46 UTC
parent d0f65881c984d5aed330fadc6efc808c7f7b2271

smtpsrv: Don't hard-code ports in tests

The smtpsrv tests hard-code ports, but this patch fixes that by making it
use the new testlib.GetFreePort function.

internal/smtpsrv/server_test.go +9 -5

diff --git a/internal/smtpsrv/server_test.go b/internal/smtpsrv/server_test.go
index 292ee1c..23a5e90 100644
--- a/internal/smtpsrv/server_test.go
+++ b/internal/smtpsrv/server_test.go
@@ -19,6 +19,7 @@ import (
 
 	"blitiri.com.ar/go/chasquid/internal/aliases"
 	"blitiri.com.ar/go/chasquid/internal/courier"
+	"blitiri.com.ar/go/chasquid/internal/testlib"
 	"blitiri.com.ar/go/chasquid/internal/userdb"
 )
 
@@ -33,12 +34,11 @@ var (
 )
 
 var (
-	// Server addresses.
+	// Server addresses. Will be filled in at init time.
 	// We default to internal ones, but may get overridden via flags.
-	// TODO: Don't hard-code the default.
-	smtpAddr          = "127.0.0.1:13444"
-	submissionAddr    = "127.0.0.1:13999"
-	submissionTLSAddr = "127.0.0.1:13777"
+	smtpAddr          = ""
+	submissionAddr    = ""
+	submissionTLSAddr = ""
 
 	// TLS configuration to use in the clients.
 	// Will contain the generated server certificate as root CA.
@@ -470,6 +470,10 @@ func realMain(m *testing.M) int {
 			return 1
 		}
 
+		smtpAddr = testlib.GetFreePort()
+		submissionAddr = testlib.GetFreePort()
+		submissionTLSAddr = testlib.GetFreePort()
+
 		s := NewServer()
 		s.Hostname = "localhost"
 		s.MaxDataSize = 50 * 1024 * 1025