Skip to content

docs: add default options to k6 module #1744

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

Merged
merged 6 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion docs/modules/k6.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Not available until the next release of testcontainers-go <a href="https://githu

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.
Expand All @@ -22,6 +21,9 @@ go get github.com/testcontainers/testcontainers-go/modules/k6
## Usage example

<!--codeinclude-->
[Creating a httpbin application](../../modules/k6/examples_test.go) inside_block:runHTTPBin
[Obtain IP for the httpbin application](../../modules/k6/examples_test.go) inside_block:getHTTPBinIP
[httpbin script](../../modules/k6/scripts/httpbin.js)
[Creating a K6 container](../../modules/k6/examples_test.go) inside_block:runK6Container
<!--/codeinclude-->

Expand All @@ -40,6 +42,13 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize

When starting the K6 container, you can pass options in a variadic way to configure it.

#### Image

If you need to set a different K6 Docker image, you can use `testcontainers.WithImage` with a valid Docker image
for Cassandra. E.g. `testcontainers.WithImage("szkiba/k6x:v0.3.1")`.

{% include "../features/common_functional_options.md" %}

#### 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.
Expand Down Expand Up @@ -74,3 +83,7 @@ Use the `WithTestScript` option to specify the test script to run. The path to t
```golang
k6.RunContainer(ctx, k6.WithTestScript("/tests/test.js"))
```

### Container Methods

The K6 container does not expose any method.
6 changes: 5 additions & 1 deletion modules/k6/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func ExampleRunContainer() {
// runK6Container {
// runHTTPBin {
ctx := context.Background()

// create a container with the httpbin application that will be the target
Expand All @@ -37,17 +37,21 @@ func ExampleRunContainer() {
panic(fmt.Errorf("failed to terminate container: %w", err))
}
}()
// }

// getHTTPBinIP {
httpbinIP, err := httpbin.ContainerIP(ctx)
if err != nil {
panic(fmt.Errorf("failed to get httpbin IP: %w", err))
}
// }

absPath, err := filepath.Abs(filepath.Join("scripts", "httpbin.js"))
if err != nil {
panic(fmt.Errorf("failed to get path to test script: %w", err))
}

// runK6Container {
// run the httpbin.js test scripts passing the IP address the httpbin container
k6, err := k6.RunContainer(
ctx,
Expand Down