Skip to content

Commit

Permalink
testserver/datastore: misc docker arg cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie authored and vroldanbet committed Mar 20, 2024
1 parent 106d855 commit 88618b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
12 changes: 4 additions & 8 deletions internal/testserver/datastore/crdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 12 additions & 13 deletions internal/testserver/datastore/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
)

const (
mysqlPort = 3306
mysqlPortStr = "3306/tcp"
mysqlPort = "3306"
mysqlPortPair = mysqlPort + "/tcp"
defaultCreds = "root:secret"
testDBPrefix = "spicedb_test_"
)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 88618b9

Please sign in to comment.