Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/cql/cql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/freshworks/load-generator/internal/stats"
"github.com/gocql/gocql"
"github.com/ory/dockertest/v3"
dc "github.com/ory/dockertest/v3/docker"
mysqlquery "github.com/percona/go-mysql/query"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -123,9 +124,15 @@ func startCassandra() (*dockertest.Pool, *dockertest.Resource, error) {
"--permissions-update-interval-in-ms", "100",
"--permissions-validity-in-ms", "100",
},
ExposedPorts: []string{"9042/tcp"},
PortBindings: map[dc.Port][]dc.PortBinding{
"9042/tcp": {{HostIP: "", HostPort: ""}},
},
}

resource, err := pool.RunWithOptions(o)
resource, err := pool.RunWithOptions(o, func(hc *dc.HostConfig) {
hc.PublishAllPorts = false
})
if err != nil {
return nil, nil, err
}
Expand Down
9 changes: 8 additions & 1 deletion internal/lua/lua_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/gocql/gocql"
"github.com/google/uuid"
"github.com/ory/dockertest/v3"
dc "github.com/ory/dockertest/v3/docker"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -1143,9 +1144,15 @@ func startCassandra() (*dockertest.Pool, *dockertest.Resource, error) {
"--permissions-update-interval-in-ms", "100",
"--permissions-validity-in-ms", "100",
},
ExposedPorts: []string{"9042/tcp"},
PortBindings: map[dc.Port][]dc.PortBinding{
"9042/tcp": {{HostIP: "", HostPort: ""}},
},
}

resource, err := pool.RunWithOptions(o)
resource, err := pool.RunWithOptions(o, func(hc *dc.HostConfig) {
hc.PublishAllPorts = false
})
if err != nil {
return nil, nil, err
}
Expand Down
27 changes: 18 additions & 9 deletions internal/psql/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/stdlib"
"github.com/ory/dockertest/v3"
dc "github.com/ory/dockertest/v3/docker"
mysqlquery "github.com/percona/go-mysql/query"
)

Expand Down Expand Up @@ -100,7 +101,9 @@ func runPostgresDB(version string, certData *Cert) (string /*DB Connection Strin
//
// fmt.Printf("\n\ncontainer logs: %v\n\n", string(bytes))

pool.Purge(resource)
if resource != nil {
pool.Purge(resource)
}
}
// if function panics anywhere in further steps,
// cleanup resources.
Expand Down Expand Up @@ -155,14 +158,20 @@ func runDockerContainer(repo string, tag string, mountOptions []string, envOptio
}

o := &dockertest.RunOptions{
Repository: repo,
Tag: tag,
Mounts: mountOptions,
Env: envOptions,
Cmd: cmdOptions,
Entrypoint: entrypointOverrides,
}
resource, err := pool.RunWithOptions(o)
Repository: repo,
Tag: tag,
Mounts: mountOptions,
Env: envOptions,
Cmd: cmdOptions,
Entrypoint: entrypointOverrides,
ExposedPorts: []string{postgresPort + "/tcp"},
PortBindings: map[dc.Port][]dc.PortBinding{
dc.Port(postgresPort + "/tcp"): {{HostIP: "", HostPort: ""}},

Copilot AI Dec 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty HostIP and HostPort values in PortBinding may lead to unexpected behavior. Consider documenting the intended behavior when these are empty strings, or explicitly set them to meaningful defaults if automatic assignment is not the desired outcome.

Suggested change
dc.Port(postgresPort + "/tcp"): {{HostIP: "", HostPort: ""}},
dc.Port(postgresPort + "/tcp"): {{HostIP: "0.0.0.0", HostPort: ""}},

Copilot uses AI. Check for mistakes.
},
Comment on lines +167 to +170

Copilot AI Dec 23, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PostgreSQL port configuration uses a variable 'postgresPort' while Cassandra configurations use hardcoded '9042/tcp'. This inconsistency makes the codebase harder to maintain. Consider either defining a constant for the Cassandra port or documenting why PostgreSQL uses a variable while Cassandra uses a hardcoded value.

Copilot uses AI. Check for mistakes.
}
resource, err := pool.RunWithOptions(o, func(hc *dc.HostConfig) {
hc.PublishAllPorts = false
})

return resource, pool, err
}
Expand Down
Loading