-
-
Notifications
You must be signed in to change notification settings - Fork 500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add Cassandra module #1726
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
docs/modules/postgres.md
Outdated
@@ -51,7 +51,7 @@ If you need to set a different database, and its credentials, you can use the `W | |||
|
|||
#### Init Scripts | |||
|
|||
If you would like to do additional initialization in the Postgres container, add one or more `*.sql`, `*.sql.gz`, or `*.sh` scripts to the container request with the `WithInitScript` function. | |||
If you would like to do additional initialization in the Postgres container, add one or more `*.sql`, `*.sql.gz`, or `*.sh` scripts to the container request with the `WithInitScripts` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I saw typo in postgres readme, I wanted to fix this typo in this pr also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do it in another PR as it is outside the current scope.
for _, script := range scripts { | ||
cf := testcontainers.ContainerFile{ | ||
HostFilePath: script, | ||
ContainerFilePath: "/" + filepath.Base(script), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cassandra docker image does not support /docker-entrypoint-initdb.d/
so I put script files in root directory and in line 105 they will be executed via cqlsh
or sh
command by file extension. Is this a valid solution? What do you think?
docs/modules/postgres.md
Outdated
@@ -51,7 +51,7 @@ If you need to set a different database, and its credentials, you can use the `W | |||
|
|||
#### Init Scripts | |||
|
|||
If you would like to do additional initialization in the Postgres container, add one or more `*.sql`, `*.sql.gz`, or `*.sh` scripts to the container request with the `WithInitScript` function. | |||
If you would like to do additional initialization in the Postgres container, add one or more `*.sql`, `*.sql.gz`, or `*.sh` scripts to the container request with the `WithInitScripts` function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do it in another PR as it is outside the current scope.
"path/filepath" | ||
"strings" | ||
|
||
"github.com/docker/go-connections/nat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gci shall require a new line here.
Which IDE are you using ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im using vscode but also i checked in GoLand, it did not do anything or warn about it. But I added new line manually. Thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdelapenya , shall an issue be created ? This is the second module where the linting is not applied.
@anilsenay , Is golangci-lint installed on your machine ?
In vscode, are you using the workspace configuration from here ?
In your settings, do you have this:
"go.lintTool": "golangci-lint"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could run golangci-lint when a module is generated, but instead of using the binary (see Makefile) calling the right Docker image to avoid having to install it on every developer's machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not every machine has docker, on windows for exemple, it's not installed by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but installing docker is easier than installing a binary for linting. In any case, I'm biased from my past experience in a release engineering team, where we dockerised everything to run smoothly on the CI 😅
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/gocql/gocql" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shall be a new line here too
Also revert typo fix in postgres document while its not scope of this pr
…s-go into cassandra-module
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job with the new module! Thanks for contributing it!
I left a few comments, the most important for me is the one leveraging the container lifecycle hooks using startup commands.
Other than than, feels look good to me. Once we address them, I think it will be ready to be merged
Thanks!
package cassandra | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type initScript struct { | ||
File string | ||
} | ||
|
||
func (i initScript) AsCommand() []string { | ||
if strings.HasSuffix(i.File, ".cql") { | ||
return []string{"cqlsh", "-f", i.File} | ||
} else if strings.HasSuffix(i.File, ".sh") { | ||
return []string{"/bin/sh", i.File} | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdelapenya hey, can you review this again? I add this to the separated file as "executable" but I need help with the naming convention because there is no example except rabbitmq/types_test.go. I think we should decide on good naming for both file names and structs for this executable usage for the sake of example to other modules
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think initScript
, not exported, is fine. I thought about the following names:
cassandraCommand
: no because it includes the package namespace, and no again because calling the .AsCommand() method will come with duplication.script
: no because it's very simpleexecutable
: no because it's very abstractinitScript
: in the context of Cassandra, I think this is the one that makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename the executable.go file, and once there. we are good to go.
In any case, LGTM!
package cassandra | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type initScript struct { | ||
File string | ||
} | ||
|
||
func (i initScript) AsCommand() []string { | ||
if strings.HasSuffix(i.File, ".cql") { | ||
return []string{"cqlsh", "-f", i.File} | ||
} else if strings.HasSuffix(i.File, ".sh") { | ||
return []string{"/bin/sh", i.File} | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think initScript
, not exported, is fine. I thought about the following names:
cassandraCommand
: no because it includes the package namespace, and no again because calling the .AsCommand() method will come with duplication.script
: no because it's very simpleexecutable
: no because it's very abstractinitScript
: in the context of Cassandra, I think this is the one that makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I took the license to fix a typo in a comment to not load you again with more rework.
Thanks again for your had work here! Much appreciated! 💪
Merging, as last commit is a change in a comment. |
* main: docs: Fix typo and mention the relevant function name in doc (testcontainers#1745) DOCKER_HOST var typo (testcontainers#1743) feat: Add Cassandra module (testcontainers#1726) K6 module (testcontainers#1721) Rancher Desktop instructions (testcontainers#1724) chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.8 to 3.23.9 (testcontainers#1720) chore(deps): bump urllib3 from 2.0.5 to 2.0.6 (testcontainers#1718) chore(deps): bump github.com/twmb/franz-go/pkg/kadm in /modules/redpanda (testcontainers#1714) chore(deps): bump github.com/couchbase/gocb/v2 in /modules/couchbase (testcontainers#1704) chore(deps): bump github.com/neo4j/neo4j-go-driver/v5 in /modules/neo4j (testcontainers#1713)
* main: (137 commits) Fix wrong module names (testcontainers#1776) docs: add default options to k6 module (testcontainers#1744) fix race condition in Test_StartStop (testcontainers#1700) chore(deps): bump github.com/aws/aws-sdk-go-v2/{service/s3,credentials,config} in /modules/localstack (testcontainers#1773) chore(deps): bump cloud.google.com/go/{datastore,bigtable,spanner} in /modules/gcloud (testcontainers#1774) chore(deps): bump golang.org/x/net from 0.15.0 to 0.17.0 (testcontainers#1772) docs: Fix typo and mention the relevant function name in doc (testcontainers#1745) DOCKER_HOST var typo (testcontainers#1743) feat: Add Cassandra module (testcontainers#1726) K6 module (testcontainers#1721) Rancher Desktop instructions (testcontainers#1724) chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.8 to 3.23.9 (testcontainers#1720) chore(deps): bump urllib3 from 2.0.5 to 2.0.6 (testcontainers#1718) chore(deps): bump github.com/twmb/franz-go/pkg/kadm in /modules/redpanda (testcontainers#1714) chore(deps): bump github.com/couchbase/gocb/v2 in /modules/couchbase (testcontainers#1704) chore(deps): bump github.com/neo4j/neo4j-go-driver/v5 in /modules/neo4j (testcontainers#1713) chore(deps): bump github.com/nats-io/nats.go in /modules/nats (testcontainers#1705) chore(deps): bump cloud.google.com/go/firestore from 1.12.0 to 1.13.0, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/ge, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/go/bigquery from 1.53.0 to 1.55 in /modules/gcloud (testcontainers#1716) chore(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.39.0 to 1.40.0 and github.com/aws/aws-sdk-go from 1.45.15 to 1.45.19 in /modules/localstack (testcontainers#1717) chore: prepare for next minor development cycle (0.26.0) ...
* main: (137 commits) Fix wrong module names (testcontainers#1776) docs: add default options to k6 module (testcontainers#1744) fix race condition in Test_StartStop (testcontainers#1700) chore(deps): bump github.com/aws/aws-sdk-go-v2/{service/s3,credentials,config} in /modules/localstack (testcontainers#1773) chore(deps): bump cloud.google.com/go/{datastore,bigtable,spanner} in /modules/gcloud (testcontainers#1774) chore(deps): bump golang.org/x/net from 0.15.0 to 0.17.0 (testcontainers#1772) docs: Fix typo and mention the relevant function name in doc (testcontainers#1745) DOCKER_HOST var typo (testcontainers#1743) feat: Add Cassandra module (testcontainers#1726) K6 module (testcontainers#1721) Rancher Desktop instructions (testcontainers#1724) chore(deps): bump github.com/shirou/gopsutil/v3 from 3.23.8 to 3.23.9 (testcontainers#1720) chore(deps): bump urllib3 from 2.0.5 to 2.0.6 (testcontainers#1718) chore(deps): bump github.com/twmb/franz-go/pkg/kadm in /modules/redpanda (testcontainers#1714) chore(deps): bump github.com/couchbase/gocb/v2 in /modules/couchbase (testcontainers#1704) chore(deps): bump github.com/neo4j/neo4j-go-driver/v5 in /modules/neo4j (testcontainers#1713) chore(deps): bump github.com/nats-io/nats.go in /modules/nats (testcontainers#1705) chore(deps): bump cloud.google.com/go/firestore from 1.12.0 to 1.13.0, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/ge, google.golang.org/api from 0.142.0 to 0.143.0 and cloud.google.com/go/bigquery from 1.53.0 to 1.55 in /modules/gcloud (testcontainers#1716) chore(deps): bump github.com/aws/aws-sdk-go-v2/service/s3 from 1.39.0 to 1.40.0 and github.com/aws/aws-sdk-go from 1.45.15 to 1.45.19 in /modules/localstack (testcontainers#1717) chore: prepare for next minor development cycle (0.26.0) ...
What does this PR do?
This PR adds Cassandra module for go-testcontainers
Why is it important?
It is important as part of a task of #636 to support Cassandra modules too.
Related issues
Follow-ups
Cassandra docker image does not provide a configuration from environment variables for authentication. It allows all connections by default without auth. To enable authentication and set a user, you should provide it in config yaml file or it may be ran by
cqlsh
command in container to execute query as an alternative. As a follow-up improvement, authentication options could be added somehow.