@@ -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
1614const (
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
7573func 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
0 commit comments