-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into log_producer_race
- Loading branch information
Showing
79 changed files
with
1,626 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Cassandra | ||
|
||
Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
## Introduction | ||
|
||
The Testcontainers module for Cassandra. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the Cassandra module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/cassandra | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a Cassandra container](../../modules/cassandra/examples_test.go) inside_block:runCassandraContainer | ||
<!--/codeinclude--> | ||
|
||
## Module reference | ||
|
||
The Cassandra module exposes one entrypoint function to create the Cassandra container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the Cassandra container, you can pass options in a variadic way to configure it. | ||
|
||
#### Image | ||
|
||
If you need to set a different Cassandra Docker image, you can use `testcontainers.WithImage` with a valid Docker image | ||
for Cassandra. E.g. `testcontainers.WithImage("cassandra:4.1.3")`. | ||
|
||
{% include "../features/common_functional_options.md" %} | ||
|
||
#### Init Scripts | ||
|
||
If you would like to do additional initialization in the Cassandra container, add one or more `*.cql` or `*.sh` scripts to the container request with the `WithInitScripts` function. | ||
Those files will be copied after the container is created but before it's started under root directory. | ||
An example of a `*.sh` script that creates a keyspace and table is shown below: | ||
<!--codeinclude--> | ||
[Init script content](../../modules/cassandra/testdata/init.sh) | ||
<!--/codeinclude--> | ||
#### Database configuration | ||
In the case you have a custom config file for Cassandra, it's possible to copy that file into the container before it's started, using the `WithConfigFile(cfgPath string)` function. | ||
!!!warning | ||
You should provide a valid Cassandra configuration file, otherwise the container will fail to start. | ||
### Container Methods | ||
The Cassandra container exposes the following methods: | ||
#### ConnectionHost | ||
This method returns the host and port of the Cassandra container, using the default, `9042/tcp` port. E.g. `localhost:9042` | ||
<!--codeinclude--> | ||
[Get connection host](../../modules/cassandra/cassandra_test.go) inside_block:connectionHost | ||
<!--/codeinclude--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# K6 | ||
|
||
Not available until the next release of testcontainers-go <a href="https://github.com/testcontainers/testcontainers-go"><span class="tc-version">:material-tag: main</span></a> | ||
|
||
## Introduction | ||
|
||
The Testcontainers module for K6. | ||
|
||
|
||
### Using k6 extensions | ||
|
||
This module takes advantage of [k6x](https://github.com/szkiba/k6x) to dynamically build a `k6` binary with all the [k6 extensions](https://k6.io/docs/extensions/get-started/explore/) required by the test script. | ||
|
||
## Adding this module to your project dependencies | ||
|
||
Please run the following command to add the K6 module to your Go dependencies: | ||
|
||
``` | ||
go get github.com/testcontainers/testcontainers-go/modules/k6 | ||
``` | ||
|
||
## Usage example | ||
|
||
<!--codeinclude--> | ||
[Creating a K6 container](../../modules/k6/examples_test.go) inside_block:runK6Container | ||
<!--/codeinclude--> | ||
|
||
## Module reference | ||
|
||
The K6 module exposes one entrypoint function to run the K6 container, and this function receives two parameters: | ||
|
||
```golang | ||
func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) | ||
``` | ||
|
||
- `context.Context`, the Go context. | ||
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options. | ||
|
||
### Container Options | ||
|
||
When starting the K6 container, you can pass options in a variadic way to configure it. | ||
|
||
#### SetEnvVar | ||
|
||
`SetEnvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script using the '--env' command-line flag in the k6 command in the container. | ||
|
||
```golang | ||
k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) | ||
``` | ||
|
||
#### WithCache | ||
|
||
Use `WithCache` passes a volume to be used as a [cache for building the k6 binary](https://github.com/szkiba/k6x#cache) inside the `k6` container. | ||
This option improves considerably the execution time of test suites that creates multiple `k6` test containers. | ||
If the volume does not exits, it is created. The test is responsible for cleaning up this volume when no longer needed. | ||
|
||
|
||
```golang | ||
k6.RunContainer(ctx, WithCache("cache"), k6.WithTestScript("/tests/test.js")) | ||
``` | ||
|
||
#### WithCmdOptions | ||
|
||
Use `WithCmdOptions` to pass a variadic list of strings as [options](https://k6.io/docs/using-k6/k6-options/reference/) to the k6 run command | ||
|
||
```golang | ||
k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) | ||
``` | ||
|
||
#### WithTestScript | ||
|
||
Use the `WithTestScript` option to specify the test script to run. The path to the script must be an absolute path. This option copies the script file to the container and pass it to k6's `run` command. At least one `WithTestScript` option must be specified. | ||
|
||
```golang | ||
k6.RunContainer(ctx, k6.WithTestScript("/tests/test.js")) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Using Rancher Desktop | ||
|
||
It is possible to use Rancher Desktop to satisfy the system requirements instead of Docker. | ||
|
||
**IMPORTANT**: Please ensure you are running an up-to-date version of Rancher Desktop. There were some key fixes made in earlier versions (especially around v1.6). It is highly unlikely you will be able to get Rancher Desktop working with testcontainers if you are on an old version. | ||
|
||
The instructions below are written on the assumption that: | ||
|
||
1. you wish to run Rancher Desktop without administrative permissions (i.e. without granting `sudo` access a.k.a *"Administrative Access"* setting tickbox in Rancher Desktop is *unticked*). | ||
2. you are running Rancher Desktop on an Apple-silicon device a.k.a M-series processor. | ||
|
||
Steps are as follows: | ||
|
||
1. In Rancher Desktop change engine from `containerd` to `dockerd (moby)`. | ||
2. In Rancher Desktop set `VZ mode` networking. | ||
3. On macOS CLI (e.g. `Terminal` app), set the following environment variables: | ||
|
||
```sh | ||
export DOCKER_HOST=unix://$HOME/.rd/docker.sock | ||
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock | ||
export TESTCONTAINERS_HOST_OVERRIDE=$(rdctl shell ip a show vznat | awk '/inet / {sub("/.*",""); print $2}') | ||
``` | ||
|
||
As always, remember that environment variables are not persisted unless you add them to the relevant file for your default shell e.g. `~/.zshrc`. | ||
|
||
Credit: Thank you to @pdrosos on GitHub. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.