diff --git a/container_test.go b/container_test.go index 9f32a854b4..04c57c615a 100644 --- a/container_test.go +++ b/container_test.go @@ -419,3 +419,57 @@ func TestVolumeMount(t *testing.T) { }) } } + +func TestOverrideContainerRequest(t *testing.T) { + req := GenericContainerRequest{ + ContainerRequest: ContainerRequest{ + Env: map[string]string{ + "BAR": "BAR", + }, + Image: "foo", + ExposedPorts: []string{"12345/tcp"}, + WaitingFor: wait.ForNop( + func(ctx context.Context, target wait.StrategyTarget) error { + return nil + }, + ), + Networks: []string{"foo", "bar", "baaz"}, + NetworkAliases: map[string][]string{ + "foo": {"foo0", "foo1", "foo2", "foo3"}, + }, + }, + } + + toBeMergedRequest := GenericContainerRequest{ + ContainerRequest: ContainerRequest{ + Env: map[string]string{ + "FOO": "FOO", + }, + Image: "bar", + ExposedPorts: []string{"67890/tcp"}, + Networks: []string{"foo1", "bar1"}, + NetworkAliases: map[string][]string{ + "foo1": {"bar"}, + }, + WaitingFor: wait.ForLog("foo"), + }, + } + + // the toBeMergedRequest should be merged into the req + CustomizeRequest(toBeMergedRequest)(&req) + + // toBeMergedRequest should not be changed + assert.Equal(t, "", toBeMergedRequest.Env["BAR"]) + assert.Equal(t, 1, len(toBeMergedRequest.ExposedPorts)) + assert.Equal(t, "67890/tcp", toBeMergedRequest.ExposedPorts[0]) + + // req should be merged with toBeMergedRequest + assert.Equal(t, "FOO", req.Env["FOO"]) + assert.Equal(t, "BAR", req.Env["BAR"]) + assert.Equal(t, "bar", req.Image) + assert.Equal(t, []string{"12345/tcp", "67890/tcp"}, req.ExposedPorts) + assert.Equal(t, []string{"foo", "bar", "baaz", "foo1", "bar1"}, req.Networks) + assert.Equal(t, []string{"foo0", "foo1", "foo2", "foo3"}, req.NetworkAliases["foo"]) + assert.Equal(t, []string{"bar"}, req.NetworkAliases["foo1"]) + assert.Equal(t, wait.ForLog("foo"), req.WaitingFor) +} diff --git a/docker.go b/docker.go index e4ec56926c..2897ef2518 100644 --- a/docker.go +++ b/docker.go @@ -188,7 +188,7 @@ func (c *DockerContainer) SessionID() string { // Start will start an already created container func (c *DockerContainer) Start(ctx context.Context) error { shortID := c.ID[:12] - c.logger.Printf("Starting container id: %s image: %s", shortID, c.Image) + c.logger.Printf("🐳 Starting container id: %s image: %s", shortID, c.Image) if err := c.provider.client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{}); err != nil { return err @@ -197,12 +197,12 @@ func (c *DockerContainer) Start(ctx context.Context) error { // if a Wait Strategy has been specified, wait before returning if c.WaitingFor != nil { - c.logger.Printf("Waiting for container id %s image: %s", shortID, c.Image) + c.logger.Printf("🚧 Waiting for container id %s image: %s", shortID, c.Image) if err := c.WaitingFor.WaitUntilReady(ctx, c); err != nil { return err } } - c.logger.Printf("Container is ready id: %s image: %s", shortID, c.Image) + c.logger.Printf("✅ Container is ready id: %s image: %s", shortID, c.Image) c.isRunning = true return nil } diff --git a/docs/features/creating_container.md b/docs/features/creating_container.md index 58f10914e8..6a31b4e236 100644 --- a/docs/features/creating_container.md +++ b/docs/features/creating_container.md @@ -89,7 +89,7 @@ func TestIntegrationNginxLatestReturn(t *testing.T) { ### Advanced Settings -The aforementioned `GenericContainer` function and the `ContainerRequest` struct represent a straightforward manner to configure the containers, but you could need to create your containers with more advance settings regarding the config, host config and endpoint settings Docker types. For those more advance settings, _Testcontainers for Go_ offers a way to fully customise the container request and those internal Docker types. These customisations, called _modifiers_, will be applied just before the internal call to the Docker client to create the container. +The aforementioned `GenericContainer` function and the `ContainerRequest` struct represent a straightforward manner to configure the containers, but you could need to create your containers with more advance settings regarding the config, host config and endpoint settings Docker types. For those more advance settings, _Testcontainers for Go_ offers a way to fully customize the container request and those internal Docker types. These customisations, called _modifiers_, will be applied just before the internal call to the Docker client to create the container. [Using modifiers](../../lifecycle_test.go) inside_block:reqWithModifiers diff --git a/docs/modules/index.md b/docs/modules/index.md index b692f61bf8..eb7299b2ce 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -46,7 +46,44 @@ or for creating a Go module: go run . --name ${NAME_OF_YOUR_MODULE} --image "${REGISTRY}/${MODULE}:${TAG}" --title ${TITLE_OF_YOUR_MODULE} --as-module ``` -## Update Go dependencies in the modules +### Adding types and methods to the module + +We are going to propose a set of steps to follow when adding types and methods to the module: + +!!!warning + The `StartContainer` function will be eventually deprecated and replaced with `RunContainer`. We are keeping it in certain modules for backwards compatibility, but they will be removed in the future. + +- Make sure a public `Container` type exists for the module. This type have to use composition to embed the `testcontainers.Container` type, inheriting all the methods from it. +- Make sure a `RunContainer` function exists and is public. This function is the entrypoint to the module and will define the initial values for a `testcontainers.GenericContainerRequest` struct, including the image, the default exposed ports, wait strategies, etc. Therefore, the function must initialise the container request with the default values. +- Define container options for the module. We consider that a best practice for the options is to return a function that returns a modified `testcontainers.GenericContainerRequest` type, and for that, the library already provides with a `testcontainers.CustomizeRequestOption` type representing this function signature. +- The options will be passed to the `RunContainer` function as variadic arguments after the Go context, and they will be processed right after defining the initial `testcontainers.GenericContainerRequest` struct using a for loop. + +```golang +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*Container, error) {...} +``` + +- If needed, define public methods to extract information from the running container, using the `Container` type as receiver. E.g. a connection string to access a database: + +```golang +func (c *Container) ConnectionString(ctx context.Context) (string, error) {...} +``` + +- Document the public API with Go comments. +- Extend the docs to describe the new API of the module. We usually define a parent `Module reference` section, including a `Container options` and a `Container methods` subsections; within each subsection, we define a nested subsection for each option and method, respectively. + +### ContainerRequest options + +In order to simplify the creation of the container for a given module, `Testcontainers for Go` provides with a set of `testcontainers.CustomizeRequestOption` functions to customise the container request for the module. These options are: + +- `testcontainers.CustomizeRequest`: a function that merges the default options with the ones provided by the user. Recommended for completely customising the container request. +- `testcontainers.WithImage`: a function that sets the image for the container request. +- `testcontainers.WithConfigModifier`: a function that sets the config Docker type for the container request. Please see [Advanced Settings](../features/creating_container.md#advanced-settings) for more information. +- `testcontainers.WithEndpointSettingsModifier`: a function that sets the endpoint settings Docker type for the container request. Please see [Advanced Settings](../features/creating_container.md#advanced-settings) for more information. +- `testcontainers.WithHostConfigModifier`: a function that sets the host config Docker type for the container request. Please see [Advanced Settings](../features/creating_container.md#advanced-settings) for more information. +- `testcontainers.WithWaitStrategy`: a function that sets the wait strategy for the container request, adding all the passed wait strategies to the container request, using a `testcontainers.MultiStrategy` with 60 seconds of deadline. Please see [Wait strategies](../features/wait/multi.md) for more information. +- `testcontainers.WithWaitStrategyAndDeadline`: a function that sets the wait strategy for the container request, adding all the passed wait strategies to the container request, using a `testcontainers.MultiStrategy` with the passed deadline. Please see [Wait strategies](../features/wait/multi.md) for more information. + +### Update Go dependencies in the modules To update the Go dependencies in the modules, please run: @@ -54,3 +91,14 @@ To update the Go dependencies in the modules, please run: $ cd modules $ make tidy-examples ``` + +## Interested in converting an example into a module? + +The steps to convert an existing example, aka `${THE_EXAMPLE}`, into a module are the following: + +1. Rename the module path at the `go.mod`file for your example. +1. Move the `examples/${THE_EXAMPLE}` directory to `modules/${THE_EXAMPLE}`. +1. Move the `${THE_EXAMPLE}` dependabot config from the examples section to the modules one, which is located at the bottom. +1. In the `mkdocs.yml` file, move the entry for `${THE_EXAMPLE}` from examples to modules. +1. Move `docs/examples${THE_EXAMPLE}.md` file to `docs/modules/${THE_EXAMPLE}`, updating the references to the source code paths. +1. Update the Github workflow for `${THE_EXAMPLE}`, modifying names and paths. diff --git a/docs/modules/mysql.md b/docs/modules/mysql.md index 08c5cc14f4..8ce8a6cb1e 100644 --- a/docs/modules/mysql.md +++ b/docs/modules/mysql.md @@ -19,11 +19,11 @@ go get github.com/testcontainers/testcontainers-go/modules/mysql The MySQL module exposes one entrypoint function to create the container, and this function receives two parameters: ```golang -func StartContainer(ctx context.Context, opts ...Option) (*MySQLContainer, error) { +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*MySQLContainer, error) { ``` - `context.Context`, the Go context. -- `Option`, a variad argument for passing options. +- `testcontainers.CustomizeRequestOption`, a variad argument for passing options. ## Container Options @@ -35,7 +35,7 @@ When starting the MySQL container, you can pass options in a variadic way to con ### Set Image -By default, the image used is `mysql:8`. If you need to use a different image, you can use `WithImage` option. +By default, the image used is `mysql:8`. If you need to use a different image, you can use `testcontainers.WithImage` option. [Custom Image](../../modules/mysql/mysql_test.go) inside_block:withConfigFile diff --git a/docs/modules/postgres.md b/docs/modules/postgres.md index 9a493f74b3..bc7dd502a1 100644 --- a/docs/modules/postgres.md +++ b/docs/modules/postgres.md @@ -19,11 +19,11 @@ go get github.com/testcontainers/testcontainers-go/modules/postgres The Postgres module exposes one entrypoint function to create the Postgres container, and this function receives two parameters: ```golang -func StartContainer(ctx context.Context, opts ...PostgresContainerOption) (*PostgresContainer, error) +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*PostgresContainer, error) ``` - `context.Context`, the Go context. -- `PostgresContainerOption`, a variad argument for passing options. +- `testcontainers.CustomizeRequestOption`, a variadic argument for passing options. ### Container Options @@ -34,8 +34,8 @@ When starting the Postgres container, you can pass options in a variadic way to #### Image -If you need to set a different Postgres Docker image, you can use `WithImage` with a valid Docker image -for Postgres. E.g. `WithImage("docker.io/postgres:9.6")`. +If you need to set a different Postgres Docker image, you can use `testcontainers.WithImage` with a valid Docker image +for Postgres. E.g. `testcontainers.WithImage("docker.io/postgres:9.6")`. #### Initial Database @@ -74,7 +74,7 @@ In the case you have a custom config file for Postgres, it's possible to copy th #### Wait Strategies Given you could need to wait for different conditions, in particular using a wait.ForSQL strategy, -the Postgres container exposes a `WithWaitStrategy` option to set a custom wait strategy. +the Postgres container exposes a `testcontainers.WithWaitStrategy` option to set a custom wait strategy. [Set Wait Strategy](../../modules/postgres/postgres_test.go) inside_block:withWaitStrategy diff --git a/docs/modules/pulsar.md b/docs/modules/pulsar.md index a28d7693d7..35121d90ea 100644 --- a/docs/modules/pulsar.md +++ b/docs/modules/pulsar.md @@ -33,7 +33,7 @@ Then you can retrieve the broker and the admin url: When starting the Pulsar container, you can pass options in a variadic way to configure it. ### Pulsar Image -If you need to set a different Pulsar image you can use the `WithPulsarImage`. +If you need to set a different Pulsar image you can use the `testcontainers.WithImage`. [Set Pulsar image](../../modules/pulsar/pulsar_test.go) inside_block:setPulsarImage @@ -87,7 +87,7 @@ If you want to know more about LogConsumers, please check the [Following Contain ## Advanced configuration In the case you need a more advanced configuration regarding the config, host config and endpoint settings Docker types, you can leverage the modifier functions that are available in -the ContainerRequest. The Pulsar container exposes a way to interact with those modifiers in a simple manner, using the aforementioned options in the `StartContainer` function: +the ContainerRequest. The Pulsar container exposes a way to interact with those modifiers in a simple manner, using the aforementioned options in the `RunContainer` function: [Advanced Docker settings](../../modules/pulsar/pulsar_test.go) inside_block:advancedDockerSettings diff --git a/docs/modules/redis.md b/docs/modules/redis.md index 66ddb53b9d..714b8a48d1 100644 --- a/docs/modules/redis.md +++ b/docs/modules/redis.md @@ -19,11 +19,11 @@ go get github.com/testcontainers/testcontainers-go/modules/redis The Redis module exposes one entrypoint function to create the containerr, and this function receives two parameters: ```golang -func StartContainer(ctx context.Context, opts ...RedisContainerOption) (*RedisContainer, error) +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*RedisContainer, error) ``` - `context.Context`, the Go context. -- `RedisContainerOption`, a variad argument for passing options. +- `testcontainers.CustomizeRequestOption`, a variad argument for passing options. ### Container Options @@ -34,8 +34,8 @@ When starting the Redis container, you can pass options in a variadic way to con #### Image -If you need to set a different Redis Docker image, you can use `WithImage` with a valid Docker image -for Postgres. E.g. `WithImage("docker.io/redis:7")`. +If you need to set a different Redis Docker image, you can use `testcontainers.WithImage` with a valid Docker image +for Postgres. E.g. `testcontainers.WithImage("docker.io/redis:7")`. [Use a different image](../../modules/redis/redis_test.go) inside_block:withImage diff --git a/docs/modules/vault.md b/docs/modules/vault.md index aef8362c88..11bb677d2f 100644 --- a/docs/modules/vault.md +++ b/docs/modules/vault.md @@ -13,10 +13,10 @@ go get github.com/testcontainers/testcontainers-go/modules/vault ``` ## Usage example -The **StartContainer** function is the main entry point to create a new VaultContainer instance. +The **RunContainer** function is the main entry point to create a new VaultContainer instance. It takes a context and zero or more Option values to configure the container. -[Creating a Vault container](../../modules/vault/vault_test.go) inside_block:StartContainer +[Creating a Vault container](../../modules/vault/vault_test.go) inside_block:RunContainer ### Use CLI to read data from Vault container: @@ -43,7 +43,7 @@ go get -u github.com/hashicorp/vault-client-go You can set below options to create Vault container. ### Image -If you need to set a different Vault image, you can use the `WithImageName`. +If you need to set a different Vault image, you can use the `testcontainers.WithImage`. !!!info Default image name is `hashicorp/vault:1.13.0`. diff --git a/examples/bigtable/go.mod b/examples/bigtable/go.mod index 5be59a3610..d964afeec8 100644 --- a/examples/bigtable/go.mod +++ b/examples/bigtable/go.mod @@ -27,7 +27,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/envoyproxy/go-control-plane v0.10.3 // indirect @@ -42,6 +42,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/bigtable/go.sum b/examples/bigtable/go.sum index c33713d353..cae3b15711 100644 --- a/examples/bigtable/go.sum +++ b/examples/bigtable/go.sum @@ -97,8 +97,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -205,6 +205,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -617,6 +619,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/cockroachdb/go.mod b/examples/cockroachdb/go.mod index 5d94aa32e3..bd1cf9f813 100644 --- a/examples/cockroachdb/go.mod +++ b/examples/cockroachdb/go.mod @@ -21,7 +21,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -29,6 +29,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/jackc/chunkreader/v2 v2.0.1 // indirect github.com/jackc/pgconn v1.14.0 // indirect github.com/jackc/pgio v1.0.0 // indirect diff --git a/examples/cockroachdb/go.sum b/examples/cockroachdb/go.sum index ab801fc456..4e7186bacd 100644 --- a/examples/cockroachdb/go.sum +++ b/examples/cockroachdb/go.sum @@ -45,8 +45,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -106,6 +106,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jackc/chunkreader v1.0.0/go.mod h1:RT6O25fNZIuasFJRyZ4R/Y2BbhasbmZXF9QQ7T3kePo= github.com/jackc/chunkreader/v2 v2.0.0/go.mod h1:odVSm741yZoC3dpHEUXIqA9tQRhFrgOHwnPIn9lDKlk= github.com/jackc/chunkreader/v2 v2.0.1 h1:i+RDz65UE+mmpjTfyz0MoVTnzeYxroil2G82ki7MGG8= @@ -435,6 +437,8 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/consul/go.mod b/examples/consul/go.mod index 82f1020732..8889cbfc36 100644 --- a/examples/consul/go.mod +++ b/examples/consul/go.mod @@ -17,7 +17,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -32,6 +32,7 @@ require ( github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/serf v0.10.1 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/consul/go.sum b/examples/consul/go.sum index f9f9561b9a..e54c4bcd2d 100644 --- a/examples/consul/go.sum +++ b/examples/consul/go.sum @@ -43,8 +43,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -136,6 +136,8 @@ github.com/hashicorp/memberlist v0.5.0 h1:EtYPN8DpAURiapus508I4n9CzHs2W+8NZGbmmR github.com/hashicorp/memberlist v0.5.0/go.mod h1:yvyXLpo0QaGE59Y7hDTsTzDD25JYBZ4mHgHUZ8lrOI0= github.com/hashicorp/serf v0.10.1 h1:Z1H2J60yRKvfDYAOZLd2MU0ND4AH/WDz7xYHDWQsIPY= github.com/hashicorp/serf v0.10.1/go.mod h1:yL2t6BqATOLGc5HF7qbFkTfXoPIY0WZdWHfEvMqbG+4= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -363,6 +365,8 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw 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.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= gotest.tools/gotestsum v1.9.0 h1:Jbo/0k/sIOXIJu51IZxEAt27n77xspFEfL6SqKUR72A= diff --git a/examples/datastore/go.mod b/examples/datastore/go.mod index b92d7d3217..e8d0670a8b 100644 --- a/examples/datastore/go.mod +++ b/examples/datastore/go.mod @@ -21,7 +21,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -34,6 +34,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/datastore/go.sum b/examples/datastore/go.sum index 1da3ed1be9..458b141268 100644 --- a/examples/datastore/go.sum +++ b/examples/datastore/go.sum @@ -38,8 +38,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -96,6 +96,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9 github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ= github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -291,6 +293,8 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175 google.golang.org/protobuf v1.28.1/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.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/firestore/go.mod b/examples/firestore/go.mod index 612a30a87a..6896e16e65 100644 --- a/examples/firestore/go.mod +++ b/examples/firestore/go.mod @@ -22,7 +22,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -35,6 +35,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.11.13 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/firestore/go.sum b/examples/firestore/go.sum index 70adc28142..24f80ab226 100644 --- a/examples/firestore/go.sum +++ b/examples/firestore/go.sum @@ -39,8 +39,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -97,6 +97,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9 github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/gax-go/v2 v2.7.0 h1:IcsPKeInNvYi7eqSaDjiZqDDKu5rsmunY0Y1YupQSSQ= github.com/googleapis/gax-go/v2 v2.7.0/go.mod h1:TEop28CZZQ2y+c0VxMUmu1lV+fQx57QpBWsYpwqHJx8= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.11.13 h1:eSvu8Tmq6j2psUJqJrLcWH6K3w5Dwc+qipbaA6eVEN4= @@ -293,6 +295,8 @@ google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175 google.golang.org/protobuf v1.28.1/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.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/mongodb/go.mod b/examples/mongodb/go.mod index 590aee5a4c..82077c68b7 100644 --- a/examples/mongodb/go.mod +++ b/examples/mongodb/go.mod @@ -16,7 +16,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -26,6 +26,7 @@ require ( github.com/golang/snappy v0.0.1 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/mongodb/go.sum b/examples/mongodb/go.sum index 5a65bc7a27..a3f7734256 100644 --- a/examples/mongodb/go.sum +++ b/examples/mongodb/go.sum @@ -37,8 +37,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -95,6 +95,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= @@ -310,6 +312,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/nginx/go.mod b/examples/nginx/go.mod index 490162e232..769852ad24 100644 --- a/examples/nginx/go.mod +++ b/examples/nginx/go.mod @@ -17,7 +17,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -26,6 +26,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.11.13 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/nginx/go.sum b/examples/nginx/go.sum index 693bde15c8..03bca64dd2 100644 --- a/examples/nginx/go.sum +++ b/examples/nginx/go.sum @@ -37,8 +37,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -92,6 +92,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.11.13 h1:eSvu8Tmq6j2psUJqJrLcWH6K3w5Dwc+qipbaA6eVEN4= @@ -282,6 +284,8 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw 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.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= gotest.tools/gotestsum v1.9.0 h1:Jbo/0k/sIOXIJu51IZxEAt27n77xspFEfL6SqKUR72A= diff --git a/examples/pubsub/go.mod b/examples/pubsub/go.mod index 47804ae107..272d5c4d68 100644 --- a/examples/pubsub/go.mod +++ b/examples/pubsub/go.mod @@ -22,7 +22,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -35,6 +35,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.1 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/pubsub/go.sum b/examples/pubsub/go.sum index b6e37aa00d..f026f077c0 100644 --- a/examples/pubsub/go.sum +++ b/examples/pubsub/go.sum @@ -41,8 +41,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -99,6 +99,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.2.3 h1:yk9/cqRKtT9wXZSsRH9 github.com/googleapis/enterprise-certificate-proxy v0.2.3/go.mod h1:AwSRAtLfXpU5Nm3pW+v7rGDHp09LsPtGY9MduiEsR9k= github.com/googleapis/gax-go/v2 v2.7.1 h1:gF4c0zjUP2H/s/hEGyLA3I0fA2ZWjzYiONAD6cvPr8A= github.com/googleapis/gax-go/v2 v2.7.1/go.mod h1:4orTrqY6hXxxaUL4LHIPl6lGo8vAE38/qKbhSAKP6QI= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -292,6 +294,8 @@ google.golang.org/protobuf v1.29.1 h1:7QBf+IK2gx70Ap/hDsOmam3GE0v9HicjfEdAxE62Uo google.golang.org/protobuf v1.29.1/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.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/spanner/go.mod b/examples/spanner/go.mod index 94cd23d7e9..cbb04a7a94 100644 --- a/examples/spanner/go.mod +++ b/examples/spanner/go.mod @@ -28,7 +28,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/envoyproxy/go-control-plane v0.10.3 // indirect @@ -43,6 +43,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect github.com/googleapis/gax-go/v2 v2.7.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.11.13 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/examples/spanner/go.sum b/examples/spanner/go.sum index 6468c06049..869c2e39ae 100644 --- a/examples/spanner/go.sum +++ b/examples/spanner/go.sum @@ -97,8 +97,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -204,6 +204,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -616,6 +618,8 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/examples/toxiproxy/go.mod b/examples/toxiproxy/go.mod index 8114cd2a57..2abfc0df20 100644 --- a/examples/toxiproxy/go.mod +++ b/examples/toxiproxy/go.mod @@ -20,7 +20,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -28,6 +28,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.11.13 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/examples/toxiproxy/go.sum b/examples/toxiproxy/go.sum index d2fbd9b980..ceb3c20e38 100644 --- a/examples/toxiproxy/go.sum +++ b/examples/toxiproxy/go.sum @@ -43,8 +43,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -100,6 +100,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.11.13 h1:eSvu8Tmq6j2psUJqJrLcWH6K3w5Dwc+qipbaA6eVEN4= @@ -296,6 +298,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/generic.go b/generic.go index ce79aa1100..b7b10efe03 100644 --- a/generic.go +++ b/generic.go @@ -5,6 +5,12 @@ import ( "errors" "fmt" "sync" + "time" + + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/network" + "github.com/imdario/mergo" + "github.com/testcontainers/testcontainers-go/wait" ) var ( @@ -21,6 +27,61 @@ type GenericContainerRequest struct { Reuse bool // reuse an existing container if it exists or create a new one. a container name mustn't be empty } +// CustomizeRequestOption is a type that can be used to configure the Testcontainers container request. +// The passed request will be merged with the default one. +type CustomizeRequestOption func(req *GenericContainerRequest) + +// CustomizeRequest returns a function that can be used to merge the passed container request with the one that is used by the container. +// Slices and Maps will be appended. +func CustomizeRequest(src GenericContainerRequest) CustomizeRequestOption { + return func(req *GenericContainerRequest) { + if err := mergo.Merge(req, &src, mergo.WithOverride, mergo.WithAppendSlice); err != nil { + fmt.Printf("error merging container request, keeping the original one. Error: %v", err) + return + } + } +} + +// WithImage sets the image for a container +func WithImage(image string) CustomizeRequestOption { + return func(req *GenericContainerRequest) { + req.Image = image + } +} + +// WithConfigModifier allows to override the default container config +func WithConfigModifier(modifier func(config *container.Config)) CustomizeRequestOption { + return func(req *GenericContainerRequest) { + req.ConfigModifier = modifier + } +} + +// WithEndpointSettingsModifier allows to override the default endpoint settings +func WithEndpointSettingsModifier(modifier func(settings map[string]*network.EndpointSettings)) CustomizeRequestOption { + return func(req *GenericContainerRequest) { + req.EnpointSettingsModifier = modifier + } +} + +// WithHostConfigModifier allows to override the default host config +func WithHostConfigModifier(modifier func(hostConfig *container.HostConfig)) CustomizeRequestOption { + return func(req *GenericContainerRequest) { + req.HostConfigModifier = modifier + } +} + +// WithWaitStrategy sets the wait strategy for a container, using 60 seconds as deadline +func WithWaitStrategy(strategies ...wait.Strategy) CustomizeRequestOption { + return WithWaitStrategyAndDeadline(60*time.Second, strategies...) +} + +// WithWaitStrategyAndDeadline sets the wait strategy for a container, including deadline +func WithWaitStrategyAndDeadline(deadline time.Duration, strategies ...wait.Strategy) CustomizeRequestOption { + return func(req *GenericContainerRequest) { + req.WaitingFor = wait.ForAll(strategies...).WithDeadline(deadline) + } +} + // GenericNetworkRequest represents parameters to a generic network type GenericNetworkRequest struct { NetworkRequest // embedded request for provider diff --git a/go.mod b/go.mod index b9a4af7b8a..44fa3e2d0f 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/docker/go-connections v0.4.0 github.com/docker/go-units v0.5.0 github.com/google/uuid v1.3.0 + github.com/imdario/mergo v0.3.12 github.com/magiconair/properties v1.8.7 github.com/moby/term v0.0.0-20221128092401-c43b287e0e0f github.com/opencontainers/image-spec v1.1.0-rc2 diff --git a/go.sum b/go.sum index de01a00331..dfb1a7e01d 100644 --- a/go.sum +++ b/go.sum @@ -95,6 +95,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.11.13 h1:eSvu8Tmq6j2psUJqJrLcWH6K3w5Dwc+qipbaA6eVEN4= @@ -304,6 +306,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/modulegen/_template/docs_example.md.tmpl b/modulegen/_template/docs_example.md.tmpl index 8b63cb3a56..67f99a5f9a 100644 --- a/modulegen/_template/docs_example.md.tmpl +++ b/modulegen/_template/docs_example.md.tmpl @@ -17,3 +17,47 @@ go get github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }} {{ codeinclude "" }} [Test for a {{ $title }} container](../../{{ ParentDir }}/{{ $lower }}/{{ $lower }}_test.go) {{ codeinclude "" }} + +## Module reference + +The {{ $title }} module exposes one entrypoint function to create the {{ $title }} container, and this function receives two parameters: + +```golang +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*{{ $title }}Container, error) +``` + +- `context.Context`, the Go context. +- `testcontainers.CustomizeRequestOption`, a variadic argument for passing options. + +### Container Options + +When starting the {{ $title }} container, you can pass options in a variadic way to configure it. + +#### Image + +If you need to set a different {{ $title }} Docker image, you can use `testcontainers.WithImage` with a valid Docker image +for {{ $title }}. E.g. `testcontainers.WithImage("{{ .Image }}")`. + +#### Wait Strategies + +If you need to set a different wait strategy for {{ $title }}, you can use `testcontainers.WithWaitStrategy` with a valid wait strategy +for {{ $title }}. + +!!!info + The default deadline for the wait strategy is 60 seconds. + +At the same time, it's possible to set a wait strategy and a custom deadline with `testcontainers.WithWaitStrategyAndDeadline`. + +#### Docker type modifiers + +If you need an advanced configuration for {{ $title }}, you can leverage the following Docker type modifiers: + +- `testcontainers.WithConfigModifier` +- `testcontainers.WithHostConfigModifier` +- `testcontainers.WithEndpointSettingsModifier` + +Please read the [Create containers: Advanced Settings](../features/creating_container.md#advanced-settings) documentation for more information. + +### Container Methods + +The {{ $title }} container exposes the following methods: diff --git a/modulegen/_template/example.go.tmpl b/modulegen/_template/example.go.tmpl index 4936388a94..34b96df089 100644 --- a/modulegen/_template/example.go.tmpl +++ b/modulegen/_template/example.go.tmpl @@ -12,10 +12,15 @@ type {{ $containerName }} struct { } // {{ $entrypoint }} creates an instance of the {{ $title }} container type -func {{ $entrypoint }}(ctx context.Context) (*{{ $containerName }}, error) { +func {{ $entrypoint }}(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*{{ $containerName }}, error) { req := testcontainers.ContainerRequest{ Image: "{{ .Image }}", } + + for _, opt := range opts { + opt(&req) + } + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: req, Started: true, diff --git a/modulegen/main.go b/modulegen/main.go index d5e6b8b4ed..a4ee7fb3bf 100644 --- a/modulegen/main.go +++ b/modulegen/main.go @@ -59,13 +59,13 @@ func (e *Example) ContainerName() string { } // Entrypoint returns the name of the entrypoint function, which is the lower-cased title of the example -// If the example is a module, the entrypoint will be "StartContainer" +// If the example is a module, the entrypoint will be "RunContainer" func (e *Example) Entrypoint() string { if e.IsModule { - return "StartContainer" + return "RunContainer" } - return "startContainer" + return "runContainer" } func (e *Example) Lower() string { diff --git a/modulegen/main_test.go b/modulegen/main_test.go index 0baffc9e22..e886fb5a19 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -27,7 +27,7 @@ func TestExample(t *testing.T) { TitleName: "MongoDB", }, expectedContainerName: "MongoDBContainer", - expectedEntrypoint: "StartContainer", + expectedEntrypoint: "RunContainer", expectedTitle: "MongoDB", }, { @@ -38,7 +38,7 @@ func TestExample(t *testing.T) { Image: "mongodb:latest", }, expectedContainerName: "MongodbContainer", - expectedEntrypoint: "StartContainer", + expectedEntrypoint: "RunContainer", expectedTitle: "Mongodb", }, { @@ -50,7 +50,7 @@ func TestExample(t *testing.T) { TitleName: "MongoDB", }, expectedContainerName: "mongoDBContainer", - expectedEntrypoint: "startContainer", + expectedEntrypoint: "runContainer", expectedTitle: "MongoDB", }, { @@ -61,7 +61,7 @@ func TestExample(t *testing.T) { Image: "mongodb:latest", }, expectedContainerName: "mongodbContainer", - expectedEntrypoint: "startContainer", + expectedEntrypoint: "runContainer", expectedTitle: "Mongodb", }, } @@ -422,6 +422,9 @@ func assertExampleDocContent(t *testing.T, example Example, exampleDocFile strin assert.Equal(t, data[16], "") assert.Equal(t, data[17], "[Test for a "+title+" container](../../"+example.ParentDir()+"/"+lower+"/"+lower+"_test.go)") assert.Equal(t, data[18], "") + assert.Equal(t, data[22], "The "+title+" module exposes one entrypoint function to create the "+title+" container, and this function receives two parameters:") + assert.True(t, strings.HasSuffix(data[25], "(*"+title+"Container, error)")) + assert.Equal(t, "for "+title+". E.g. `testcontainers.WithImage(\""+example.Image+"\")`.", data[38]) } // assert content example test @@ -450,9 +453,9 @@ func assertExampleContent(t *testing.T, example Example, exampleFile string) { assert.Equal(t, data[8], "// "+containerName+" represents the "+exampleName+" container type used in the module") assert.Equal(t, data[9], "type "+containerName+" struct {") assert.Equal(t, data[13], "// "+entrypoint+" creates an instance of the "+exampleName+" container type") - assert.Equal(t, data[14], "func "+entrypoint+"(ctx context.Context) (*"+containerName+", error) {") + assert.Equal(t, data[14], "func "+entrypoint+"(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*"+containerName+", error) {") assert.Equal(t, data[16], "\t\tImage: \""+example.Image+"\",") - assert.Equal(t, data[26], "\treturn &"+containerName+"{Container: container}, nil") + assert.Equal(t, data[31], "\treturn &"+containerName+"{Container: container}, nil") } // assert content GitHub workflow for the example diff --git a/modules/couchbase/go.mod b/modules/couchbase/go.mod index e79b5887a6..60872fde04 100644 --- a/modules/couchbase/go.mod +++ b/modules/couchbase/go.mod @@ -19,7 +19,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect @@ -28,6 +28,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/modules/couchbase/go.sum b/modules/couchbase/go.sum index 3367afb213..951b0d4382 100644 --- a/modules/couchbase/go.sum +++ b/modules/couchbase/go.sum @@ -43,8 +43,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -100,6 +100,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -302,6 +304,8 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw 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.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/modules/localstack/go.mod b/modules/localstack/go.mod index 7bc621e8f8..38dbc8c1b8 100644 --- a/modules/localstack/go.mod +++ b/modules/localstack/go.mod @@ -39,7 +39,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect diff --git a/modules/localstack/go.sum b/modules/localstack/go.sum index 4e9702e803..8a7a28fe2c 100644 --- a/modules/localstack/go.sum +++ b/modules/localstack/go.sum @@ -75,8 +75,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= diff --git a/modules/localstack/types_test.go b/modules/localstack/types_test.go deleted file mode 100644 index faae146e51..0000000000 --- a/modules/localstack/types_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package localstack - -import ( - "context" - "testing" - - "github.com/stretchr/testify/assert" - testcontainers "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/wait" -) - -func TestOverrideContainerRequest(t *testing.T) { - req := testcontainers.ContainerRequest{ - Env: map[string]string{}, - Image: "foo", - ExposedPorts: []string{}, - WaitingFor: wait.ForNop( - func(ctx context.Context, target wait.StrategyTarget) error { - return nil - }, - ), - Networks: []string{"foo", "bar", "baaz"}, - NetworkAliases: map[string][]string{ - "foo": {"foo0", "foo1", "foo2", "foo3"}, - }, - } - - merged := OverrideContainerRequest(testcontainers.ContainerRequest{ - Env: map[string]string{ - "FOO": "BAR", - }, - Image: "bar", - ExposedPorts: []string{"12345/tcp"}, - Networks: []string{"foo1", "bar1"}, - NetworkAliases: map[string][]string{ - "foo1": {"bar"}, - }, - WaitingFor: wait.ForLog("foo"), - })(req) - - assert.Equal(t, "BAR", merged.Env["FOO"]) - assert.Equal(t, "bar", merged.Image) - assert.Equal(t, []string{"12345/tcp"}, merged.ExposedPorts) - assert.Equal(t, []string{"foo1", "bar1"}, merged.Networks) - assert.Equal(t, []string{"foo0", "foo1", "foo2", "foo3"}, merged.NetworkAliases["foo"]) - assert.Equal(t, []string{"bar"}, merged.NetworkAliases["foo1"]) - assert.Equal(t, wait.ForLog("foo"), merged.WaitingFor) -} diff --git a/modules/mysql/go.mod b/modules/mysql/go.mod index ee1866ed0a..1ebcff6d25 100644 --- a/modules/mysql/go.mod +++ b/modules/mysql/go.mod @@ -16,7 +16,7 @@ require ( github.com/cpuguy83/dockercfg v0.3.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -25,6 +25,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/modules/mysql/go.sum b/modules/mysql/go.sum index c9452c8142..0c9f8fa560 100644 --- a/modules/mysql/go.sum +++ b/modules/mysql/go.sum @@ -37,8 +37,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -94,6 +94,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -284,6 +286,8 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw 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.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= gotest.tools/gotestsum v1.9.0 h1:Jbo/0k/sIOXIJu51IZxEAt27n77xspFEfL6SqKUR72A= diff --git a/modules/mysql/mysql.go b/modules/mysql/mysql.go index 8408075e21..4cbb8e605e 100644 --- a/modules/mysql/mysql.go +++ b/modules/mysql/mysql.go @@ -3,10 +3,11 @@ package mysql import ( "context" "fmt" - "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/wait" "path/filepath" "strings" + + "github.com/testcontainers/testcontainers-go" + "github.com/testcontainers/testcontainers-go/wait" ) const rootUser = "root" @@ -23,10 +24,8 @@ type MySQLContainer struct { database string } -type MySQLContainerOption func(req *testcontainers.ContainerRequest) - -// StartContainer creates an instance of the MySQL container type -func StartContainer(ctx context.Context, opts ...MySQLContainerOption) (*MySQLContainer, error) { +// RunContainer creates an instance of the MySQL container type +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*MySQLContainer, error) { req := testcontainers.ContainerRequest{ Image: defaultImage, ExposedPorts: []string{"3306/tcp", "33060/tcp"}, @@ -38,7 +37,7 @@ func StartContainer(ctx context.Context, opts ...MySQLContainerOption) (*MySQLCo WaitingFor: wait.ForLog("port: 3306 MySQL Community Server"), } - opts = append(opts, func(req *testcontainers.ContainerRequest) { + opts = append(opts, func(req *testcontainers.GenericContainerRequest) { username := req.Env["MYSQL_USER"] password := req.Env["MYSQL_PASSWORD"] if strings.EqualFold(rootUser, username) { @@ -52,8 +51,12 @@ func StartContainer(ctx context.Context, opts ...MySQLContainerOption) (*MySQLCo } }) + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + } for _, opt := range opts { - opt(&req) + opt(&genericContainerReq) } username, ok := req.Env["MYSQL_USER"] @@ -66,10 +69,7 @@ func StartContainer(ctx context.Context, opts ...MySQLContainerOption) (*MySQLCo return nil, fmt.Errorf("empty password can be used only with the root user") } - container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ - ContainerRequest: req, - Started: true, - }) + container, err := testcontainers.GenericContainer(ctx, genericContainerReq) if err != nil { return nil, err } @@ -102,37 +102,26 @@ func (c *MySQLContainer) ConnectionString(ctx context.Context, args ...string) ( return connectionString, nil } -// WithImage sets the image to be used for the mysql container -func WithImage(image string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { - if image == "" { - image = "mysql:8" - } - - req.Image = image - } -} - -func WithUsername(username string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithUsername(username string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Env["MYSQL_USER"] = username } } -func WithPassword(password string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithPassword(password string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Env["MYSQL_PASSWORD"] = password } } -func WithDatabase(database string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithDatabase(database string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Env["MYSQL_DATABASE"] = database } } -func WithConfigFile(configFile string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { cf := testcontainers.ContainerFile{ HostFilePath: configFile, ContainerFilePath: "/etc/mysql/conf.d/my.cnf", @@ -142,8 +131,8 @@ func WithConfigFile(configFile string) func(req *testcontainers.ContainerRequest } } -func WithScripts(scripts ...string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithScripts(scripts ...string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { var initScripts []testcontainers.ContainerFile for _, script := range scripts { cf := testcontainers.ContainerFile{ diff --git a/modules/mysql/mysql_test.go b/modules/mysql/mysql_test.go index 19987ee264..c38653007e 100644 --- a/modules/mysql/mysql_test.go +++ b/modules/mysql/mysql_test.go @@ -8,13 +8,14 @@ import ( // Import mysql into the scope of this package (required) _ "github.com/go-sql-driver/mysql" + "github.com/testcontainers/testcontainers-go" ) func TestMySQL(t *testing.T) { ctx := context.Background() // createMysqlContainer { - container, err := StartContainer(ctx) + container, err := RunContainer(ctx) if err != nil { t.Fatal(err) } @@ -52,7 +53,7 @@ func TestMySQL(t *testing.T) { func TestMySQLWithNonRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - _, err := StartContainer(ctx, + _, err := RunContainer(ctx, WithDatabase("foo"), WithUsername("test"), WithPassword("")) @@ -65,7 +66,7 @@ func TestMySQLWithRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() // customInitialization { - container, err := StartContainer(ctx, + container, err := RunContainer(ctx, WithDatabase("foo"), WithUsername("root"), WithPassword("")) @@ -107,7 +108,7 @@ func TestMySQLWithConfigFile(t *testing.T) { ctx := context.Background() // withConfigFile { - container, err := StartContainer(ctx, WithImage("mysql:5.6.51"), + container, err := RunContainer(ctx, testcontainers.WithImage("mysql:5.6"), WithConfigFile("./testdata/my.cnf")) if err != nil { t.Fatal(err) @@ -153,7 +154,7 @@ func TestMySQLWithScripts(t *testing.T) { ctx := context.Background() // withScripts { - container, err := StartContainer(ctx, + container, err := RunContainer(ctx, WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) diff --git a/modules/neo4j/config.go b/modules/neo4j/config.go index cbf27e65a6..b0a0dd6da4 100644 --- a/modules/neo4j/config.go +++ b/modules/neo4j/config.go @@ -3,19 +3,10 @@ package neo4j import ( "errors" "fmt" - "github.com/testcontainers/testcontainers-go" "strings" -) - -type Option func(*config) -type config struct { - imageCoordinates string - adminPassword string - labsPlugins []string - neo4jSettings map[string]string - logger testcontainers.Logging -} + "github.com/testcontainers/testcontainers-go" +) type LabsPlugin string @@ -29,35 +20,36 @@ const ( ) // WithoutAuthentication disables authentication. -func WithoutAuthentication() Option { +func WithoutAuthentication() testcontainers.CustomizeRequestOption { return WithAdminPassword("") } // WithAdminPassword sets the admin password for the default account // An empty string disables authentication. // The default password is "password". -func WithAdminPassword(adminPassword string) Option { - return func(c *config) { - c.adminPassword = adminPassword - } -} +func WithAdminPassword(adminPassword string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + pwd := "none" + if adminPassword != "" { + pwd = fmt.Sprintf("neo4j/%s", adminPassword) + } -// WithImageCoordinates sets the image coordinates of the Neo4j container. -func WithImageCoordinates(imageCoordinates string) Option { - return func(c *config) { - c.imageCoordinates = imageCoordinates + req.Env["NEO4J_AUTH"] = pwd } } // WithLabsPlugin registers one or more Neo4jLabsPlugin for download and server startup. // There might be plugins not supported by your selected version of Neo4j. -func WithLabsPlugin(plugins ...LabsPlugin) Option { - return func(c *config) { +func WithLabsPlugin(plugins ...LabsPlugin) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { rawPluginValues := make([]string, len(plugins)) for i := 0; i < len(plugins); i++ { rawPluginValues[i] = string(plugins[i]) } - c.labsPlugins = rawPluginValues + + if len(plugins) > 0 { + req.Env["NEO4JLABS_PLUGINS"] = fmt.Sprintf(`["%s"]`, strings.Join(rawPluginValues, `","`)) + } } } @@ -67,9 +59,9 @@ func WithLabsPlugin(plugins ...LabsPlugin) Option { // This function can be called multiple times. A warning is emitted if a key is overwritten. // See WithNeo4jSettings to add multiple settings at once // Note: credentials must be configured with WithAdminPassword -func WithNeo4jSetting(key, value string) Option { - return func(c *config) { - c.addSetting(key, value) +func WithNeo4jSetting(key, value string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + addSetting(req, key, value) } } @@ -79,52 +71,38 @@ func WithNeo4jSetting(key, value string) Option { // This function can be called multiple times. A warning is emitted if a key is overwritten. // See WithNeo4jSetting to add a single setting // Note: credentials must be configured with WithAdminPassword -func WithNeo4jSettings(settings map[string]string) Option { - return func(c *config) { +func WithNeo4jSettings(settings map[string]string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { for key, value := range settings { - c.addSetting(key, value) + addSetting(req, key, value) } } } // WithLogger sets a custom logger to be used by the container // Consider calling this before other "With functions" as these may generate logs -func WithLogger(logger testcontainers.Logging) Option { - return func(c *config) { - c.logger = logger +func WithLogger(logger testcontainers.Logging) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + req.Logger = logger } } -func (c *config) exportEnv() map[string]string { - env := c.neo4jSettings // set this first to ensure it has the lowest precedence - env["NEO4J_AUTH"] = c.authEnvVar() - if len(c.labsPlugins) > 0 { - env["NEO4JLABS_PLUGINS"] = c.labsPluginsEnvVar() - } - return env -} - -func (c *config) authEnvVar() string { - if c.adminPassword == "" { - return "none" - } - return fmt.Sprintf("neo4j/%s", c.adminPassword) -} - -func (c *config) labsPluginsEnvVar() string { - return fmt.Sprintf(`["%s"]`, strings.Join(c.labsPlugins, `","`)) -} - -func (c *config) addSetting(key string, newVal string) { +func addSetting(req *testcontainers.GenericContainerRequest, key string, newVal string) { normalizedKey := formatNeo4jConfig(key) - if oldVal, found := c.neo4jSettings[normalizedKey]; found { - c.logger.Printf("setting %q with value %q is now overwritten with value %q\n", []any{key, oldVal, newVal}...) + if oldVal, found := req.Env[normalizedKey]; found { + // make sure AUTH is not overwritten by a setting + if key == "AUTH" { + req.Logger.Printf("setting %q is not permitted, WithAdminPassword as already been set\n", normalizedKey) + return + } + + req.Logger.Printf("setting %q with value %q is now overwritten with value %q\n", []any{key, oldVal, newVal}...) } - c.neo4jSettings[normalizedKey] = newVal + req.Env[normalizedKey] = newVal } -func (c *config) validate() error { - if c.logger == nil { +func validate(req *testcontainers.GenericContainerRequest) error { + if req.Logger == nil { return errors.New("nil logger is not permitted") } return nil diff --git a/modules/neo4j/go.mod b/modules/neo4j/go.mod index e17552c6e1..46bdfaa32a 100644 --- a/modules/neo4j/go.mod +++ b/modules/neo4j/go.mod @@ -25,6 +25,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/modules/neo4j/go.sum b/modules/neo4j/go.sum index bd7559a9fc..00da5b44d5 100644 --- a/modules/neo4j/go.sum +++ b/modules/neo4j/go.sum @@ -92,6 +92,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -284,6 +286,8 @@ google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw 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.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= gotest.tools/gotestsum v1.9.0 h1:Jbo/0k/sIOXIJu51IZxEAt27n77xspFEfL6SqKUR72A= diff --git a/modules/neo4j/neo4j.go b/modules/neo4j/neo4j.go index e4b36e0150..d9206126c6 100644 --- a/modules/neo4j/neo4j.go +++ b/modules/neo4j/neo4j.go @@ -3,10 +3,11 @@ package neo4j import ( "context" "fmt" + "net/http" + "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" - "net/http" ) const defaultImageName = "neo4j" @@ -36,26 +37,14 @@ func (c Neo4jContainer) BoltUrl(ctx context.Context) (string, error) { return fmt.Sprintf("neo4j://%s:%d", host, mappedPort.Int()), nil } -// StartContainer creates an instance of the Neo4j container type -func StartContainer(ctx context.Context, options ...Option) (*Neo4jContainer, error) { - settings := &config{ - imageCoordinates: fmt.Sprintf("docker.io/%s:%s", defaultImageName, defaultTag), - adminPassword: "password", - neo4jSettings: map[string]string{}, - logger: testcontainers.Logger, - } - for _, option := range options { - option(settings) - } - - if err := settings.validate(); err != nil { - return nil, err - } - +// RunContainer creates an instance of the Neo4j container type +func RunContainer(ctx context.Context, options ...testcontainers.CustomizeRequestOption) (*Neo4jContainer, error) { httpPort, _ := nat.NewPort("tcp", defaultHttpPort) request := testcontainers.ContainerRequest{ - Image: settings.imageCoordinates, - Env: settings.exportEnv(), + Image: fmt.Sprintf("docker.io/%s:%s", defaultImageName, defaultTag), + Env: map[string]string{ + "NEO4J_AUTH": "none", + }, ExposedPorts: []string{ fmt.Sprintf("%s/tcp", defaultBoltPort), fmt.Sprintf("%s/tcp", defaultHttpPort), @@ -71,10 +60,29 @@ func StartContainer(ctx context.Context, options ...Option) (*Neo4jContainer, er }, }, } + + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: request, + Logger: testcontainers.Logger, + Started: true, + } + + if len(options) == 0 { + options = append(options, WithoutAuthentication()) + } + + for _, option := range options { + option(&genericContainerReq) + } + + err := validate(&genericContainerReq) + if err != nil { + return nil, err + } + container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ ContainerRequest: request, Started: true, - Logger: settings.logger, }) if err != nil { return nil, err diff --git a/modules/neo4j/neo4j_test.go b/modules/neo4j/neo4j_test.go index 1f8ce5355e..82bb738bb3 100644 --- a/modules/neo4j/neo4j_test.go +++ b/modules/neo4j/neo4j_test.go @@ -3,11 +3,12 @@ package neo4j_test import ( "context" "fmt" - neo "github.com/neo4j/neo4j-go-driver/v5/neo4j" - "github.com/testcontainers/testcontainers-go/modules/neo4j" "io" "strings" "testing" + + neo "github.com/neo4j/neo4j-go-driver/v5/neo4j" + "github.com/testcontainers/testcontainers-go/modules/neo4j" ) const testPassword = "letmein!" @@ -64,8 +65,20 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { ctx := context.Background() + outer.Run("without authentication", func(t *testing.T) { + container, err := neo4j.RunContainer(ctx) + if err != nil { + t.Fatalf("expected env to successfully run but did not: %s", err) + } + t.Cleanup(func() { + if err := container.Terminate(ctx); err != nil { + outer.Fatalf("failed to terminate container: %s", err) + } + }) + }) + outer.Run("ignores auth setting outside WithAdminPassword", func(t *testing.T) { - container, err := neo4j.StartContainer(ctx, + container, err := neo4j.RunContainer(ctx, neo4j.WithAdminPassword(testPassword), neo4j.WithNeo4jSetting("AUTH", "neo4j/thisisgonnabeignored"), ) @@ -87,7 +100,7 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { outer.Run("warns about overwrites of setting keys", func(t *testing.T) { logger := &inMemoryLogger{} - container, err := neo4j.StartContainer(ctx, + container, err := neo4j.RunContainer(ctx, neo4j.WithLogger(logger), // needs to go before WithNeo4jSetting and WithNeo4jSettings neo4j.WithAdminPassword(testPassword), neo4j.WithNeo4jSetting("some.key", "value1"), @@ -114,7 +127,7 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { }) outer.Run("rejects nil logger", func(t *testing.T) { - container, err := neo4j.StartContainer(ctx, neo4j.WithLogger(nil)) + container, err := neo4j.RunContainer(ctx, neo4j.WithLogger(nil)) if container != nil { t.Fatalf("container must not be created with nil logger") @@ -127,7 +140,7 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { func setupNeo4j(ctx context.Context, t *testing.T) *neo4j.Neo4jContainer { // neo4jCreateContainer { - container, err := neo4j.StartContainer(ctx, + container, err := neo4j.RunContainer(ctx, neo4j.WithAdminPassword(testPassword), neo4j.WithLabsPlugin(neo4j.Apoc), neo4j.WithNeo4jSetting("dbms.tx_log.rotation.size", "42M"), diff --git a/modules/postgres/go.mod b/modules/postgres/go.mod index 150bfd3597..96cf9f22fe 100644 --- a/modules/postgres/go.mod +++ b/modules/postgres/go.mod @@ -19,7 +19,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect github.com/fsnotify/fsnotify v1.5.4 // indirect @@ -27,6 +27,7 @@ require ( github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/kr/text v0.2.0 // indirect github.com/magiconair/properties v1.8.7 // indirect diff --git a/modules/postgres/go.sum b/modules/postgres/go.sum index 6814eebf38..0f90c23956 100644 --- a/modules/postgres/go.sum +++ b/modules/postgres/go.sum @@ -38,8 +38,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -93,6 +93,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -295,6 +297,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/modules/postgres/postgres.go b/modules/postgres/postgres.go index c33388561b..ae44c2cc9c 100644 --- a/modules/postgres/postgres.go +++ b/modules/postgres/postgres.go @@ -4,10 +4,8 @@ import ( "context" "fmt" "path/filepath" - "time" "github.com/testcontainers/testcontainers-go" - "github.com/testcontainers/testcontainers-go/wait" ) const defaultUser = "postgres" @@ -46,32 +44,11 @@ func (c *PostgresContainer) ConnectionString(ctx context.Context, args ...string return connStr, nil } -// PostgresContainerOption is a function that configures the postgres container, affecting the container request -type PostgresContainerOption func(req *testcontainers.ContainerRequest) - -// WithWaitStrategy sets the wait strategy for the postgres container -func WithWaitStrategy(strategies ...wait.Strategy) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { - req.WaitingFor = wait.ForAll(strategies...).WithDeadline(1 * time.Minute) - } -} - -// WithImage sets the image to be used for the postgres container -func WithImage(image string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { - if image == "" { - image = defaultPostgresImage - } - - req.Image = image - } -} - // WithConfigFile sets the config file to be used for the postgres container // It will also set the "config_file" parameter to the path of the config file // as a command line argument to the container -func WithConfigFile(cfg string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithConfigFile(cfg string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { cfgFile := testcontainers.ContainerFile{ HostFilePath: cfg, ContainerFilePath: "/etc/postgresql.conf", @@ -87,15 +64,15 @@ func WithConfigFile(cfg string) func(req *testcontainers.ContainerRequest) { // WithDatabase sets the initial database to be created when the container starts // It can be used to define a different name for the default database that is created when the image is first started. // If it is not specified, then the value of WithUser will be used. -func WithDatabase(dbName string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithDatabase(dbName string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Env["POSTGRES_DB"] = dbName } } // WithInitScripts sets the init scripts to be run when the container starts -func WithInitScripts(scripts ...string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { initScripts := []testcontainers.ContainerFile{} for _, script := range scripts { cf := testcontainers.ContainerFile{ @@ -112,8 +89,8 @@ func WithInitScripts(scripts ...string) func(req *testcontainers.ContainerReques // WithPassword sets the initial password of the user to be created when the container starts // It is required for you to use the PostgreSQL image. It must not be empty or undefined. // This environment variable sets the superuser password for PostgreSQL. -func WithPassword(password string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithPassword(password string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Env["POSTGRES_PASSWORD"] = password } } @@ -122,8 +99,8 @@ func WithPassword(password string) func(req *testcontainers.ContainerRequest) { // It is used in conjunction with WithPassword to set a user and its password. // It will create the specified user with superuser power and a database with the same name. // If it is not specified, then the default user of postgres will be used. -func WithUsername(user string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithUsername(user string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { if user == "" { user = defaultUser } @@ -132,8 +109,8 @@ func WithUsername(user string) func(req *testcontainers.ContainerRequest) { } } -// StartContainer creates an instance of the postgres container type -func StartContainer(ctx context.Context, opts ...PostgresContainerOption) (*PostgresContainer, error) { +// RunContainer creates an instance of the postgres container type +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*PostgresContainer, error) { req := testcontainers.ContainerRequest{ Image: defaultPostgresImage, Env: map[string]string{ @@ -145,14 +122,16 @@ func StartContainer(ctx context.Context, opts ...PostgresContainerOption) (*Post Cmd: []string{"postgres", "-c", "fsync=off"}, } + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + } + for _, opt := range opts { - opt(&req) + opt(&genericContainerReq) } - container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ - ContainerRequest: req, - Started: true, - }) + container, err := testcontainers.GenericContainer(ctx, genericContainerReq) if err != nil { return nil, err } diff --git a/modules/postgres/postgres_test.go b/modules/postgres/postgres_test.go index 0dc520af8a..fe91985faa 100644 --- a/modules/postgres/postgres_test.go +++ b/modules/postgres/postgres_test.go @@ -13,6 +13,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" ) @@ -52,12 +53,12 @@ func TestPostgres(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // postgresCreateContainer { - container, err := StartContainer(ctx, - WithImage(tt.image), + container, err := RunContainer(ctx, + testcontainers.WithImage(tt.image), WithDatabase(dbname), WithUsername(user), WithPassword(password), - WithWaitStrategy(tt.wait), + testcontainers.WithWaitStrategy(tt.wait), ) if err != nil { t.Fatal(err) @@ -104,12 +105,12 @@ func TestContainerWithWaitForSQL(t *testing.T) { t.Run("default query", func(t *testing.T) { // withInitialDatabase { - container, err := StartContainer( + container, err := RunContainer( ctx, WithDatabase(dbname), WithUsername(user), WithPassword(password), - WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL)), + testcontainers.WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL)), ) require.NoError(t, err) require.NotNil(t, container) @@ -117,24 +118,24 @@ func TestContainerWithWaitForSQL(t *testing.T) { }) t.Run("custom query", func(t *testing.T) { // withWaitStrategy { - container, err := StartContainer( + container, err := RunContainer( ctx, WithDatabase(dbname), WithUsername(user), WithPassword(password), - WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 10")), + testcontainers.WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 10")), ) require.NoError(t, err) require.NotNil(t, container) // } }) t.Run("custom bad query", func(t *testing.T) { - container, err := StartContainer( + container, err := RunContainer( ctx, WithDatabase(dbname), WithUsername(user), WithPassword(password), - WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 'a' from b")), + testcontainers.WithWaitStrategy(wait.ForSQL(nat.Port(port), "postgres", dbURL).WithStartupTimeout(time.Second*5).WithQuery("SELECT 'a' from b")), ) require.Error(t, err) require.Nil(t, container) @@ -145,12 +146,12 @@ func TestWithConfigFile(t *testing.T) { ctx := context.Background() // withConfigFile { - container, err := StartContainer(ctx, + container, err := RunContainer(ctx, WithConfigFile(filepath.Join("testdata", "my-postgres.conf")), WithDatabase(dbname), WithUsername(user), WithPassword(password), - WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)), + testcontainers.WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)), ) if err != nil { t.Fatal(err) @@ -177,13 +178,13 @@ func TestWithInitScript(t *testing.T) { ctx := context.Background() // withInitScripts { - container, err := StartContainer(ctx, - WithImage("docker.io/postgres:15.2-alpine"), + container, err := RunContainer(ctx, + testcontainers.WithImage("docker.io/postgres:15.2-alpine"), WithInitScripts(filepath.Join("testdata", "init-user-db.sh")), WithDatabase(dbname), WithUsername(user), WithPassword(password), - WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)), + testcontainers.WithWaitStrategy(wait.ForLog("database system is ready to accept connections").WithOccurrence(2).WithStartupTimeout(5*time.Second)), ) if err != nil { t.Fatal(err) diff --git a/modules/pulsar/go.mod b/modules/pulsar/go.mod index baf14021cc..c4df3bd55c 100644 --- a/modules/pulsar/go.mod +++ b/modules/pulsar/go.mod @@ -42,6 +42,7 @@ require ( github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/google/uuid v1.3.0 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/kr/text v0.2.0 // indirect github.com/linkedin/goavro/v2 v2.9.8 // indirect diff --git a/modules/pulsar/go.sum b/modules/pulsar/go.sum index 069d4ce552..01cc827319 100644 --- a/modules/pulsar/go.sum +++ b/modules/pulsar/go.sum @@ -264,6 +264,8 @@ github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/J github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jawher/mow.cli v1.0.4/go.mod h1:5hQj2V8g+qYmLUVWqu4Wuja1pI57M83EChYLVZ0sMKk= github.com/jawher/mow.cli v1.2.0/go.mod h1:y+pcA3jBAdo/GIZx/0rFjw/K2bVEODP9rfZOfaiq8Ko= diff --git a/modules/pulsar/pulsar.go b/modules/pulsar/pulsar.go index 818581b62d..112efd8916 100644 --- a/modules/pulsar/pulsar.go +++ b/modules/pulsar/pulsar.go @@ -6,8 +6,6 @@ import ( "io" "strings" - "github.com/docker/docker/api/types/container" - "github.com/docker/docker/api/types/network" "github.com/docker/go-connections/nat" "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/wait" @@ -67,32 +65,10 @@ func (c *Container) resolveURL(ctx context.Context, port nat.Port) (string, erro return fmt.Sprintf("%s://%s:%v", proto, host, pulsarPort.Int()), nil } -type ContainerRequest struct { - testcontainers.ContainerRequest - logConsumers []testcontainers.LogConsumer -} - -// ContainerOptions is a function that can be used to configure the Pulsar container -type ContainerOptions func(req *ContainerRequest) - -// WithConfigModifier allows to override the default container config -func WithConfigModifier(modifier func(config *container.Config)) ContainerOptions { - return func(req *ContainerRequest) { - req.ConfigModifier = modifier - } -} - -// WithEndpointSettingsModifier allows to override the default endpoint settings -func WithEndpointSettingsModifier(modifier func(settings map[string]*network.EndpointSettings)) ContainerOptions { - return func(req *ContainerRequest) { - req.EnpointSettingsModifier = modifier - } -} - // WithFunctionsWorker enables the functions worker, which will override the default pulsar command // and add a waiting strategy for the functions worker -func WithFunctionsWorker() ContainerOptions { - return func(req *ContainerRequest) { +func WithFunctionsWorker() testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Cmd = []string{"/bin/bash", "-c", defaultPulsarCmd} // add the waiting strategy for the functions worker @@ -105,41 +81,27 @@ func WithFunctionsWorker() ContainerOptions { } } -// WithHostConfigModifier allows to override the default host config -func WithHostConfigModifier(modifier func(hostConfig *container.HostConfig)) ContainerOptions { - return func(req *ContainerRequest) { - req.HostConfigModifier = modifier - } -} - -// WithLogConsumer allows to add log consumers to the container. They will be automatically started and stopped by the StartContainer function +// WithLogConsumers allows to add log consumers to the container. +// They will be automatically started and they will follow the container logs, // but it's a responsibility of the caller to stop them calling StopLogProducer -func WithLogConsumers(consumer ...testcontainers.LogConsumer) ContainerOptions { - return func(req *ContainerRequest) { - req.logConsumers = append(req.logConsumers, consumer...) +func (c *Container) WithLogConsumers(ctx context.Context, consumer ...testcontainers.LogConsumer) { + if len(c.LogConsumers) > 0 { + c.StartLogProducer(ctx) } -} - -// WithPulsarEnv allows to use the native APIs and set each variable with PULSAR_PREFIX_ as prefix. -func WithPulsarEnv(configVar string, configValue string) ContainerOptions { - return func(req *ContainerRequest) { - req.ContainerRequest.Env["PULSAR_PREFIX_"+configVar] = configValue + for _, lc := range c.LogConsumers { + c.FollowOutput(lc) } } -// WithPulsarImage allows to override the default Pulsar image -func WithPulsarImage(image string) ContainerOptions { - return func(req *ContainerRequest) { - if image == "" { - image = defaultPulsarImage - } - - req.Image = image +// WithPulsarEnv allows to use the native APIs and set each variable with PULSAR_PREFIX_ as prefix. +func WithPulsarEnv(configVar string, configValue string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { + req.Env["PULSAR_PREFIX_"+configVar] = configValue } } -func WithTransactions() ContainerOptions { - return func(req *ContainerRequest) { +func WithTransactions() testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { WithPulsarEnv("transactionCoordinatorEnabled", "true")(req) // add the waiting strategy for the transaction topic @@ -154,7 +116,7 @@ func WithTransactions() ContainerOptions { } } -// StartContainer creates an instance of the Pulsar container type, being possible to pass a custom request and options +// RunContainer creates an instance of the Pulsar container type, being possible to pass a custom request and options // The created container will use the following defaults: // - image: docker.io/apachepulsar/pulsar:2.10.2 // - exposed ports: 6650/tcp, 8080/tcp @@ -162,7 +124,7 @@ func WithTransactions() ContainerOptions { // - the Pulsar admin API ("/admin/v2/clusters") to be ready on port 8080/tcp and return the response `["standalone"]` // - the log message "Successfully updated the policies on namespace public/default" // - command: "/bin/bash -c /pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone --no-functions-worker -nss" -func StartContainer(ctx context.Context, opts ...ContainerOptions) (*Container, error) { +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*Container, error) { req := testcontainers.ContainerRequest{ Image: defaultPulsarImage, Env: map[string]string{}, @@ -171,33 +133,22 @@ func StartContainer(ctx context.Context, opts ...ContainerOptions) (*Container, Cmd: []string{"/bin/bash", "-c", strings.Join([]string{defaultPulsarCmd, detaultPulsarCmdWithoutFunctionsWorker}, " ")}, } - pulsarRequest := ContainerRequest{ + genericContainerReq := testcontainers.GenericContainerRequest{ ContainerRequest: req, - logConsumers: []testcontainers.LogConsumer{}, + Started: true, } for _, opt := range opts { - opt(&pulsarRequest) + opt(&genericContainerReq) } - c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ - ContainerRequest: pulsarRequest.ContainerRequest, - Started: true, - }) + c, err := testcontainers.GenericContainer(ctx, genericContainerReq) if err != nil { return nil, err } pc := &Container{ - Container: c, - LogConsumers: pulsarRequest.logConsumers, - } - - if len(pc.LogConsumers) > 0 { - c.StartLogProducer(ctx) - } - for _, lc := range pc.LogConsumers { - c.FollowOutput(lc) + Container: c, } return pc, nil diff --git a/modules/pulsar/pulsar_test.go b/modules/pulsar/pulsar_test.go index 833e457fb1..e87fa5edfb 100644 --- a/modules/pulsar/pulsar_test.go +++ b/modules/pulsar/pulsar_test.go @@ -43,31 +43,32 @@ func TestPulsar(t *testing.T) { require.NoError(t, err) tests := []struct { - name string - opts []testcontainerspulsar.ContainerOptions + name string + opts []testcontainers.CustomizeRequestOption + logConsumers []testcontainers.LogConsumer }{ { name: "default", }, { name: "with modifiers", - opts: []testcontainerspulsar.ContainerOptions{ + opts: []testcontainers.CustomizeRequestOption{ // setPulsarImage { - testcontainerspulsar.WithPulsarImage("docker.io/apachepulsar/pulsar:2.10.2"), + testcontainers.WithImage("docker.io/apachepulsar/pulsar:2.10.2"), // } // addPulsarEnv { testcontainerspulsar.WithPulsarEnv("brokerDeduplicationEnabled", "true"), // } // advancedDockerSettings { - testcontainerspulsar.WithConfigModifier(func(config *container.Config) { + testcontainers.WithConfigModifier(func(config *container.Config) { config.Env = append(config.Env, "PULSAR_MEM= -Xms512m -Xmx512m -XX:MaxDirectMemorySize=512m") }), - testcontainerspulsar.WithHostConfigModifier(func(hostConfig *container.HostConfig) { + testcontainers.WithHostConfigModifier(func(hostConfig *container.HostConfig) { hostConfig.Resources = container.Resources{ Memory: 1024 * 1024 * 1024, } }), - testcontainerspulsar.WithEndpointSettingsModifier(func(settings map[string]*network.EndpointSettings) { + testcontainers.WithEndpointSettingsModifier(func(settings map[string]*network.EndpointSettings) { settings[nwName] = &network.EndpointSettings{ Aliases: []string{"pulsar"}, } @@ -77,7 +78,7 @@ func TestPulsar(t *testing.T) { }, { name: "with functions worker", - opts: []testcontainerspulsar.ContainerOptions{ + opts: []testcontainers.CustomizeRequestOption{ // withFunctionsWorker { testcontainerspulsar.WithFunctionsWorker(), // } @@ -85,35 +86,38 @@ func TestPulsar(t *testing.T) { }, { name: "with transactions", - opts: []testcontainerspulsar.ContainerOptions{ + opts: []testcontainers.CustomizeRequestOption{ // withTransactions { testcontainerspulsar.WithTransactions(), // } }, }, { - name: "with log consumers", - opts: []testcontainerspulsar.ContainerOptions{ - // withLogConsumers { - testcontainerspulsar.WithLogConsumers(&testLogConsumer{}), - // } - }, + name: "with log consumers", + logConsumers: []testcontainers.LogConsumer{&testLogConsumer{}}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // startPulsarContainer { - c, err := testcontainerspulsar.StartContainer( + c, err := testcontainerspulsar.RunContainer( ctx, tt.opts..., ) - // } require.Nil(t, err) + defer func() { + err := c.Terminate(ctx) + require.Nil(t, err) + }() + // } + // withLogConsumers { if len(c.LogConsumers) > 0 { + c.WithLogConsumers(ctx, tt.logConsumers...) defer c.StopLogProducer() } + // } // getPulsarURLs { brokerURL, err := c.BrokerURL(ctx) diff --git a/modules/redis/go.mod b/modules/redis/go.mod index 2994449c44..d76bcb17a5 100644 --- a/modules/redis/go.mod +++ b/modules/redis/go.mod @@ -23,7 +23,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dnephin/pflag v1.0.7 // indirect github.com/docker/distribution v2.8.1+incompatible // indirect - github.com/docker/docker v23.0.1+incompatible // indirect + github.com/docker/docker v23.0.2+incompatible // indirect github.com/docker/go-connections v0.4.0 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/fatih/color v1.13.0 // indirect @@ -31,6 +31,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.11.13 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/modules/redis/go.sum b/modules/redis/go.sum index 721655532a..b961320a95 100644 --- a/modules/redis/go.sum +++ b/modules/redis/go.sum @@ -41,8 +41,8 @@ github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk= github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE= github.com/docker/distribution v2.8.1+incompatible h1:Q50tZOPR6T/hjNsyc9g8/syEs6bk8XXApsHjKukMl68= github.com/docker/distribution v2.8.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w= -github.com/docker/docker v23.0.1+incompatible h1:vjgvJZxprTTE1A37nm+CLNAdwu6xZekyoiVlUZEINcY= -github.com/docker/docker v23.0.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk= +github.com/docker/docker v23.0.2+incompatible h1:q81C2qQ/EhPm8COZMUGOQYh4qLv4Xu6CXELJ3WK/mlU= +github.com/docker/docker v23.0.2+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= @@ -98,6 +98,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.11.13 h1:eSvu8Tmq6j2psUJqJrLcWH6K3w5Dwc+qipbaA6eVEN4= @@ -301,6 +303,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/modules/redis/redis.go b/modules/redis/redis.go index e0728f5336..6b608ecc4b 100644 --- a/modules/redis/redis.go +++ b/modules/redis/redis.go @@ -46,22 +46,24 @@ func (c *RedisContainer) ConnectionString(ctx context.Context) (string, error) { return uri, nil } -// StartContainer creates an instance of the Redis container type -func StartContainer(ctx context.Context, opts ...RedisContainerOption) (*RedisContainer, error) { +// RunContainer creates an instance of the Redis container type +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*RedisContainer, error) { req := testcontainers.ContainerRequest{ Image: defaultImage, ExposedPorts: []string{"6379/tcp"}, WaitingFor: wait.ForLog("* Ready to accept connections"), } + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + } + for _, opt := range opts { - opt(&req) + opt(&genericContainerReq) } - container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ - ContainerRequest: req, - Started: true, - }) + container, err := testcontainers.GenericContainer(ctx, genericContainerReq) if err != nil { return nil, err } @@ -69,22 +71,12 @@ func StartContainer(ctx context.Context, opts ...RedisContainerOption) (*RedisCo return &RedisContainer{Container: container}, nil } -// RedisContainerOption is a function that configures the redis container, affecting the container request -type RedisContainerOption func(req *testcontainers.ContainerRequest) - -// WithImage sets the image to be used for the redis container -func WithImage(image string) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { - req.Image = image - } -} - // WithConfigFile sets the config file to be used for the redis container, and sets the command to run the redis server // using the passed config file -func WithConfigFile(configFile string) func(req *testcontainers.ContainerRequest) { +func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption { const defaultConfigFile = "/usr/local/redis.conf" - return func(req *testcontainers.ContainerRequest) { + return func(req *testcontainers.GenericContainerRequest) { cf := testcontainers.ContainerFile{ HostFilePath: configFile, ContainerFilePath: defaultConfigFile, @@ -110,8 +102,8 @@ func WithConfigFile(configFile string) func(req *testcontainers.ContainerRequest // WithLogLevel sets the log level for the redis server process // See https://redis.io/docs/reference/modules/modules-api-ref/#redismodule_log for more information. -func WithLogLevel(level LogLevel) func(req *testcontainers.ContainerRequest) { - return func(req *testcontainers.ContainerRequest) { +func WithLogLevel(level LogLevel) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { processRedisServerArgs(req, []string{"--loglevel", string(level)}) } } @@ -120,7 +112,7 @@ func WithLogLevel(level LogLevel) func(req *testcontainers.ContainerRequest) { // save the dataset every N seconds if there are at least M changes in the dataset. // This method allows Redis to benefit from copy-on-write semantics. // See https://redis.io/docs/management/persistence/#snapshotting for more information. -func WithSnapshotting(seconds int, changedKeys int) func(req *testcontainers.ContainerRequest) { +func WithSnapshotting(seconds int, changedKeys int) testcontainers.CustomizeRequestOption { if changedKeys < 1 { changedKeys = 1 } @@ -128,12 +120,12 @@ func WithSnapshotting(seconds int, changedKeys int) func(req *testcontainers.Con seconds = 1 } - return func(req *testcontainers.ContainerRequest) { + return func(req *testcontainers.GenericContainerRequest) { processRedisServerArgs(req, []string{"--save", fmt.Sprintf("%d", seconds), fmt.Sprintf("%d", changedKeys)}) } } -func processRedisServerArgs(req *testcontainers.ContainerRequest, args []string) { +func processRedisServerArgs(req *testcontainers.GenericContainerRequest, args []string) { if len(req.Cmd) == 0 { req.Cmd = append([]string{redisServerProcess}, args...) return diff --git a/modules/redis/redis_test.go b/modules/redis/redis_test.go index 79d615cf7c..b9cffc032e 100644 --- a/modules/redis/redis_test.go +++ b/modules/redis/redis_test.go @@ -17,7 +17,7 @@ func TestIntegrationSetGet(t *testing.T) { ctx := context.Background() // createRedisContainer { - redisContainer, err := StartContainer(ctx) + redisContainer, err := RunContainer(ctx) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -33,7 +33,7 @@ func TestRedisWithConfigFile(t *testing.T) { ctx := context.Background() // withConfigFile { - redisContainer, err := StartContainer(ctx, WithConfigFile(filepath.Join("testdata", "redis7.conf"))) + redisContainer, err := RunContainer(ctx, WithConfigFile(filepath.Join("testdata", "redis7.conf"))) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -77,7 +77,7 @@ func TestRedisWithImage(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { // withImage { - redisContainer, err := StartContainer(ctx, WithImage(tt.image), WithConfigFile(filepath.Join("testdata", "redis6.conf"))) + redisContainer, err := RunContainer(ctx, testcontainers.WithImage(tt.image), WithConfigFile(filepath.Join("testdata", "redis6.conf"))) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -95,7 +95,7 @@ func TestRedisWithLogLevel(t *testing.T) { ctx := context.Background() // withLogLevel { - redisContainer, err := StartContainer(ctx, WithLogLevel(LogLevelVerbose)) + redisContainer, err := RunContainer(ctx, WithLogLevel(LogLevelVerbose)) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -111,7 +111,7 @@ func TestRedisWithSnapshotting(t *testing.T) { ctx := context.Background() // withSnapshotting { - redisContainer, err := StartContainer(ctx, WithSnapshotting(10, 1)) + redisContainer, err := RunContainer(ctx, WithSnapshotting(10, 1)) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -196,8 +196,10 @@ func TestWithConfigFile(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - req := &testcontainers.ContainerRequest{ - Cmd: tt.cmds, + req := &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Cmd: tt.cmds, + }, } WithConfigFile("redis.conf")(req) @@ -232,8 +234,10 @@ func TestWithLogLevel(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - req := &testcontainers.ContainerRequest{ - Cmd: tt.cmds, + req := &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Cmd: tt.cmds, + }, } WithLogLevel(LogLevelDebug)(req) @@ -283,8 +287,10 @@ func TestWithSnapshotting(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - req := &testcontainers.ContainerRequest{ - Cmd: tt.cmds, + req := &testcontainers.GenericContainerRequest{ + ContainerRequest: testcontainers.ContainerRequest{ + Cmd: tt.cmds, + }, } WithSnapshotting(tt.seconds, tt.changedKeys)(req) diff --git a/modules/vault/go.mod b/modules/vault/go.mod index abaad7d8f1..470a439966 100644 --- a/modules/vault/go.mod +++ b/modules/vault/go.mod @@ -34,6 +34,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.2 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect + github.com/imdario/mergo v0.3.12 // indirect github.com/klauspost/compress v1.15.9 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-colorable v0.1.12 // indirect diff --git a/modules/vault/go.sum b/modules/vault/go.sum index 5dd809e14f..80200d4e64 100644 --- a/modules/vault/go.sum +++ b/modules/vault/go.sum @@ -109,6 +109,8 @@ github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9 github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= github.com/hashicorp/vault-client-go v0.2.0 h1:Zzf5D2kj7QmBZE2ZTdril1aJlujMptPatxslTkdDF+U= github.com/hashicorp/vault-client-go v0.2.0/go.mod h1:C9rbJeHeI1Dy/MXXd5YLrzRfAH27n6mARnhpvaW/8gk= +github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= +github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= 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.15.9 h1:wKRjX6JRtDdrE9qwa4b/Cip7ACOshUI4smpCQanqjSY= @@ -322,6 +324,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= 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= diff --git a/modules/vault/vault.go b/modules/vault/vault.go index 76d64dd8a2..bd34762754 100644 --- a/modules/vault/vault.go +++ b/modules/vault/vault.go @@ -3,9 +3,10 @@ package vault import ( "context" "fmt" - "github.com/testcontainers/testcontainers-go/wait" "strings" + "github.com/testcontainers/testcontainers-go/wait" + "github.com/docker/docker/api/types/container" "github.com/testcontainers/testcontainers-go" ) @@ -15,16 +16,13 @@ const ( defaultImageName = "hashicorp/vault:1.13.0" ) -// ContainerOptions is a function that can be used to configure the Vault container -type ContainerOptions func(req *testcontainers.ContainerRequest) - // VaultContainer represents the vault container type used in the module type VaultContainer struct { testcontainers.Container } -// StartContainer creates an instance of the vault container type -func StartContainer(ctx context.Context, opts ...ContainerOptions) (*VaultContainer, error) { +// RunContainer creates an instance of the vault container type +func RunContainer(ctx context.Context, opts ...testcontainers.CustomizeRequestOption) (*VaultContainer, error) { req := testcontainers.ContainerRequest{ Image: defaultImageName, ExposedPorts: []string{defaultPort + "/tcp"}, @@ -37,14 +35,16 @@ func StartContainer(ctx context.Context, opts ...ContainerOptions) (*VaultContai }, } + genericContainerReq := testcontainers.GenericContainerRequest{ + ContainerRequest: req, + Started: true, + } + for _, opt := range opts { - opt(&req) + opt(&genericContainerReq) } - container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ - ContainerRequest: req, - Started: true, - }) + container, err := testcontainers.GenericContainer(ctx, genericContainerReq) if err != nil { return nil, err } @@ -52,24 +52,17 @@ func StartContainer(ctx context.Context, opts ...ContainerOptions) (*VaultContai return &VaultContainer{container}, nil } -// WithImageName is an option function that sets the Docker image name for the Vault -func WithImageName(imageName string) ContainerOptions { - return func(req *testcontainers.ContainerRequest) { - req.Image = imageName - } -} - // WithToken is a container option function that sets the root token for the Vault -func WithToken(token string) ContainerOptions { - return func(req *testcontainers.ContainerRequest) { +func WithToken(token string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { req.Env["VAULT_DEV_ROOT_TOKEN_ID"] = token req.Env["VAULT_TOKEN"] = token } } // WithInitCommand is an option function that adds a set of initialization commands to the Vault's configuration -func WithInitCommand(commands ...string) ContainerOptions { - return func(req *testcontainers.ContainerRequest) { +func WithInitCommand(commands ...string) testcontainers.CustomizeRequestOption { + return func(req *testcontainers.GenericContainerRequest) { commandsList := make([]string, 0, len(commands)) for _, command := range commands { commandsList = append(commandsList, "vault "+command) diff --git a/modules/vault/vault_test.go b/modules/vault/vault_test.go index 18f6213b60..ca1fac69cd 100644 --- a/modules/vault/vault_test.go +++ b/modules/vault/vault_test.go @@ -12,6 +12,7 @@ import ( vaultClient "github.com/hashicorp/vault-client-go" "github.com/hashicorp/vault-client-go/schema" "github.com/stretchr/testify/assert" + "github.com/testcontainers/testcontainers-go" testcontainervault "github.com/testcontainers/testcontainers-go/modules/vault" "github.com/tidwall/gjson" ) @@ -27,9 +28,9 @@ var ( func TestMain(m *testing.M) { var err error - opts := []testcontainervault.ContainerOptions{ + opts := []testcontainers.CustomizeRequestOption{ // WithImageName { - testcontainervault.WithImageName("hashicorp/vault:1.13.0"), + testcontainers.WithImage("hashicorp/vault:1.13.0"), // } // WithToken { testcontainervault.WithToken(token), @@ -40,8 +41,8 @@ func TestMain(m *testing.M) { // } } - // StartContainer { - vault, err = testcontainervault.StartContainer(ctx, opts...) + // RunContainer { + vault, err = testcontainervault.RunContainer(ctx, opts...) // } if err != nil { log.Fatal(err)