Skip to content

Commit e3a0ef6

Browse files
committed
chore(cassandra): use Run function
1 parent c3b4d4c commit e3a0ef6

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

modules/cassandra/cassandra.go

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import (
77
"path/filepath"
88
"strings"
99

10-
"github.com/docker/go-connections/nat"
11-
1210
"github.com/testcontainers/testcontainers-go"
1311
"github.com/testcontainers/testcontainers-go/wait"
1412
)
1513

1614
const (
17-
port = nat.Port("9042/tcp")
15+
port = "9042/tcp"
1816
)
1917

2018
// CassandraContainer represents the Cassandra container type used in the module
@@ -73,45 +71,35 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
7371

7472
// Run creates an instance of the Cassandra container type
7573
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) {
76-
req := testcontainers.ContainerRequest{
77-
Image: img,
78-
ExposedPorts: []string{string(port)},
79-
Env: map[string]string{
74+
moduleOpts := []testcontainers.ContainerCustomizer{
75+
testcontainers.WithExposedPorts(port),
76+
testcontainers.WithEnv(map[string]string{
8077
"CASSANDRA_SNITCH": "GossipingPropertyFileSnitch",
8178
"JVM_OPTS": "-Dcassandra.skip_wait_for_gossip_to_settle=0 -Dcassandra.initial_token=0",
8279
"HEAP_NEWSIZE": "128M",
8380
"MAX_HEAP_SIZE": "1024M",
8481
"CASSANDRA_ENDPOINT_SNITCH": "GossipingPropertyFileSnitch",
8582
"CASSANDRA_DC": "datacenter1",
86-
},
87-
WaitingFor: wait.ForAll(
83+
}),
84+
testcontainers.WithWaitStrategy(wait.ForAll(
8885
wait.ForListeningPort(port),
8986
wait.ForExec([]string{"cqlsh", "-e", "SELECT bootstrapped FROM system.local"}).WithResponseMatcher(func(body io.Reader) bool {
9087
data, _ := io.ReadAll(body)
9188
return strings.Contains(string(data), "COMPLETED")
9289
}),
93-
),
94-
}
95-
96-
genericContainerReq := testcontainers.GenericContainerRequest{
97-
ContainerRequest: req,
98-
Started: true,
90+
)),
9991
}
10092

101-
for _, opt := range opts {
102-
if err := opt.Customize(&genericContainerReq); err != nil {
103-
return nil, err
104-
}
105-
}
93+
moduleOpts = append(moduleOpts, opts...)
10694

107-
container, err := testcontainers.GenericContainer(ctx, genericContainerReq)
95+
ctr, err := testcontainers.Run(ctx, img, moduleOpts...)
10896
var c *CassandraContainer
109-
if container != nil {
110-
c = &CassandraContainer{Container: container}
97+
if ctr != nil {
98+
c = &CassandraContainer{Container: ctr}
11199
}
112100

113101
if err != nil {
114-
return c, fmt.Errorf("generic container: %w", err)
102+
return c, fmt.Errorf("run cassandra: %w", err)
115103
}
116104

117105
return c, nil

modules/cassandra/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.24.0
55
toolchain go1.24.7
66

77
require (
8-
github.com/docker/go-connections v0.6.0
98
github.com/gocql/gocql v1.6.0
109
github.com/stretchr/testify v1.10.0
1110
github.com/testcontainers/testcontainers-go v0.39.0
@@ -24,6 +23,7 @@ require (
2423
github.com/davecgh/go-spew v1.1.1 // indirect
2524
github.com/distribution/reference v0.6.0 // indirect
2625
github.com/docker/docker v28.3.3+incompatible // indirect
26+
github.com/docker/go-connections v0.6.0 // indirect
2727
github.com/docker/go-units v0.5.0 // indirect
2828
github.com/ebitengine/purego v0.8.4 // indirect
2929
github.com/felixge/httpsnoop v1.0.4 // indirect

0 commit comments

Comments
 (0)