Skip to content

[Enhancement]: Add example test to the K6 module docs #8780

Open
@FieteO

Description

@FieteO

Module

K6

Proposal

I am currently trying to setup a k6 integration test and have a hard time figuring out, how tests are supposed to be written with the module.
When googling for solutions, I primarily found an example repository for go and the docs page.
I then looked at the code and found the test case that is provided for the feature:

public class K6ContainerTests {

    @Test
    public void k6StandardTest() throws Exception {
        try (
            // standard_k6 {
            K6Container container = new K6Container("grafana/k6:0.49.0")
                .withTestScript(MountableFile.forClasspathResource("scripts/test.js"))
                .withScriptVar("MY_SCRIPT_VAR", "are cool!")
                .withScriptVar("AN_UNUSED_VAR", "unused")
                .withCmdOptions("--quiet", "--no-usage-report")
            // }
        ) {
            container.start();

            WaitingConsumer consumer = new WaitingConsumer();
            container.followOutput(consumer);

            // Wait for test script results to be collected
            consumer.waitUntil(
                frame -> {
                    return frame.getUtf8String().contains("iteration_duration");
                },
                3,
                TimeUnit.SECONDS
            );

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

The docs page however, is not stating how a test case would look like and the provided test case does not look like the typical syntax I am used to from testcontainers. I would have expected something similar to the quick start examples to get started quickly.
Either way, I think it would be a good idea to provide an example test in the docs.

(@javaducky @eddumelendez I think you were involved in contributing the module)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions