From 130d68537b79fe6086ad54adf85b38136ce648b8 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Tue, 3 Oct 2023 16:58:59 +0200 Subject: [PATCH 01/18] Add modulegen generated code for k6 module Signed-off-by: Pablo Chacin --- .github/dependabot.yml | 7 + .github/workflows/ci.yml | 4 +- .vscode/.testcontainers-go.code-workspace | 8 + docs/examples/k6.md | 47 ++++++ docs/modules/k6.md | 47 ++++++ examples/k6/Makefile | 5 + examples/k6/examples_test.go | 37 +++++ examples/k6/go.mod | 7 + examples/k6/k6.go | 35 ++++ examples/k6/k6_test.go | 26 +++ mkdocs.yml | 1 + modules/k6/Makefile | 5 + modules/k6/examples_test.go | 37 +++++ modules/k6/go.mod | 51 ++++++ modules/k6/go.sum | 189 ++++++++++++++++++++++ modules/k6/k6.go | 35 ++++ modules/k6/k6_test.go | 26 +++ sonar-project.properties | 2 +- 18 files changed, 566 insertions(+), 3 deletions(-) create mode 100644 docs/examples/k6.md create mode 100644 docs/modules/k6.md create mode 100644 examples/k6/Makefile create mode 100644 examples/k6/examples_test.go create mode 100644 examples/k6/go.mod create mode 100644 examples/k6/k6.go create mode 100644 examples/k6/k6_test.go create mode 100644 modules/k6/Makefile create mode 100644 modules/k6/examples_test.go create mode 100644 modules/k6/go.mod create mode 100644 modules/k6/go.sum create mode 100644 modules/k6/k6.go create mode 100644 modules/k6/k6_test.go diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 9791fe56e0..cd763d7d6d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -107,6 +107,13 @@ updates: day: sunday open-pull-requests-limit: 3 rebase-strategy: disabled + - package-ecosystem: gomod + directory: /modules/k6 + schedule: + interval: monthly + day: sunday + open-pull-requests-limit: 3 + rebase-strategy: disabled - package-ecosystem: gomod directory: /modules/kafka schedule: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7b6f69b2ad..e8d2cbff3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,7 +106,7 @@ jobs: matrix: go-version: [1.20.x, 1.x] platform: [ubuntu-latest, macos-latest] - module: [artemis, clickhouse, compose, couchbase, elasticsearch, gcloud, k3s, kafka, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, rabbitmq, redis, redpanda, vault] + module: [artemis, clickhouse, compose, couchbase, elasticsearch, gcloud, k3s, k6, kafka, localstack, mariadb, mongodb, mysql, nats, neo4j, postgres, pulsar, rabbitmq, redis, redpanda, vault] uses: ./.github/workflows/ci-test-go.yml with: go-version: ${{ matrix.go-version }} @@ -123,7 +123,7 @@ jobs: needs: test-modules strategy: matrix: - module: [cockroachdb, consul, nginx, toxiproxy] + module: [cockroachdb, consul, k6, nginx, toxiproxy] uses: ./.github/workflows/ci-test-go.yml with: go-version: "1.20.x" diff --git a/.vscode/.testcontainers-go.code-workspace b/.vscode/.testcontainers-go.code-workspace index 16c84286cd..e2fc5c0ada 100644 --- a/.vscode/.testcontainers-go.code-workspace +++ b/.vscode/.testcontainers-go.code-workspace @@ -13,6 +13,10 @@ "name": "example / consul", "path": "../examples/consul" }, + { + "name": "example / k6", + "path": "../examples/k6" + }, { "name": "example / nginx", "path": "../examples/nginx" @@ -49,6 +53,10 @@ "name": "module / k3s", "path": "../modules/k3s" }, + { + "name": "module / k6", + "path": "../modules/k6" + }, { "name": "module / kafka", "path": "../modules/kafka" diff --git a/docs/examples/k6.md b/docs/examples/k6.md new file mode 100644 index 0000000000..94b9804ab3 --- /dev/null +++ b/docs/examples/k6.md @@ -0,0 +1,47 @@ +# k6 + +Not available until the next release of testcontainers-go :material-tag: main + +## Introduction + +The Testcontainers module for k6. + +## 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/examples/k6 +``` + +## Usage example + + +[Creating a k6 container](../../examples/k6/examples_test.go) inside_block:runk6Container + + +## Module reference + +The k6 module exposes one entrypoint function to create 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. + +#### Image + +If you need to set a different k6 Docker image, you can use `testcontainers.WithImage` with a valid Docker image +for k6. E.g. `testcontainers.WithImage("grafana/k6")`. + +{% include "../features/common_functional_options.md" %} + +### Container Methods + +The k6 container exposes the following methods: diff --git a/docs/modules/k6.md b/docs/modules/k6.md new file mode 100644 index 0000000000..f5d61c9c70 --- /dev/null +++ b/docs/modules/k6.md @@ -0,0 +1,47 @@ +# K6 + +Not available until the next release of testcontainers-go :material-tag: main + +## Introduction + +The Testcontainers module for K6. + +## 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 + + +[Creating a K6 container](../../modules/k6/examples_test.go) inside_block:runK6Container + + +## Module reference + +The K6 module exposes one entrypoint function to create 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. + +#### Image + +If you need to set a different K6 Docker image, you can use `testcontainers.WithImage` with a valid Docker image +for K6. E.g. `testcontainers.WithImage("szkiba/k6x")`. + +{% include "../features/common_functional_options.md" %} + +### Container Methods + +The K6 container exposes the following methods: diff --git a/examples/k6/Makefile b/examples/k6/Makefile new file mode 100644 index 0000000000..30ab524295 --- /dev/null +++ b/examples/k6/Makefile @@ -0,0 +1,5 @@ +include ../../commons-test.mk + +.PHONY: test +test: + $(MAKE) test-k6 diff --git a/examples/k6/examples_test.go b/examples/k6/examples_test.go new file mode 100644 index 0000000000..9d24f60be6 --- /dev/null +++ b/examples/k6/examples_test.go @@ -0,0 +1,37 @@ +package k6_test + +import ( + "context" + "fmt" + + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/k6" +) + +func ExamplerunContainer() { + // runk6Container { + ctx := context.Background() + + k6Container, err := k6.runContainer(ctx, testcontainers.WithImage("grafana/k6")) + if err != nil { + panic(err) + } + + // Clean up the container + defer func() { + if err := k6Container.Terminate(ctx); err != nil { + panic(err) + } + }() + // } + + state, err := k6Container.State(ctx) + if err != nil { + panic(err) + } + + fmt.Println(state.Running) + + // Output: + // true +} diff --git a/examples/k6/go.mod b/examples/k6/go.mod new file mode 100644 index 0000000000..089135ef10 --- /dev/null +++ b/examples/k6/go.mod @@ -0,0 +1,7 @@ +module github.com/testcontainers/testcontainers-go/examples/k6 + +go 1.20 + +require github.com/testcontainers/testcontainers-go v0.24.1 + +replace github.com/testcontainers/testcontainers-go => ../.. diff --git a/examples/k6/k6.go b/examples/k6/k6.go new file mode 100644 index 0000000000..03fb7b30d5 --- /dev/null +++ b/examples/k6/k6.go @@ -0,0 +1,35 @@ +package k6 + +import ( + "context" + + "github.com/testcontainers/testcontainers-go" +) + +// k6Container represents the k6 container type used in the module +type k6Container struct { + testcontainers.Container +} + +// runContainer creates an instance of the k6 container type +func runContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*k6Container, error) { + req := testcontainers.ContainerRequest{ + Image: "grafana/k6", + } + + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + } + + for _, opt := range opts { + opt.Customize(&genericContainerReq) + } + + container, err := testcontainers.GenericContainer(ctx, genericContainerReq) + if err != nil { + return nil, err + } + + return &k6Container{Container: container}, nil +} diff --git a/examples/k6/k6_test.go b/examples/k6/k6_test.go new file mode 100644 index 0000000000..9fbfb30b3e --- /dev/null +++ b/examples/k6/k6_test.go @@ -0,0 +1,26 @@ +package k6 + +import ( + "context" + "testing" + + "github.com/testcontainers/testcontainers-go" +) + +func Testk6(t *testing.T) { + ctx := context.Background() + + container, err := runContainer(ctx, testcontainers.WithImage("grafana/k6")) + if err != nil { + t.Fatal(err) + } + + // Clean up the container after the test is complete + t.Cleanup(func() { + if err := container.Terminate(ctx); err != nil { + t.Fatalf("failed to terminate container: %s", err) + } + }) + + // perform assertions +} diff --git a/mkdocs.yml b/mkdocs.yml index 08977466aa..df56c61db9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -69,6 +69,7 @@ nav: - modules/elasticsearch.md - modules/gcloud.md - modules/k3s.md + - modules/k6.md - modules/kafka.md - modules/localstack.md - modules/mariadb.md diff --git a/modules/k6/Makefile b/modules/k6/Makefile new file mode 100644 index 0000000000..30ab524295 --- /dev/null +++ b/modules/k6/Makefile @@ -0,0 +1,5 @@ +include ../../commons-test.mk + +.PHONY: test +test: + $(MAKE) test-k6 diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go new file mode 100644 index 0000000000..249500e2fe --- /dev/null +++ b/modules/k6/examples_test.go @@ -0,0 +1,37 @@ +package k6_test + +import ( + "context" + "fmt" + + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/modules/k6" +) + +func ExampleRunContainer() { + // runK6Container { + ctx := context.Background() + + k6Container, err := k6.RunContainer(ctx, testcontainers.WithImage("szkiba/k6x")) + if err != nil { + panic(err) + } + + // Clean up the container + defer func() { + if err := k6Container.Terminate(ctx); err != nil { + panic(err) + } + }() + // } + + state, err := k6Container.State(ctx) + if err != nil { + panic(err) + } + + fmt.Println(state.Running) + + // Output: + // true +} diff --git a/modules/k6/go.mod b/modules/k6/go.mod new file mode 100644 index 0000000000..611fdfb7a5 --- /dev/null +++ b/modules/k6/go.mod @@ -0,0 +1,51 @@ +module github.com/testcontainers/testcontainers-go/modules/k6 + +go 1.20 + +require github.com/testcontainers/testcontainers-go v0.25.0 + +require ( + dario.cat/mergo v1.0.0 // indirect + github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect + github.com/Microsoft/go-winio v0.6.1 // indirect + github.com/Microsoft/hcsshim v0.11.0 // indirect + github.com/cenkalti/backoff/v4 v4.2.1 // indirect + github.com/containerd/containerd v1.7.6 // indirect + github.com/cpuguy83/dockercfg v0.3.1 // indirect + github.com/docker/distribution v2.8.2+incompatible // indirect + github.com/docker/docker v24.0.6+incompatible // indirect + github.com/docker/go-connections v0.4.0 // indirect + github.com/docker/go-units v0.5.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/protobuf v1.5.3 // indirect + github.com/google/uuid v1.3.1 // indirect + github.com/klauspost/compress v1.16.0 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/magiconair/properties v1.8.7 // indirect + github.com/moby/patternmatcher v0.5.0 // indirect + github.com/moby/sys/sequential v0.5.0 // indirect + github.com/moby/term v0.5.0 // indirect + github.com/morikuni/aec v1.0.0 // indirect + github.com/opencontainers/go-digest v1.0.0 // indirect + github.com/opencontainers/image-spec v1.1.0-rc4 // indirect + github.com/opencontainers/runc v1.1.5 // indirect + github.com/pkg/errors v0.9.1 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect + github.com/shirou/gopsutil/v3 v3.23.9 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/sirupsen/logrus v1.9.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect + golang.org/x/mod v0.9.0 // indirect + golang.org/x/net v0.15.0 // indirect + golang.org/x/sys v0.12.0 // indirect + golang.org/x/tools v0.7.0 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect + google.golang.org/grpc v1.57.0 // indirect + google.golang.org/protobuf v1.30.0 // indirect +) + +replace github.com/testcontainers/testcontainers-go => ../.. diff --git a/modules/k6/go.sum b/modules/k6/go.sum new file mode 100644 index 0000000000..d650278552 --- /dev/null +++ b/modules/k6/go.sum @@ -0,0 +1,189 @@ +dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= +dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 h1:UQHMgLO+TxOElx5B5HZ4hJQsoJ/PvUvKRhJHDQXO8P8= +github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow= +github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM= +github.com/Microsoft/hcsshim v0.11.0 h1:7EFNIY4igHEXUdj1zXgAyU3fLc7QfOKHbkldRVTBdiM= +github.com/Microsoft/hcsshim v0.11.0/go.mod h1:OEthFdQv/AD2RAdzR6Mm1N1KPCztGKDurW1Z8b8VGMM= +github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM= +github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= +github.com/checkpoint-restore/go-criu/v5 v5.3.0/go.mod h1:E/eQpaFtUKGOOSEBZgmKAcn+zUUwWxqcaKZlF54wK8E= +github.com/cilium/ebpf v0.7.0/go.mod h1:/oI2+1shJiTGAMgl6/RgJr36Eo1jzrRcAWbcXO2usCA= +github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= +github.com/containerd/containerd v1.7.6 h1:oNAVsnhPoy4BTPQivLgTzI9Oleml9l/+eYIDYXRCYo8= +github.com/containerd/containerd v1.7.6/go.mod h1:SY6lrkkuJT40BVNO37tlYTSnKJnP5AXBc0fhx0q+TJ4= +github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoYe9E= +github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc= +github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= +github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= +github.com/cyphar/filepath-securejoin v0.2.3/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/docker/distribution v2.8.2+incompatible h1:T3de5rq0dB1j30rp0sA2rER+m322EBzniBPB6ZIzuh8= +github.com/docker/distribution v2.8.2+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= +github.com/docker/docker v24.0.6+incompatible h1:hceabKCtUgDqPu+qm0NgsaXf28Ljf4/pWFL7xjWWDgE= +github.com/docker/docker v24.0.6+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ= +github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec= +github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= +github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= +github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= +github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4= +github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= +github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= +github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= +github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M7DBo= +github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc= +github.com/moby/sys/mountinfo v0.5.0/go.mod h1:3bMD3Rg+zkqx8MRYPi7Pyb0Ie97QEBmdxbhnCLlSvSU= +github.com/moby/sys/sequential v0.5.0 h1:OPvI35Lzn9K04PBbCLW0g4LcFAJgHsvXsRyewg5lXtc= +github.com/moby/sys/sequential v0.5.0/go.mod h1:tH2cOOs5V9MlPiXcQzRC+eEyab644PWKGRYaaV5ZZlo= +github.com/moby/term v0.5.0 h1:xt8Q1nalod/v7BqbG21f8mQPqH+xAaC9C3N3wfWbVP0= +github.com/moby/term v0.5.0/go.mod h1:8FzsFHVUBGZdbDsJw/ot+X+d5HLUbvklYLJ9uGfcI3Y= +github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= +github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= +github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= +github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= +github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= +github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYBTS5Y4x/Cgeo1E0= +github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8= +github.com/opencontainers/runc v1.1.5 h1:L44KXEpKmfWDcS02aeGm8QNTFXTo2D+8MYGDIJ/GDEs= +github.com/opencontainers/runc v1.1.5/go.mod h1:1J5XiS+vdZ3wCyZybsuxXZWGrgSr8fFJHLXuG2PsnNg= +github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= +github.com/opencontainers/selinux v1.10.0/go.mod h1:2i0OySw99QjzBBQByd1Gr9gSjvuho1lHsJxIJ3gGbJI= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= +github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg= +github.com/shirou/gopsutil/v3 v3.23.9 h1:ZI5bWVeu2ep4/DIxB4U9okeYJ7zp/QLTO4auRb/ty/E= +github.com/shirou/gopsutil/v3 v3.23.9/go.mod h1:x/NWSb71eMcjFIO0vhyGW5nZ7oSIgVjrCnADckb85GA= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= +github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= +github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= +github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE= +github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea h1:vLCWI/yYrdEHyN2JzIzPO3aaQJHQdp89IZBA/+azVC4= +golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs= +golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= +golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191115151921-52ab43148777/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210906170528-6f6e22806c34/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211116061358-0a5406a5449c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4= +golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM= +google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19/go.mod h1:66JfowdXAEgad5O9NnYcsNPLCPZJD++2L9X0PCMODrA= +google.golang.org/grpc v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw= +google.golang.org/grpc v1.57.0/go.mod h1:Sd+9RMTACXwmub0zcNY2c4arhtrbBYD1AUHI/dt16Mo= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng= +google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= diff --git a/modules/k6/k6.go b/modules/k6/k6.go new file mode 100644 index 0000000000..a7eebe46b1 --- /dev/null +++ b/modules/k6/k6.go @@ -0,0 +1,35 @@ +package k6 + +import ( + "context" + + "github.com/testcontainers/testcontainers-go" +) + +// K6Container represents the K6 container type used in the module +type K6Container struct { + testcontainers.Container +} + +// RunContainer creates an instance of the K6 container type +func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { + req := testcontainers.ContainerRequest{ + Image: "szkiba/k6x", + } + + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + } + + for _, opt := range opts { + opt.Customize(&genericContainerReq) + } + + container, err := testcontainers.GenericContainer(ctx, genericContainerReq) + if err != nil { + return nil, err + } + + return &K6Container{Container: container}, nil +} diff --git a/modules/k6/k6_test.go b/modules/k6/k6_test.go new file mode 100644 index 0000000000..aad2209be5 --- /dev/null +++ b/modules/k6/k6_test.go @@ -0,0 +1,26 @@ +package k6 + +import ( + "context" + "testing" + + "github.com/testcontainers/testcontainers-go" +) + +func TestK6(t *testing.T) { + ctx := context.Background() + + container, err := RunContainer(ctx, testcontainers.WithImage("szkiba/k6x")) + if err != nil { + t.Fatal(err) + } + + // Clean up the container after the test is complete + t.Cleanup(func() { + if err := container.Terminate(ctx); err != nil { + t.Fatalf("failed to terminate container: %s", err) + } + }) + + // perform assertions +} diff --git a/sonar-project.properties b/sonar-project.properties index 966b50c730..06663163bd 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -18,4 +18,4 @@ sonar.test.inclusions=**/*_test.go sonar.test.exclusions=**/vendor/** sonar.go.coverage.reportPaths=**/coverage.out -sonar.go.tests.reportPaths=TEST-unit.xml,examples/cockroachdb/TEST-unit.xml,examples/consul/TEST-unit.xml,examples/nginx/TEST-unit.xml,examples/toxiproxy/TEST-unit.xml,modulegen/TEST-unit.xml,modules/artemis/TEST-unit.xml,modules/clickhouse/TEST-unit.xml,modules/compose/TEST-unit.xml,modules/couchbase/TEST-unit.xml,modules/elasticsearch/TEST-unit.xml,modules/gcloud/TEST-unit.xml,modules/k3s/TEST-unit.xml,modules/kafka/TEST-unit.xml,modules/localstack/TEST-unit.xml,modules/mariadb/TEST-unit.xml,modules/mongodb/TEST-unit.xml,modules/mysql/TEST-unit.xml,modules/nats/TEST-unit.xml,modules/neo4j/TEST-unit.xml,modules/postgres/TEST-unit.xml,modules/pulsar/TEST-unit.xml,modules/rabbitmq/TEST-unit.xml,modules/redis/TEST-unit.xml,modules/redpanda/TEST-unit.xml,modules/vault/TEST-unit.xml +sonar.go.tests.reportPaths=TEST-unit.xml,examples/cockroachdb/TEST-unit.xml,examples/consul/TEST-unit.xml,examples/k6/TEST-unit.xml,examples/nginx/TEST-unit.xml,examples/toxiproxy/TEST-unit.xml,modulegen/TEST-unit.xml,modules/artemis/TEST-unit.xml,modules/clickhouse/TEST-unit.xml,modules/compose/TEST-unit.xml,modules/couchbase/TEST-unit.xml,modules/elasticsearch/TEST-unit.xml,modules/gcloud/TEST-unit.xml,modules/k3s/TEST-unit.xml,modules/k6/TEST-unit.xml,modules/kafka/TEST-unit.xml,modules/localstack/TEST-unit.xml,modules/mariadb/TEST-unit.xml,modules/mongodb/TEST-unit.xml,modules/mysql/TEST-unit.xml,modules/nats/TEST-unit.xml,modules/neo4j/TEST-unit.xml,modules/postgres/TEST-unit.xml,modules/pulsar/TEST-unit.xml,modules/rabbitmq/TEST-unit.xml,modules/redis/TEST-unit.xml,modules/redpanda/TEST-unit.xml,modules/vault/TEST-unit.xml From 1e6cc6a26bccc0b71ef0466ebe383e046614e6a4 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Tue, 3 Oct 2023 22:00:54 +0200 Subject: [PATCH 02/18] Initial implementation Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 26 +++++++++++++++++++------- modules/k6/examples_test.go | 21 +++++---------------- modules/k6/k6.go | 31 +++++++++++++++++++++++++++++++ modules/k6/k6_test.go | 27 +++++++++++++++++++++++---- modules/k6/scripts/test.js | 3 +++ 5 files changed, 81 insertions(+), 27 deletions(-) create mode 100644 modules/k6/scripts/test.js diff --git a/docs/modules/k6.md b/docs/modules/k6.md index f5d61c9c70..22e09176eb 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -6,6 +6,11 @@ Not available until the next release of testcontainers-go Date: Wed, 4 Oct 2023 14:29:37 +0200 Subject: [PATCH 03/18] Address review comments Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 6 +++--- modules/k6/examples_test.go | 8 ++++++-- modules/k6/k6.go | 6 +++--- modules/k6/k6_test.go | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/modules/k6.md b/docs/modules/k6.md index 22e09176eb..53fd5472c5 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -48,12 +48,12 @@ Use the `WithTestScript` option to specify the test script to run. The path to t k6.RunContainer(ctx, k6.WithTestScript("/tests/test.js")) ``` -#### WithOptions +#### WithCmdOptions -Use `WithOptions` to pass a variadic list of strings as [options](https://k6.io/docs/using-k6/k6-options/reference/) to the k6 run command +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, WithOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) +k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) ``` diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index f6e5e05d17..558a6daa07 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -20,7 +20,11 @@ func ExampleRunContainer() { if err != nil { panic(err) } - //} - container.Terminate(ctx) + defer func() { + if err := container.Terminate(ctx); err != nil { + panic(err) + } + }() + // } } diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 63a4f29ab3..85fd5f10ec 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -33,8 +33,8 @@ func WithTestScript(scriptPath string) testcontainers.CustomizeRequestOption { } } -// WithOptions pass the given options to the k6 run command -func WithOptions(options...string) testcontainers.CustomizeRequestOption { +// WithCmdOptions pass the given options to the k6 run command +func WithCmdOptions(options...string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { req.Cmd = append(req.Cmd, options...) } @@ -43,7 +43,7 @@ func WithOptions(options...string) testcontainers.CustomizeRequestOption { // RunContainer creates an instance of the K6 container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { req := testcontainers.ContainerRequest{ - Image: "szkiba/k6x", + Image: "szkiba/k6x:v0.3.1", Cmd: []string{"run"}, WaitingFor: wait.ForExit(), } diff --git a/modules/k6/k6_test.go b/modules/k6/k6_test.go index a1e0a53e81..a193ba3239 100644 --- a/modules/k6/k6_test.go +++ b/modules/k6/k6_test.go @@ -11,7 +11,7 @@ import ( func TestK6(t *testing.T) { ctx := context.Background() - absPath, err := filepath.Abs("./scripts/test.js") + absPath, err := filepath.Abs(filepath.Join("scripts", "test.js")) if err != nil { t.Fatal(err) } From 1958637db01c16189fd54345dd04857d9f447dde Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Wed, 4 Oct 2023 14:41:10 +0200 Subject: [PATCH 04/18] Remove k6 examples Signed-off-by: Pablo Chacin --- .github/workflows/ci.yml | 2 +- .vscode/.testcontainers-go.code-workspace | 4 -- docs/examples/k6.md | 47 ----------------------- examples/k6/Makefile | 5 --- examples/k6/examples_test.go | 37 ------------------ examples/k6/go.mod | 7 ---- examples/k6/k6.go | 35 ----------------- examples/k6/k6_test.go | 26 ------------- sonar-project.properties | 2 +- 9 files changed, 2 insertions(+), 163 deletions(-) delete mode 100644 docs/examples/k6.md delete mode 100644 examples/k6/Makefile delete mode 100644 examples/k6/examples_test.go delete mode 100644 examples/k6/go.mod delete mode 100644 examples/k6/k6.go delete mode 100644 examples/k6/k6_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8d2cbff3f..84123d6745 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -123,7 +123,7 @@ jobs: needs: test-modules strategy: matrix: - module: [cockroachdb, consul, k6, nginx, toxiproxy] + module: [cockroachdb, consul, nginx, toxiproxy] uses: ./.github/workflows/ci-test-go.yml with: go-version: "1.20.x" diff --git a/.vscode/.testcontainers-go.code-workspace b/.vscode/.testcontainers-go.code-workspace index e2fc5c0ada..49faf54917 100644 --- a/.vscode/.testcontainers-go.code-workspace +++ b/.vscode/.testcontainers-go.code-workspace @@ -13,10 +13,6 @@ "name": "example / consul", "path": "../examples/consul" }, - { - "name": "example / k6", - "path": "../examples/k6" - }, { "name": "example / nginx", "path": "../examples/nginx" diff --git a/docs/examples/k6.md b/docs/examples/k6.md deleted file mode 100644 index 94b9804ab3..0000000000 --- a/docs/examples/k6.md +++ /dev/null @@ -1,47 +0,0 @@ -# k6 - -Not available until the next release of testcontainers-go :material-tag: main - -## Introduction - -The Testcontainers module for k6. - -## 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/examples/k6 -``` - -## Usage example - - -[Creating a k6 container](../../examples/k6/examples_test.go) inside_block:runk6Container - - -## Module reference - -The k6 module exposes one entrypoint function to create 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. - -#### Image - -If you need to set a different k6 Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for k6. E.g. `testcontainers.WithImage("grafana/k6")`. - -{% include "../features/common_functional_options.md" %} - -### Container Methods - -The k6 container exposes the following methods: diff --git a/examples/k6/Makefile b/examples/k6/Makefile deleted file mode 100644 index 30ab524295..0000000000 --- a/examples/k6/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -include ../../commons-test.mk - -.PHONY: test -test: - $(MAKE) test-k6 diff --git a/examples/k6/examples_test.go b/examples/k6/examples_test.go deleted file mode 100644 index 9d24f60be6..0000000000 --- a/examples/k6/examples_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package k6_test - -import ( - "context" - "fmt" - - "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/modules/k6" -) - -func ExamplerunContainer() { - // runk6Container { - ctx := context.Background() - - k6Container, err := k6.runContainer(ctx, testcontainers.WithImage("grafana/k6")) - if err != nil { - panic(err) - } - - // Clean up the container - defer func() { - if err := k6Container.Terminate(ctx); err != nil { - panic(err) - } - }() - // } - - state, err := k6Container.State(ctx) - if err != nil { - panic(err) - } - - fmt.Println(state.Running) - - // Output: - // true -} diff --git a/examples/k6/go.mod b/examples/k6/go.mod deleted file mode 100644 index 089135ef10..0000000000 --- a/examples/k6/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -module github.com/testcontainers/testcontainers-go/examples/k6 - -go 1.20 - -require github.com/testcontainers/testcontainers-go v0.24.1 - -replace github.com/testcontainers/testcontainers-go => ../.. diff --git a/examples/k6/k6.go b/examples/k6/k6.go deleted file mode 100644 index 03fb7b30d5..0000000000 --- a/examples/k6/k6.go +++ /dev/null @@ -1,35 +0,0 @@ -package k6 - -import ( - "context" - - "github.com/testcontainers/testcontainers-go" -) - -// k6Container represents the k6 container type used in the module -type k6Container struct { - testcontainers.Container -} - -// runContainer creates an instance of the k6 container type -func runContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*k6Container, error) { - req := testcontainers.ContainerRequest{ - Image: "grafana/k6", - } - - genericContainerReq := testcontainers.GenericContainerRequest{ - ContainerRequest: req, - Started: true, - } - - for _, opt := range opts { - opt.Customize(&genericContainerReq) - } - - container, err := testcontainers.GenericContainer(ctx, genericContainerReq) - if err != nil { - return nil, err - } - - return &k6Container{Container: container}, nil -} diff --git a/examples/k6/k6_test.go b/examples/k6/k6_test.go deleted file mode 100644 index 9fbfb30b3e..0000000000 --- a/examples/k6/k6_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package k6 - -import ( - "context" - "testing" - - "github.com/testcontainers/testcontainers-go" -) - -func Testk6(t *testing.T) { - ctx := context.Background() - - container, err := runContainer(ctx, testcontainers.WithImage("grafana/k6")) - if err != nil { - t.Fatal(err) - } - - // Clean up the container after the test is complete - t.Cleanup(func() { - if err := container.Terminate(ctx); err != nil { - t.Fatalf("failed to terminate container: %s", err) - } - }) - - // perform assertions -} diff --git a/sonar-project.properties b/sonar-project.properties index 06663163bd..af2796246e 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -18,4 +18,4 @@ sonar.test.inclusions=**/*_test.go sonar.test.exclusions=**/vendor/** sonar.go.coverage.reportPaths=**/coverage.out -sonar.go.tests.reportPaths=TEST-unit.xml,examples/cockroachdb/TEST-unit.xml,examples/consul/TEST-unit.xml,examples/k6/TEST-unit.xml,examples/nginx/TEST-unit.xml,examples/toxiproxy/TEST-unit.xml,modulegen/TEST-unit.xml,modules/artemis/TEST-unit.xml,modules/clickhouse/TEST-unit.xml,modules/compose/TEST-unit.xml,modules/couchbase/TEST-unit.xml,modules/elasticsearch/TEST-unit.xml,modules/gcloud/TEST-unit.xml,modules/k3s/TEST-unit.xml,modules/k6/TEST-unit.xml,modules/kafka/TEST-unit.xml,modules/localstack/TEST-unit.xml,modules/mariadb/TEST-unit.xml,modules/mongodb/TEST-unit.xml,modules/mysql/TEST-unit.xml,modules/nats/TEST-unit.xml,modules/neo4j/TEST-unit.xml,modules/postgres/TEST-unit.xml,modules/pulsar/TEST-unit.xml,modules/rabbitmq/TEST-unit.xml,modules/redis/TEST-unit.xml,modules/redpanda/TEST-unit.xml,modules/vault/TEST-unit.xml +sonar.go.tests.reportPaths=TEST-unit.xml,examples/cockroachdb/TEST-unit.xml,examples/consul/TEST-unit.xml,examples/nginx/TEST-unit.xml,examples/toxiproxy/TEST-unit.xml,modulegen/TEST-unit.xml,modules/artemis/TEST-unit.xml,modules/clickhouse/TEST-unit.xml,modules/compose/TEST-unit.xml,modules/couchbase/TEST-unit.xml,modules/elasticsearch/TEST-unit.xml,modules/gcloud/TEST-unit.xml,modules/k3s/TEST-unit.xml,modules/k6/TEST-unit.xml,modules/kafka/TEST-unit.xml,modules/localstack/TEST-unit.xml,modules/mariadb/TEST-unit.xml,modules/mongodb/TEST-unit.xml,modules/mysql/TEST-unit.xml,modules/nats/TEST-unit.xml,modules/neo4j/TEST-unit.xml,modules/postgres/TEST-unit.xml,modules/pulsar/TEST-unit.xml,modules/rabbitmq/TEST-unit.xml,modules/redis/TEST-unit.xml,modules/redpanda/TEST-unit.xml,modules/vault/TEST-unit.xml From 420041c98045ce3af95b86dc6bdf396a0947549e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Wed, 4 Oct 2023 16:53:25 +0200 Subject: [PATCH 05/18] fix: lint --- modules/k6/k6.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 85fd5f10ec..6e15020dc5 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -14,7 +14,6 @@ type K6Container struct { testcontainers.Container } - // WithTestScript mounts the given script into the ./test directory in the container // and passes it to k6 as the test to run. // The path to the script must be an absolute path @@ -24,7 +23,7 @@ func WithTestScript(scriptPath string) testcontainers.CustomizeRequestOption { target := fmt.Sprintf("/tests/%s", script) mount := testcontainers.ContainerMount{ Source: testcontainers.GenericBindMountSource{ - HostPath: scriptPath, + HostPath: scriptPath, }, Target: testcontainers.ContainerMountTarget(target), } @@ -34,7 +33,7 @@ func WithTestScript(scriptPath string) testcontainers.CustomizeRequestOption { } // WithCmdOptions pass the given options to the k6 run command -func WithCmdOptions(options...string) testcontainers.CustomizeRequestOption { +func WithCmdOptions(options ...string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { req.Cmd = append(req.Cmd, options...) } @@ -43,8 +42,8 @@ func WithCmdOptions(options...string) testcontainers.CustomizeRequestOption { // RunContainer creates an instance of the K6 container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { req := testcontainers.ContainerRequest{ - Image: "szkiba/k6x:v0.3.1", - Cmd: []string{"run"}, + Image: "szkiba/k6x:v0.3.1", + Cmd: []string{"run"}, WaitingFor: wait.ForExit(), } From 904a3824598c4ea1b49b9c6ba23e1adf436e94a4 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 13:25:41 +0200 Subject: [PATCH 06/18] Use k6 return code in tests Signed-off-by: Pablo Chacin --- modules/k6/k6_test.go | 69 +++++++++++++++---------- modules/k6/scripts/fail.js | 5 ++ modules/k6/scripts/{test.js => pass.js} | 0 3 files changed, 46 insertions(+), 28 deletions(-) create mode 100644 modules/k6/scripts/fail.js rename modules/k6/scripts/{test.js => pass.js} (100%) diff --git a/modules/k6/k6_test.go b/modules/k6/k6_test.go index a193ba3239..489e275fda 100644 --- a/modules/k6/k6_test.go +++ b/modules/k6/k6_test.go @@ -1,45 +1,58 @@ package k6 import ( - "bytes" "context" "path/filepath" - "strings" "testing" ) func TestK6(t *testing.T) { ctx := context.Background() - absPath, err := filepath.Abs(filepath.Join("scripts", "test.js")) - if err != nil { - t.Fatal(err) + testCases := []struct { + title string + script string + expect int + }{ + { + title: "Passing test", + script: "pass.js", + expect: 0, + }, + { + title: "Failing test", + script: "fail.js", + expect: 108, + }, } - container, err := RunContainer(ctx, WithTestScript(absPath)) - if err != nil { - t.Fatal(err) - } - // Clean up the container after the test is complete - t.Cleanup(func() { - if err := container.Terminate(ctx); err != nil { - t.Fatalf("failed to terminate container: %s", err) - } - }) - - // assert the test script was executed - logs, err := container.Logs(ctx) - if err != nil { - t.Fatal(err) - } + for _, tc := range testCases { + tc := tc + t.Run(tc.title, func(t *testing.T) { + absPath, err := filepath.Abs(filepath.Join("scripts", tc.script)) + if err != nil { + t.Fatal(err) + } - buffer := bytes.Buffer{} - _, err = buffer.ReadFrom(logs) - if err != nil { - t.Fatal(err) - } + container, err := RunContainer(ctx, WithTestScript(absPath)) + if err != nil { + t.Fatal(err) + } + // Clean up the container after the test is complete + t.Cleanup(func() { + if err := container.Terminate(ctx); err != nil { + t.Fatalf("failed to terminate container: %s", err) + } + }) - if !strings.Contains(buffer.String(), "Test executed") { - t.Fatalf("expected 'Test executed'. got %q", buffer.String()) + // assert the result of the test + state, err := container.State(ctx) + if err != nil { + t.Fatal(err) + } + if state.ExitCode != tc.expect { + t.Fatalf("expected %d got %d", tc.expect, state.ExitCode) + } + }) } } diff --git a/modules/k6/scripts/fail.js b/modules/k6/scripts/fail.js new file mode 100644 index 0000000000..acafc81fda --- /dev/null +++ b/modules/k6/scripts/fail.js @@ -0,0 +1,5 @@ +import exec from 'k6/execution'; + +export default function(){ + exec.test.abort("failed") +} \ No newline at end of file diff --git a/modules/k6/scripts/test.js b/modules/k6/scripts/pass.js similarity index 100% rename from modules/k6/scripts/test.js rename to modules/k6/scripts/pass.js From de11382d76a7d14ea8c7d2a2ae0cdfaccf6717a9 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 13:31:01 +0200 Subject: [PATCH 07/18] Use k6 return code to check test result Signed-off-by: Pablo Chacin --- modules/k6/examples_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index 558a6daa07..b0cc155e35 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -2,6 +2,7 @@ package k6_test import ( "context" + "fmt" "path/filepath" "github.com/testcontainers/testcontainers-go/modules/k6" @@ -11,7 +12,7 @@ func ExampleRunContainer() { // runK6Container { ctx := context.Background() - absPath, err := filepath.Abs("./scripts/test.js") + absPath, err := filepath.Abs("./scripts/pass.js") if err != nil { panic(err) } @@ -26,5 +27,14 @@ func ExampleRunContainer() { panic(err) } }() + + // assert the result of the test + state, err := container.State(ctx) + if err != nil { + panic(err) + } + if state.ExitCode != 0 { + panic(fmt.Errorf("test failed with exit code %d", state.ExitCode)) + } // } } From 4cc9cc85ed9bfa44c6b81c9b47ccc6b5092e17b4 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 16:14:34 +0200 Subject: [PATCH 08/18] Add WithCache option Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 18 ++++++++++++++++++ modules/k6/k6.go | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/docs/modules/k6.md b/docs/modules/k6.md index 53fd5472c5..ba20b06d64 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -56,4 +56,22 @@ Use `WithCmdOptions` to pass a variadic list of strings as [options](https://k6. k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) ``` +#### WithCache +Use `WithCache` option to pass a local directory to be used as a [cache for building the k6 binary](https://github.com/szkiba/k6x#cache) inside the `k6` container. +This option can improve considerably the execution time of tests. + +!!!tip + In order to use this option, you must override the default user used by the `k6` container with an user that has write permission on the cache directory. Use the `AsUser` option to set this user. + +```golang +k6.RunContainer(ctx, WithCache("/tmp/.cache"), AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) +``` + +#### AsUser + +The `AsUser` sets the user id and group id to be used when running the `k6` container. + +```golang +k6.RunContainer(ctx, AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) +``` \ No newline at end of file diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 6e15020dc5..6c0d5affd9 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -39,6 +39,29 @@ func WithCmdOptions(options ...string) testcontainers.CustomizeRequestOption { } } +// WithCache uses the given directory as a cache directory building the k6 binary. +// The path to the directory must be an absolute path +// Note: The container must run using an user that +// has access to the directory. See AsUser option +func WithCache(cacheDir string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + mount := testcontainers.ContainerMount{ + Source: testcontainers.GenericBindMountSource{ + HostPath: cacheDir, + }, + Target: "/cache", + } + req.Mounts = append(req.Mounts, mount) + } +} + +// AsUser sets the user id and group id to be used when running the container +func AsUser(userId int, groupId int) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + req.User = fmt.Sprintf("%d:%d", userId, groupId) + } +} + // RunContainer creates an instance of the K6 container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { req := testcontainers.ContainerRequest{ From d16899cad3dd7acc4e2aed8013e14ba8f01d7c23 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 19:05:12 +0200 Subject: [PATCH 09/18] Fix context in tests Signed-off-by: Pablo Chacin --- modules/k6/k6_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/k6/k6_test.go b/modules/k6/k6_test.go index 489e275fda..4fc6b45c51 100644 --- a/modules/k6/k6_test.go +++ b/modules/k6/k6_test.go @@ -7,8 +7,6 @@ import ( ) func TestK6(t *testing.T) { - ctx := context.Background() - testCases := []struct { title string script string @@ -29,6 +27,8 @@ func TestK6(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.title, func(t *testing.T) { + ctx := context.Background() + absPath, err := filepath.Abs(filepath.Join("scripts", tc.script)) if err != nil { t.Fatal(err) From cc8962982d55f8975b9c82f81d2765ee1c45ffce Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 20:21:00 +0200 Subject: [PATCH 10/18] Add SetEnvVar option Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 8 ++++++++ modules/k6/k6.go | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/docs/modules/k6.md b/docs/modules/k6.md index ba20b06d64..e059c97a8f 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -74,4 +74,12 @@ The `AsUser` sets the user id and group id to be used when running the `k6` cont ```golang k6.RunContainer(ctx, AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) +``` + +#### SetEvVar + +`WithEnvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script + +```golang +k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) ``` \ No newline at end of file diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 6c0d5affd9..6dc38d49c9 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -39,6 +39,13 @@ func WithCmdOptions(options ...string) testcontainers.CustomizeRequestOption { } } +// WithEnvVar sets an environment variable for the test script +func WithEnvVar(variable string, value string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + req.Cmd = append(req.Cmd, "--env", fmt.Sprintf("%s=%s", variable, value)) + } +} + // WithCache uses the given directory as a cache directory building the k6 binary. // The path to the directory must be an absolute path // Note: The container must run using an user that From 4bb5e826869e77ec9b2872b5480807d34a9ca957 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 20:50:17 +0200 Subject: [PATCH 11/18] Add complete usage example Signed-off-by: Pablo Chacin --- modules/k6/examples_test.go | 51 ++++++++++++++++++++++++++++------- modules/k6/scripts/httpbin.js | 10 +++++++ 2 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 modules/k6/scripts/httpbin.js diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index b0cc155e35..50a7c1f70e 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -5,36 +5,69 @@ import ( "fmt" "path/filepath" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/k6" + "github.com/testcontainers/testcontainers-go/wait" ) func ExampleRunContainer() { // runK6Container { ctx := context.Background() - absPath, err := filepath.Abs("./scripts/pass.js") + gcr := testcontainers.GenericContainerRequest{ + ProviderType: testcontainers.ProviderDocker, + ContainerRequest: testcontainers.ContainerRequest{ + Image: "kennethreitz/httpbin", + ExposedPorts: []string{ + "80", + }, + WaitingFor: wait.ForExposedPort(), + }, + Started: true, + } + httpbin, err := testcontainers.GenericContainer(ctx, gcr) if err != nil { - panic(err) + panic(fmt.Errorf("failed to create httpbin container %v", err)) } - container, err := k6.RunContainer(ctx, k6.WithTestScript(absPath)) + defer func() { + if err := httpbin.Terminate(ctx); err != nil { + panic(fmt.Errorf("failed to terminate container: %s", err)) + } + }() + + httpbinIP, err := httpbin.ContainerIP(ctx) if err != nil { - panic(err) + panic(fmt.Errorf("failed to get httpbin IP:\n%v", err)) + } + + absPath, err := filepath.Abs(filepath.Join("scripts", "httpbin.js")) + if err != nil { + panic(fmt.Errorf("failed to get path to test script: %s", err)) + } + + k6, err := k6.RunContainer( + ctx, + k6.WithTestScript(absPath), + k6.WithEnvVar("HTTPBIN", httpbinIP), + ) + if err != nil { + panic(fmt.Errorf("failed to start k6 container: %s", err)) } defer func() { - if err := container.Terminate(ctx); err != nil { - panic(err) + if err := k6.Terminate(ctx); err != nil { + panic(fmt.Errorf("failed to terminate container: %s", err)) } }() // assert the result of the test - state, err := container.State(ctx) + state, err := k6.State(ctx) if err != nil { panic(err) } if state.ExitCode != 0 { - panic(fmt.Errorf("test failed with exit code %d", state.ExitCode)) + panic("k6 test failed") } - // } + //} } diff --git a/modules/k6/scripts/httpbin.js b/modules/k6/scripts/httpbin.js new file mode 100644 index 0000000000..d6c77fefd2 --- /dev/null +++ b/modules/k6/scripts/httpbin.js @@ -0,0 +1,10 @@ +import { check } from 'k6'; +import http from 'k6/http'; + +export default function () { + const res = http.get(`http://${__ENV.HTTPBIN}/status/200`); + + check(res, { + 'is status 200': (r) => r.status === 200, + }); +} \ No newline at end of file From 71b2abad1154e421fc8d22d44ed040b94712afa2 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 21:02:05 +0200 Subject: [PATCH 12/18] Address lint issues Signed-off-by: Pablo Chacin --- modules/k6/examples_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index 50a7c1f70e..009598ab5b 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -27,23 +27,23 @@ func ExampleRunContainer() { } httpbin, err := testcontainers.GenericContainer(ctx, gcr) if err != nil { - panic(fmt.Errorf("failed to create httpbin container %v", err)) + panic(fmt.Errorf("failed to create httpbin container %w", err)) } defer func() { if err := httpbin.Terminate(ctx); err != nil { - panic(fmt.Errorf("failed to terminate container: %s", err)) + panic(fmt.Errorf("failed to terminate container: %w", err)) } }() httpbinIP, err := httpbin.ContainerIP(ctx) if err != nil { - panic(fmt.Errorf("failed to get httpbin IP:\n%v", err)) + 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: %s", err)) + panic(fmt.Errorf("failed to get path to test script: %w", err)) } k6, err := k6.RunContainer( @@ -52,12 +52,12 @@ func ExampleRunContainer() { k6.WithEnvVar("HTTPBIN", httpbinIP), ) if err != nil { - panic(fmt.Errorf("failed to start k6 container: %s", err)) + panic(fmt.Errorf("failed to start k6 container: %w", err)) } defer func() { if err := k6.Terminate(ctx); err != nil { - panic(fmt.Errorf("failed to terminate container: %s", err)) + panic(fmt.Errorf("failed to terminate container: %w", err)) } }() From 380de41146ca183ec70103987224ec845b402e6e Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Thu, 5 Oct 2023 21:10:44 +0200 Subject: [PATCH 13/18] Reorganize options by name in documentation Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/modules/k6.md b/docs/modules/k6.md index e059c97a8f..959d634710 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -40,20 +40,20 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize When starting the K6 container, you can pass options in a variadic way to configure it. -#### WithTestScript +#### AsUser -Use the `WithTestScript` option to specify the test script to run. The path to the script must be an absolute path. This option mounts the script file in the container and pass it to k6's `run` command. +The `AsUser` sets the user id and group id to be used when running the `k6` container. ```golang -k6.RunContainer(ctx, k6.WithTestScript("/tests/test.js")) +k6.RunContainer(ctx, AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) ``` -#### WithCmdOptions +#### SetEvVar -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 +`SetEvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script ```golang -k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) +k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) ``` #### WithCache @@ -68,18 +68,18 @@ This option can improve considerably the execution time of tests. k6.RunContainer(ctx, WithCache("/tmp/.cache"), AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) ``` -#### AsUser +#### WithCmdOptions -The `AsUser` sets the user id and group id to be used when running the `k6` container. +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, AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) +k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) ``` -#### SetEvVar +#### WithTestScript -`WithEnvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script +Use the `WithTestScript` option to specify the test script to run. The path to the script must be an absolute path. This option mounts the script file in the container and pass it to k6's `run` command. ```golang -k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) -``` \ No newline at end of file +k6.RunContainer(ctx, k6.WithTestScript("/tests/test.js")) +``` From 846982790787cee7b3b2e6408138fcb24abd2f66 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Fri, 6 Oct 2023 09:45:27 +0200 Subject: [PATCH 14/18] Rename option to SetEnvVar Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 4 ++-- modules/k6/examples_test.go | 2 +- modules/k6/k6.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/modules/k6.md b/docs/modules/k6.md index 959d634710..b60f3e04b2 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -48,9 +48,9 @@ The `AsUser` sets the user id and group id to be used when running the `k6` cont k6.RunContainer(ctx, AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) ``` -#### SetEvVar +#### SetEnvVar -`SetEvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script +`SetEnvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script ```golang k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index 009598ab5b..4d4cff611b 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -49,7 +49,7 @@ func ExampleRunContainer() { k6, err := k6.RunContainer( ctx, k6.WithTestScript(absPath), - k6.WithEnvVar("HTTPBIN", httpbinIP), + k6.SetEnvVar("HTTPBIN", httpbinIP), ) if err != nil { panic(fmt.Errorf("failed to start k6 container: %w", err)) diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 6dc38d49c9..0e97a292be 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -39,8 +39,8 @@ func WithCmdOptions(options ...string) testcontainers.CustomizeRequestOption { } } -// WithEnvVar sets an environment variable for the test script -func WithEnvVar(variable string, value string) testcontainers.CustomizeRequestOption { +// SetEnvVar sets an environment variable for the test script +func SetEnvVar(variable string, value string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { req.Cmd = append(req.Cmd, "--env", fmt.Sprintf("%s=%s", variable, value)) } From cf691e883f3f7d03d4633701ee7c2be113f099a0 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Mon, 9 Oct 2023 12:15:04 +0200 Subject: [PATCH 15/18] Adress review comments Signed-off-by: Pablo Chacin --- modules/k6/examples_test.go | 13 ++++++++++++- modules/k6/k6.go | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index 4d4cff611b..bf5c184393 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -3,6 +3,8 @@ package k6_test import ( "context" "fmt" + "io" + "os" "path/filepath" "github.com/testcontainers/testcontainers-go" @@ -14,6 +16,8 @@ func ExampleRunContainer() { // runK6Container { ctx := context.Background() + // create a container with the httpbin application that will be the target + // for the test script that runs in the k6 container gcr := testcontainers.GenericContainerRequest{ ProviderType: testcontainers.ProviderDocker, ContainerRequest: testcontainers.ContainerRequest{ @@ -46,6 +50,7 @@ func ExampleRunContainer() { panic(fmt.Errorf("failed to get path to test script: %w", err)) } + // run the httpbin.js test scripts passing the IP address the httpbin container k6, err := k6.RunContainer( ctx, k6.WithTestScript(absPath), @@ -67,7 +72,13 @@ func ExampleRunContainer() { panic(err) } if state.ExitCode != 0 { - panic("k6 test failed") + logs, err := k6.Logs(ctx) + if err != nil { + panic(err) + } + + fmt.Println("k6 test failed:") + io.Copy(os.Stdout, logs) } //} } diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 0e97a292be..7f57930206 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -39,7 +39,7 @@ func WithCmdOptions(options ...string) testcontainers.CustomizeRequestOption { } } -// SetEnvVar sets an environment variable for the test script +// SetEnvVar adds a '--env' command-line flag to the k6 command in the container for setting an environment variable for the test script. func SetEnvVar(variable string, value string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { req.Cmd = append(req.Cmd, "--env", fmt.Sprintf("%s=%s", variable, value)) From a69aae1f5b0630e75aebd8bbd406977eaf7467f3 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Mon, 9 Oct 2023 13:22:11 +0200 Subject: [PATCH 16/18] Copy test script to container Signed-off-by: Pablo Chacin --- modules/k6/k6.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 7f57930206..e39997bfce 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -20,14 +20,17 @@ type K6Container struct { func WithTestScript(scriptPath string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { script := filepath.Base(scriptPath) - target := fmt.Sprintf("/tests/%s", script) - mount := testcontainers.ContainerMount{ - Source: testcontainers.GenericBindMountSource{ - HostPath: scriptPath, + target := filepath.Join("/home/k6x", script) + req.Files = append( + req.Files, + testcontainers.ContainerFile{ + HostFilePath: scriptPath, + ContainerFilePath: target, + FileMode: 0o644, }, - Target: testcontainers.ContainerMountTarget(target), - } - req.Mounts = append(req.Mounts, mount) + ) + + // add script to the k6 run command req.Cmd = append(req.Cmd, target) } } From d44b5473e3f29df4241490b6c9637f5387551b30 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Mon, 9 Oct 2023 14:31:24 +0200 Subject: [PATCH 17/18] Address review comments Signed-off-by: Pablo Chacin --- docs/modules/k6.md | 21 ++++++--------------- modules/k6/examples_test.go | 13 +++---------- modules/k6/k6.go | 21 ++++++--------------- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/docs/modules/k6.md b/docs/modules/k6.md index b60f3e04b2..2ab22e17ce 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -40,17 +40,9 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize When starting the K6 container, you can pass options in a variadic way to configure it. -#### AsUser - -The `AsUser` sets the user id and group id to be used when running the `k6` container. - -```golang -k6.RunContainer(ctx, AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) -``` - #### SetEnvVar -`SetEnvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script +`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")) @@ -58,14 +50,13 @@ k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests #### WithCache -Use `WithCache` option to pass a local directory to be used as a [cache for building the k6 binary](https://github.com/szkiba/k6x#cache) inside the `k6` container. -This option can improve considerably the execution time of tests. +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. -!!!tip - In order to use this option, you must override the default user used by the `k6` container with an user that has write permission on the cache directory. Use the `AsUser` option to set this user. ```golang -k6.RunContainer(ctx, WithCache("/tmp/.cache"), AsUser(os.Getuid(), os.Getgid()), k6.WithTestScript("/tests/test.js")) +k6.RunContainer(ctx, WithCache("cache"), k6.WithTestScript("/tests/test.js")) ``` #### WithCmdOptions @@ -78,7 +69,7 @@ k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestSc #### WithTestScript -Use the `WithTestScript` option to specify the test script to run. The path to the script must be an absolute path. This option mounts the script file in the container and pass it to k6's `run` command. +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")) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index bf5c184393..b800bf11b4 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -3,8 +3,6 @@ package k6_test import ( "context" "fmt" - "io" - "os" "path/filepath" "github.com/testcontainers/testcontainers-go" @@ -71,14 +69,9 @@ func ExampleRunContainer() { if err != nil { panic(err) } - if state.ExitCode != 0 { - logs, err := k6.Logs(ctx) - if err != nil { - panic(err) - } - fmt.Println("k6 test failed:") - io.Copy(os.Stdout, logs) - } + fmt.Println(state.ExitCode) + // Output: 0 + //} } diff --git a/modules/k6/k6.go b/modules/k6/k6.go index e39997bfce..ee26c433a0 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -20,7 +20,7 @@ type K6Container struct { func WithTestScript(scriptPath string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { script := filepath.Base(scriptPath) - target := filepath.Join("/home/k6x", script) + target := "/home/k6x/" + script req.Files = append( req.Files, testcontainers.ContainerFile{ @@ -49,15 +49,13 @@ func SetEnvVar(variable string, value string) testcontainers.CustomizeRequestOpt } } -// WithCache uses the given directory as a cache directory building the k6 binary. -// The path to the directory must be an absolute path -// Note: The container must run using an user that -// has access to the directory. See AsUser option -func WithCache(cacheDir string) testcontainers.CustomizeRequestOption { +// WithCache uses the given volume as a cache for building the k6 binary. +// If the volume does not exists, it is created. +func WithCache(cache string) testcontainers.CustomizeRequestOption { return func(req *testcontainers.GenericContainerRequest) { mount := testcontainers.ContainerMount{ - Source: testcontainers.GenericBindMountSource{ - HostPath: cacheDir, + Source: testcontainers.DockerVolumeMountSource{ + Name: cache, }, Target: "/cache", } @@ -65,13 +63,6 @@ func WithCache(cacheDir string) testcontainers.CustomizeRequestOption { } } -// AsUser sets the user id and group id to be used when running the container -func AsUser(userId int, groupId int) testcontainers.CustomizeRequestOption { - return func(req *testcontainers.GenericContainerRequest) { - req.User = fmt.Sprintf("%d:%d", userId, groupId) - } -} - // RunContainer creates an instance of the K6 container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { req := testcontainers.ContainerRequest{ From 4413ca4a04c3a5f6aeb6040164c81063db7f4fe5 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Mon, 9 Oct 2023 14:45:16 +0200 Subject: [PATCH 18/18] Fix executable example Signed-off-by: Pablo Chacin --- modules/k6/examples_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index b800bf11b4..cc9086e429 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -63,6 +63,7 @@ func ExampleRunContainer() { panic(fmt.Errorf("failed to terminate container: %w", err)) } }() + //} // assert the result of the test state, err := k6.State(ctx) @@ -72,6 +73,4 @@ func ExampleRunContainer() { fmt.Println(state.ExitCode) // Output: 0 - - //} }