From 88618b9a67fcce354d660baf609cd432a848e09c Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Mon, 3 Jul 2023 18:26:56 -0400 Subject: [PATCH] testserver/datastore: misc docker arg cleanup --- internal/testserver/datastore/crdb.go | 12 ++++-------- internal/testserver/datastore/mysql.go | 25 ++++++++++++------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/internal/testserver/datastore/crdb.go b/internal/testserver/datastore/crdb.go index be61279a18..1ed29fa714 100644 --- a/internal/testserver/datastore/crdb.go +++ b/internal/testserver/datastore/crdb.go @@ -46,24 +46,20 @@ func RunCRDBForTesting(t testing.TB, bridgeNetworkName string) RunningEngineForT NetworkID: bridgeNetworkName, }) require.NoError(t, err) - - builder := &crdbTester{ - hostname: "localhost", - creds: "root:fake", - } t.Cleanup(func() { require.NoError(t, pool.Purge(resource)) }) - port := resource.GetPort(fmt.Sprintf("%d/tcp", 26257)) + builder := &crdbTester{creds: "root:fake"} if bridgeNetworkName != "" { builder.hostname = name builder.port = "26257" } else { - builder.port = port + builder.hostname = "localhost" + builder.port = resource.GetPort("26257/tcp") } - uri := fmt.Sprintf("postgres://%s@localhost:%s/defaultdb?sslmode=disable", builder.creds, port) + uri := fmt.Sprintf("postgres://%s@localhost:%s/defaultdb?sslmode=disable", builder.creds, builder.port) require.NoError(t, pool.Retry(func() error { var err error ctx, cancelConnect := context.WithTimeout(context.Background(), dockerBootTimeout) diff --git a/internal/testserver/datastore/mysql.go b/internal/testserver/datastore/mysql.go index aa648867b3..531c444134 100644 --- a/internal/testserver/datastore/mysql.go +++ b/internal/testserver/datastore/mysql.go @@ -21,8 +21,8 @@ import ( ) const ( - mysqlPort = 3306 - mysqlPortStr = "3306/tcp" + mysqlPort = "3306" + mysqlPortPair = mysqlPort + "/tcp" defaultCreds = "root:secret" testDBPrefix = "spicedb_test_" ) @@ -62,30 +62,29 @@ func RunMySQLForTestingWithOptions(t testing.TB, options MySQLTesterOptions, bri Repository: "mysql", Tag: containerImageTag, Env: []string{"MYSQL_ROOT_PASSWORD=secret"}, - ExposedPorts: []string{mysqlPortStr}, - // increase max connections (default 151) to accommodate tests using the same docker container - Cmd: []string{"--max-connections=500"}, - NetworkID: bridgeNetworkName, + ExposedPorts: []string{mysqlPortPair}, + Cmd: []string{"--max-connections=500"}, // accommodate tests using the same container + NetworkID: bridgeNetworkName, }) require.NoError(t, err) + t.Cleanup(func() { + require.NoError(t, pool.Purge(resource)) + }) builder := &mysqlTester{ creds: defaultCreds, options: options, } - t.Cleanup(func() { - require.NoError(t, pool.Purge(resource)) - }) - port := resource.GetPort(mysqlPortStr) if bridgeNetworkName != "" { builder.hostname = name - builder.port = fmt.Sprintf("%d", mysqlPort) + builder.port = mysqlPort } else { - builder.port = port + builder.hostname = "localhost" + builder.port = resource.GetPort(mysqlPortPair) } - dsn := fmt.Sprintf("%s@(localhost:%s)/mysql?parseTime=true", builder.creds, port) + dsn := fmt.Sprintf("%s@(localhost:%s)/mysql?parseTime=true", builder.creds, builder.port) require.NoError(t, pool.Retry(func() error { var err error builder.db, err = sql.Open("mysql", dsn)