Skip to content

Commit

Permalink
Tweaks for k6 documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
javaducky committed Feb 15, 2024
1 parent 718d7f6 commit c19c2e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
20 changes: 6 additions & 14 deletions docs/modules/k6.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ Using this module, you can execute k6 test scripts, optionally building a custom

## Basic script execution

Create a simple k6 test script to be executed as part of your tests:
Execute a simple k6 test script, `test.js`, with commandline options and injected script variable.

<!--codeinclude-->
[Create a basic test script](../../modules/k6/src/test/resources/scripts/test.js) inside_block:access_script_vars
<!--/codeinclude-->

Execute the script with desired options and script variables:
Create a simple k6 test script to be executed as part of your tests:

<!--codeinclude-->
[Run the test script](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:standard_k6
[Setup the container](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:standard_k6
[Content of `scripts/test.js`](../../modules/k6/src/test/resources/scripts/test.js) inside_block:access_script_vars
<!--/codeinclude-->

## Customizing k6 using extensions
Expand All @@ -31,13 +28,8 @@ Using the extended k6 image enables scripts to reference extension libraries whi
Many available extensions as well as the [builder image](https://github.com/szkiba/k6x) are provided by third parties and may not be supported directly by Grafana Labs.

<!--codeinclude-->
[Create a script using extensions](../../modules/k6/src/test/resources/scripts/extensions.js) inside_block:extensions_script
<!--/codeinclude-->

Execute using the [k6 builder image](https://github.com/szkiba/k6x) to dynamically incorporate k6 extensions and run the script:

<!--codeinclude-->
[Run the test script with extensions](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:extended_k6
[Setup the container](../../modules/k6/src/test/java/org/testcontainers/k6/K6ContainerTests.java) inside_block:extended_k6
[Content of `scripts/extensions.js`](../../modules/k6/src/test/resources/scripts/extensions.js) inside_block:extensions_script
<!--/codeinclude-->

## Adding this module to your project dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@

public class K6ContainerTests {

private final String INJECT_SCRIPT_VAR = "are cool!";

@Test
public void k6StandardTest() throws Exception {
try (
// standard_k6 {
K6Container container =
new K6Container()
.withTestScript("scripts/test.js")
.withScriptVar("MY_SCRIPT_VAR", INJECT_SCRIPT_VAR)
.withScriptVar("MY_SCRIPT_VAR", "are cool!")
.withScriptVar("AN_UNUSED_VAR", "unused")
.withCmdOptions("--quiet", "--no-usage-report")
// }
) {
Expand All @@ -31,7 +30,7 @@ public void k6StandardTest() throws Exception {
consumer.waitUntil(frame ->
frame.getUtf8String().contains("iteration_duration"), 3, TimeUnit.SECONDS);

assertThat(container.getLogs()).contains("k6 tests " + INJECT_SCRIPT_VAR);
assertThat(container.getLogs()).contains("k6 tests are cool!");
}
}

Expand Down

0 comments on commit c19c2e5

Please sign in to comment.