mdelapenya commented on code in PR #1780:
URL: 
https://github.com/apache/cassandra-gocql-driver/pull/1780#discussion_r1768749517


##########
main_test.go:
##########
@@ -0,0 +1,145 @@
+//go:build cassandra || integration
+// +build cassandra integration
+
+package gocql
+
+import (
+       "context"
+       "flag"
+       "fmt"
+       "log"
+       "os"
+       "strconv"
+       "testing"
+       "time"
+
+       "github.com/testcontainers/testcontainers-go"
+       "github.com/testcontainers/testcontainers-go/wait"
+)
+
+func TestMain(m *testing.M) {
+       ctx := context.Background()
+
+       flag.Parse()
+
+       cassandraVersion := flagCassVersion.String()[1:]
+
+       jvmOpts := "-Dcassandra.test.fail_writes_ks=test 
-Dcassandra.custom_query_handler_class=org.apache.cassandra.cql3.CustomPayloadMirroringQueryHandler"
+       if *clusterSize == 1 {
+               // speeds up the creation of a single-node cluster.
+               jvmOpts += " -Dcassandra.initial_token=0 
-Dcassandra.skip_wait_for_gossip_to_settle=0"
+       }
+
+       env := map[string]string{
+               "JVM_OPTS":                  jvmOpts,
+               "CASSANDRA_SEEDS":           "cassandra1",
+               "CASSANDRA_DC":              "datacenter1",
+               "HEAP_NEWSIZE":              "100M",
+               "MAX_HEAP_SIZE":             "256M",
+               "CASSANDRA_RACK":            "rack1",
+               "CASSANDRA_ENDPOINT_SNITCH": "GossipingPropertyFileSnitch",
+               "CASS_VERSION":              cassandraVersion,
+       }
+
+       if *flagRunAuthTest {
+               env["AUTH_TEST"] = "true"
+       }
+
+       networkRequest := testcontainers.GenericNetworkRequest{
+               NetworkRequest: testcontainers.NetworkRequest{
+                       Name: "cassandra",
+               },
+       }
+       cassandraNetwork, err := testcontainers.GenericNetwork(ctx, 
networkRequest)
+       if err != nil {
+               log.Fatalf("Failed to create network: %s", err)
+       }
+       defer cassandraNetwork.Remove(ctx)
+
+       // Function to create a Cassandra container (node)
+       createCassandraContainer := func(number int) (string, error) {
+               req := testcontainers.ContainerRequest{
+                       Image:        "cassandra:" + cassandraVersion,
+                       ExposedPorts: []string{"9042/tcp"},
+                       Env:          env,
+                       Files: []testcontainers.ContainerFile{
+                               {
+                                       HostFilePath:      
"./testdata/pki/.keystore",
+                                       ContainerFilePath: "testdata/.keystore",
+                                       FileMode:          0o777,
+                               },
+                               {
+                                       HostFilePath:      
"./testdata/pki/.truststore",
+                                       ContainerFilePath: 
"testdata/.truststore",
+                                       FileMode:          0o777,
+                               },
+                               {
+                                       HostFilePath:      
"update_container_cass_config.sh",
+                                       ContainerFilePath: 
"/update_container_cass_config.sh",
+                                       FileMode:          0o777,
+                               },
+                       },
+
+                       Networks: []string{"cassandra"},
+                       LifecycleHooks: 
[]testcontainers.ContainerLifecycleHooks{{
+                               PostStarts: []testcontainers.ContainerHook{
+                                       func(ctx context.Context, c 
testcontainers.Container) error {
+                                               // wait for cassandra 
config.yaml to initialize
+                                               time.Sleep(100 * 
time.Millisecond)
+
+                                               code, _, err := c.Exec(ctx, 
[]string{"bash", "./update_container_cass_config.sh"})
+                                               if err != nil {
+                                                       return err
+                                               }
+                                               if code != 0 {
+                                                       return 
fmt.Errorf("script ./update_container_cass_config.sh exited with code %d", code)
+                                               }
+                                               return nil
+                                       },
+                               },
+                       }},

Review Comment:
   Thanks for your feedback, I'm a total newbie in Cassandra and you better 
than me know how ti start it 😊 In the current Cassandra module we do this: 
https://github.com/testcontainers/testcontainers-go/blob/main/modules/cassandra/cassandra.go#L97,
 although looking at this PR, it seems it's creating a rock-solid 
implementation for cassandra. Would you like to, at some point, contribute to 
the module? 🙏 Then the entire community would benefit from your changes. Of 
course, only if you want to.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to