From 8e4728b78824cde9248f86613848f26feb8eb35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 4 Jul 2024 10:21:34 +0200 Subject: [PATCH] feat: prepare modules for the new API (#2610) * feat: define new API for modules using Run It will force the image to be passed * chore: update module generator * docs: update module generation * fixup: modulegen * docs: update module pages * fix: lint * fix: more lint * fix: update test assertions * docs: update reference --- docs/features/common_functional_options.md | 8 ++--- docs/modules/artemis.md | 9 +++--- docs/modules/azurite.md | 9 +++--- docs/modules/cassandra.md | 9 +++--- docs/modules/chroma.md | 9 +++--- docs/modules/clickhouse.md | 9 +++--- docs/modules/cockroachdb.md | 9 +++--- docs/modules/consul.md | 9 +++--- docs/modules/couchbase.md | 17 ++++------ docs/modules/dolt.md | 9 +++--- docs/modules/elasticsearch.md | 11 ++++--- docs/modules/gcloud.md | 4 +-- docs/modules/inbucket.md | 9 +++--- docs/modules/index.md | 19 ++++++----- docs/modules/influxdb.md | 12 ++++--- docs/modules/k3s.md | 9 +++--- docs/modules/k6.md | 19 +++++------ docs/modules/kafka.md | 9 +++--- docs/modules/localstack.md | 10 +++--- docs/modules/mariadb.md | 9 +++--- docs/modules/milvus.md | 9 +++--- docs/modules/minio.md | 9 +++--- docs/modules/mockserver.md | 9 +++--- docs/modules/mongodb.md | 9 +++--- docs/modules/mssql.md | 9 +++--- docs/modules/mysql.md | 9 +++--- docs/modules/nats.md | 9 +++--- docs/modules/neo4j.md | 9 +++--- docs/modules/ollama.md | 9 +++--- docs/modules/openfga.md | 9 +++--- docs/modules/openldap.md | 9 +++--- docs/modules/opensearch.md | 9 +++--- docs/modules/postgres.md | 9 +++--- docs/modules/pulsar.md | 9 +++--- docs/modules/qdrant.md | 9 +++--- docs/modules/rabbitmq.md | 9 +++--- docs/modules/redis.md | 9 +++--- docs/modules/redpanda.md | 9 +++--- docs/modules/registry.md | 9 +++--- docs/modules/surrealdb.md | 9 +++--- docs/modules/vault.md | 20 ++++-------- docs/modules/vearch.md | 9 +++--- docs/modules/weaviate.md | 9 +++--- modulegen/_template/examples_test.go.tmpl | 3 +- modulegen/_template/module.go.tmpl | 4 +-- modulegen/_template/module.md.tmpl | 9 +++--- modulegen/_template/module_test.go.tmpl | 3 +- modulegen/internal/context/types.go | 6 ++-- modulegen/main_test.go | 36 ++++++++++----------- modules/artemis/artemis.go | 8 ++++- modules/artemis/artemis_test.go | 2 +- modules/artemis/examples_test.go | 7 ++-- modules/azurite/azurite.go | 8 ++++- modules/azurite/azurite_test.go | 3 +- modules/azurite/examples_test.go | 25 +++++++------- modules/cassandra/cassandra.go | 8 ++++- modules/cassandra/cassandra_test.go | 8 ++--- modules/cassandra/examples_test.go | 7 ++-- modules/chroma/chroma.go | 8 ++++- modules/chroma/chroma_test.go | 3 +- modules/chroma/examples_test.go | 8 ++--- modules/clickhouse/clickhouse.go | 10 ++++-- modules/clickhouse/clickhouse_test.go | 21 ++++++++---- modules/clickhouse/examples_test.go | 7 ++-- modules/cockroachdb/cockroachdb.go | 9 ++++-- modules/cockroachdb/cockroachdb_test.go | 14 ++++---- modules/cockroachdb/examples_test.go | 4 +-- modules/consul/consul.go | 9 +++++- modules/consul/consul_test.go | 2 +- modules/consul/examples_test.go | 13 +++----- modules/couchbase/couchbase.go | 16 ++++----- modules/couchbase/couchbase_test.go | 21 ++++++------ modules/couchbase/examples_test.go | 7 ++-- modules/dolt/dolt.go | 12 ++++--- modules/dolt/dolt_test.go | 17 ++++++---- modules/dolt/examples_test.go | 13 ++++---- modules/elasticsearch/elasticsearch.go | 14 ++++++-- modules/elasticsearch/elasticsearch_test.go | 12 +++---- modules/elasticsearch/examples_test.go | 17 +++++----- modules/gcloud/bigquery.go | 10 ++++-- modules/gcloud/bigquery_test.go | 5 ++- modules/gcloud/bigtable.go | 10 ++++-- modules/gcloud/bigtable_test.go | 5 ++- modules/gcloud/datastore.go | 10 ++++-- modules/gcloud/datastore_test.go | 5 ++- modules/gcloud/firestore.go | 10 ++++-- modules/gcloud/firestore_test.go | 5 ++- modules/gcloud/pubsub.go | 10 ++++-- modules/gcloud/pubsub_test.go | 5 ++- modules/gcloud/spanner.go | 10 ++++-- modules/gcloud/spanner_test.go | 5 ++- modules/inbucket/examples_test.go | 5 ++- modules/inbucket/inbucket.go | 8 ++++- modules/inbucket/inbucket_test.go | 4 +-- modules/influxdb/examples_test.go | 7 ++-- modules/influxdb/influxdb.go | 13 ++++---- modules/influxdb/influxdb_test.go | 16 ++++----- modules/k3s/k3s.go | 8 ++++- modules/k3s/k3s_example_test.go | 7 ++-- modules/k3s/k3s_test.go | 12 +++---- modules/k6/examples_test.go | 5 +-- modules/k6/k6.go | 8 ++++- modules/k6/k6_test.go | 2 +- modules/kafka/examples_test.go | 7 ++-- modules/kafka/kafka.go | 8 ++++- modules/kafka/kafka_test.go | 4 +-- modules/localstack/examples_test.go | 24 +++++++------- modules/localstack/localstack.go | 13 +++++--- modules/localstack/localstack_test.go | 12 +++---- modules/localstack/v1/s3_test.go | 2 +- modules/localstack/v2/s3_test.go | 2 +- modules/mariadb/examples_test.go | 7 ++-- modules/mariadb/mariadb.go | 13 ++++---- modules/mariadb/mariadb_test.go | 16 +++++---- modules/milvus/examples_test.go | 7 ++-- modules/milvus/milvus.go | 8 ++++- modules/milvus/milvus_test.go | 3 +- modules/minio/examples_test.go | 5 ++- modules/minio/minio.go | 9 ++++-- modules/minio/minio_test.go | 5 ++- modules/mockserver/examples_test.go | 9 +++--- modules/mockserver/mockserver.go | 11 ++++--- modules/mongodb/examples_test.go | 14 ++++---- modules/mongodb/mongodb.go | 11 ++++--- modules/mongodb/mongodb_test.go | 22 ++++++------- modules/mssql/examples_test.go | 7 ++-- modules/mssql/mssql.go | 9 ++++-- modules/mssql/mssql_test.go | 23 ++++++++----- modules/mysql/examples_test.go | 13 ++++---- modules/mysql/mysql.go | 13 ++++---- modules/mysql/mysql_test.go | 11 ++++--- modules/nats/examples_test.go | 22 ++++++------- modules/nats/nats.go | 8 ++++- modules/nats/nats_test.go | 2 +- modules/neo4j/examples_test.go | 7 ++-- modules/neo4j/neo4j.go | 23 +++++++------ modules/neo4j/neo4j_test.go | 22 +++++++------ modules/ollama/examples_test.go | 19 ++++------- modules/ollama/ollama.go | 9 +++++- modules/ollama/ollama_test.go | 11 +++---- modules/openfga/examples_test.go | 18 +++++------ modules/openfga/openfga.go | 8 ++++- modules/openfga/openfga_test.go | 3 +- modules/openldap/examples_test.go | 9 +++--- modules/openldap/openldap.go | 8 ++++- modules/openldap/openldap_test.go | 13 ++++---- modules/opensearch/examples_test.go | 7 ++-- modules/opensearch/opensearch.go | 8 ++++- modules/opensearch/opensearch_test.go | 3 +- modules/postgres/examples_test.go | 6 ++-- modules/postgres/postgres.go | 17 ++++++---- modules/postgres/postgres_test.go | 28 +++++++++------- modules/pulsar/examples_test.go | 7 ++-- modules/pulsar/pulsar.go | 13 +++++--- modules/pulsar/pulsar_test.go | 4 +-- modules/qdrant/examples_test.go | 9 +++--- modules/qdrant/qdrant.go | 8 ++++- modules/qdrant/qdrant_test.go | 3 +- modules/rabbitmq/examples_test.go | 30 ++++++++--------- modules/rabbitmq/rabbitmq.go | 8 ++++- modules/rabbitmq/rabbitmq_test.go | 8 ++--- modules/redis/examples_test.go | 7 ++-- modules/redis/redis.go | 11 ++++--- modules/redis/redis_test.go | 11 +++---- modules/redpanda/examples_test.go | 5 +-- modules/redpanda/redpanda.go | 10 ++++-- modules/redpanda/redpanda_test.go | 28 ++++++++-------- modules/registry/examples_test.go | 16 ++++----- modules/registry/registry.go | 8 ++++- modules/registry/registry_test.go | 14 ++++---- modules/surrealdb/examples_test.go | 5 ++- modules/surrealdb/surrealdb.go | 8 ++++- modules/surrealdb/surrealdb_test.go | 6 ++-- modules/vault/examples_test.go | 12 +++---- modules/vault/vault.go | 13 +++++--- modules/vault/vault_test.go | 5 +-- modules/vearch/examples_test.go | 5 ++- modules/vearch/vearch.go | 8 ++++- modules/vearch/vearch_test.go | 3 +- modules/weaviate/examples_test.go | 13 ++++---- modules/weaviate/weaviate.go | 9 ++++-- modules/weaviate/weaviate_test.go | 3 +- options.go | 1 + 183 files changed, 1016 insertions(+), 799 deletions(-) diff --git a/docs/features/common_functional_options.md b/docs/features/common_functional_options.md index 209ad654df..d559a3ee7f 100644 --- a/docs/features/common_functional_options.md +++ b/docs/features/common_functional_options.md @@ -22,7 +22,7 @@ Using the `WithImageSubstitutors` options, you could define your own substitutio If you need to either pass additional environment variables to a container or override them, you can use `testcontainers.WithEnv` for example: ```golang -postgres, err = postgresModule.RunContainer(ctx, testcontainers.WithEnv(map[string]string{"POSTGRES_INITDB_ARGS": "--no-sync"})) +postgres, err = postgresModule.Run(ctx, "postgres:15-alpine", testcontainers.WithEnv(map[string]string{"POSTGRES_INITDB_ARGS": "--no-sync"})) ``` #### WithHostPortAccess @@ -32,7 +32,7 @@ postgres, err = postgresModule.RunContainer(ctx, testcontainers.WithEnv(map[stri If you need to access a port that is already running in the host, you can use `testcontainers.WithHostPortAccess` for example: ```golang -postgres, err = postgresModule.RunContainer(ctx, testcontainers.WithHostPortAccess(8080)) +postgres, err = postgresModule.Run(ctx, "postgres:15-alpine", testcontainers.WithHostPortAccess(8080)) ``` To understand more about this feature, please read the [Exposing host ports to the container](/features/networking/#exposing-host-ports-to-the-container) documentation. @@ -70,7 +70,7 @@ useful context instead of appearing out of band. ```golang func TestHandler(t *testing.T) { logger := TestLogger(t) - _, err := postgresModule.RunContainer(ctx, testcontainers.WithLogger(logger)) + _, err := postgresModule.Run(ctx, "postgres:15-alpine", testcontainers.WithLogger(logger)) require.NoError(t, err) // Do something with container. } @@ -150,7 +150,7 @@ Please read the [Create containers: Advanced Settings](/features/creating_contai This option will merge the customized request into the module's own `ContainerRequest`. ```go -container, err := RunContainer(ctx, +container, err := Run(ctx, "postgres:13-alpine", /* Other module options */ testcontainers.CustomizeRequest(testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ diff --git a/docs/modules/artemis.md b/docs/modules/artemis.md index 2195b1f250..82aa87c659 100644 --- a/docs/modules/artemis.md +++ b/docs/modules/artemis.md @@ -26,13 +26,14 @@ go get github.com/testcontainers/testcontainers-go/modules/artemis ## Module reference -The Artemis module exposes one entrypoint function to create the Artemis container, and this function receives two parameters: +The Artemis module exposes one entrypoint function to create the Artemis container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -41,8 +42,8 @@ When starting the Artemis container, you can pass options in a variadic way to c #### Image -If you need to set a different Artemis Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Artemis. E.g. `testcontainers.WithImage("docker.io/apache/activemq-artemis:2.30.0")`. +If you need to set a different Artemis Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/apache/activemq-artemis:2.30.0")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/azurite.md b/docs/modules/azurite.md index 89cd1df824..cde6c4c88f 100644 --- a/docs/modules/azurite.md +++ b/docs/modules/azurite.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/azurite ## Module reference -The Azurite module exposes one entrypoint function to create the Azurite container, and this function receives two parameters: +The Azurite module exposes one entrypoint function to create the Azurite container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Default Credentials @@ -45,8 +46,8 @@ When starting the Azurite container, you can pass options in a variadic way to c #### Image -If you need to set a different Azurite Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Azurite. E.g. `testcontainers.WithImage("mcr.microsoft.com/azure-storage/azurite:3.28.0")`. +If you need to set a different Azurite Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "mcr.microsoft.com/azure-storage/azurite:3.28.0")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/cassandra.md b/docs/modules/cassandra.md index a020db3832..ee235a3098 100644 --- a/docs/modules/cassandra.md +++ b/docs/modules/cassandra.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/cassandra ## Module reference -The Cassandra module exposes one entrypoint function to create the Cassandra container, and this function receives two parameters: +The Cassandra module exposes one entrypoint function to create the Cassandra container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Cassandra container, you can pass options in a variadic way to #### Image -If you need to set a different Cassandra Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Cassandra. E.g. `testcontainers.WithImage("cassandra:4.1.3")`. +If you need to set a different Cassandra Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "cassandra:4.1.3")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/chroma.md b/docs/modules/chroma.md index 4eb750e7f2..0a0ddf6de7 100644 --- a/docs/modules/chroma.md +++ b/docs/modules/chroma.md @@ -27,13 +27,14 @@ go get github.com/testcontainers/testcontainers-go/modules/chroma ## Module reference -The Chroma module exposes one entrypoint function to create the Chroma container, and this function receives two parameters: +The Chroma module exposes one entrypoint function to create the Chroma container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -42,8 +43,8 @@ When starting the Chroma container, you can pass options in a variadic way to co #### Image -If you need to set a different Chroma Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Chroma. E.g. `testcontainers.WithImage("chromadb/chroma:0.4.24")`. +If you need to set a different Chroma Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "chromadb/chroma:0.4.24")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/clickhouse.md b/docs/modules/clickhouse.md index 749ded3bec..c6dba6e40e 100644 --- a/docs/modules/clickhouse.md +++ b/docs/modules/clickhouse.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/clickhouse ## Module reference -The ClickHouse module exposes one entrypoint function to create the ClickHouse container, and this function receives two parameters: +The ClickHouse module exposes one entrypoint function to create the ClickHouse container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Ports @@ -45,8 +46,8 @@ When starting the ClickHouse container, you can pass options in a variadic way t #### Image -If you need to set a different ClickHouse Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for ClickHouse. E.g. `testcontainers.WithImage("clickhouse/clickhouse-server:23.3.8.21-alpine")`. +If you need to set a different ClickHouse Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "clickhouse/clickhouse-server:23.3.8.21-alpine")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/cockroachdb.md b/docs/modules/cockroachdb.md index 51c845b9f4..062b8302aa 100644 --- a/docs/modules/cockroachdb.md +++ b/docs/modules/cockroachdb.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/cockroachdb ## Module reference -The CockroachDB module exposes one entrypoint function to create the CockroachDB container, and this function receives two parameters: +The CockroachDB module exposes one entrypoint function to create the CockroachDB container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. !!!warning @@ -40,8 +41,8 @@ When starting the CockroachDB container, you can pass options in a variadic way #### Image -If you need to set a different CockroachDB Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for CockroachDB. E.g. `testcontainers.WithImage("cockroachdb/cockroach:latest-v23.1")`. +If you need to set a different CockroachDB Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "cockroachdb/cockroach:latest-v23.1")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/consul.md b/docs/modules/consul.md index e094efed9e..9cf026aed6 100644 --- a/docs/modules/consul.md +++ b/docs/modules/consul.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/consul ## Module reference -The Consul module exposes one entrypoint function to create the Consul container, and this function receives two parameters: +The Consul module exposes one entrypoint function to create the Consul container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ConsulContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ConsulContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Consul container, you can pass options in a variadic way to co #### Image -If you need to set a different Consul Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Consul. E.g. `testcontainers.WithImage("docker.io/hashicorp/consul:1.15")`. +If you need to set a different Consul Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/hashicorp/consul:1.15")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/couchbase.md b/docs/modules/couchbase.md index 6f3a8a1398..8b7944a364 100644 --- a/docs/modules/couchbase.md +++ b/docs/modules/couchbase.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/couchbase ## Module Reference -The Couchbase module exposes one entrypoint function to create the Couchbase container, and this function receives two parameters: +The Couchbase module exposes one entrypoint function to create the Couchbase container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. Once the container is started, it will perform the following operations, **in this particular order**: @@ -64,14 +65,8 @@ When starting the Couchbase container, you can pass options in a variadic way to #### Image -If you need to set a different Couchbase Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Couchbase. E.g. `testcontainers.WithImage("docker.io/couchbase:6.5.1")`. - -By default, the container will use the following Docker image: - - -[Default Docker image](../../modules/couchbase/couchbase.go) inside_block:defaultImage - +If you need to set a different Couchbase Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/couchbase:6.5.1")`. You can find the Docker images that are currently tested in this module, for the Enterprise and Community editions, in the following list: @@ -84,7 +79,7 @@ You can find the Docker images that are currently tested in this module, for the #### Credentials If you need to change the default credentials for the admin user, you can use `WithAdminCredentials(user, password)` with a valid username and password. -When the password has less than 6 characters, the container won't be created and the `RunContainer` function will throw an error. +When the password has less than 6 characters, the container won't be created and the `New` function will throw an error. !!!info In the case this optional function is not called, the default username is `Administrator` and the default password is `password`. diff --git a/docs/modules/dolt.md b/docs/modules/dolt.md index 6d4710e65f..7c91bfe00d 100644 --- a/docs/modules/dolt.md +++ b/docs/modules/dolt.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/dolt ## Module reference -The Dolt module exposes one entrypoint function to create the Dolt container, and this function receives two parameters: +The Dolt module exposes one entrypoint function to create the Dolt container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Dolt container, you can pass options in a variadic way to conf #### Image -If you need to set a different Dolt Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Dolt. E.g. `testcontainers.WithImage("dolthub/dolt-sql-server:1.32.4")`. +If you need to set a different Dolt Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "dolthub/dolt-sql-server:1.32.4")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/elasticsearch.md b/docs/modules/elasticsearch.md index 18c58dc5eb..52e7623f0c 100644 --- a/docs/modules/elasticsearch.md +++ b/docs/modules/elasticsearch.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/elasticsearch ## Module reference -The Elasticsearch module exposes one entrypoint function to create the Elasticsearch container, and this function receives two parameters: +The Elasticsearch module exposes one entrypoint function to create the Elasticsearch container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Elasticsearch container, you can pass options in a variadic wa #### Image -If you need to set a different Elasticsearch Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Elasticsearch. E.g. `testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.0.0")`. +If you need to set a different Elasticsearch Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.elastic.co/elasticsearch/elasticsearch:8.0.0")`. {% include "../features/common_functional_options.md" %} @@ -66,7 +67,7 @@ The Elasticsearch container exposes its settings in order to configure the clien [Create an HTTP client](../../modules/elasticsearch/elasticsearch_test.go) inside_block:createHTTPClient -The `esContainer` instance is obtained from the `elasticsearch.RunContainer` function. +The `esContainer` instance is obtained from the `elasticsearch.New` function. In the case you configured the Elasticsearch container to set up a password, you'll need to add the `Authorization` header to the request. You can use the `SetBasicAuth` method from the HTTP request to generate the header value. diff --git a/docs/modules/gcloud.md b/docs/modules/gcloud.md index a925a9be66..0ebbba1372 100644 --- a/docs/modules/gcloud.md +++ b/docs/modules/gcloud.md @@ -97,8 +97,8 @@ When starting any of the GCloud containers, you can pass options in a variadic w #### Image -If you need to set a different GCloud Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for GCloud. E.g. `testcontainers.WithImage("gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators")`. +If you need to set a different GCloud Docker image, you can set a valid Docker image as the second argument in the `RunXXX` function (`RunBigQuery, RunDatastore`, ...). +E.g. `RunXXX(context.Background(), "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/inbucket.md b/docs/modules/inbucket.md index eb94a0b918..ef29835ee7 100644 --- a/docs/modules/inbucket.md +++ b/docs/modules/inbucket.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/inbucket ## Module reference -The Inbucket module exposes one entrypoint function to create the Inbucket container, and this function receives two parameters: +The Inbucket module exposes one entrypoint function to create the Inbucket container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InbucketContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InbucketContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Inbucket container, you can pass options in a variadic way to #### Image -If you need to set a different Inbucket Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Inbucket. E.g. `testcontainers.WithImage("inbucket/inbucket:sha-2d409bb")`. +If you need to set a different Inbucket Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "inbucket/inbucket:sha-2d409bb")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/index.md b/docs/modules/index.md index b279765e9d..629787fedf 100644 --- a/docs/modules/index.md +++ b/docs/modules/index.md @@ -46,8 +46,8 @@ We have provided a command line tool to generate the scaffolding for the code of - a Go module for the example, including: - go.mod and go.sum files, including the current version of _Testcontainer for Go_. - a Go package named after the module, in lowercase - - a Go file for the creation of the container, using a dedicated struct in which the image flag is set as Docker image. - - a Go test file for running a simple test for your container, consuming the above struct. + - a Go file for the creation of the container. + - a Go test file for running a simple test for your container, consuming the above struct and using the image flag as Docker image for the container. - a Go examples file for running the example in the docs site, also adding them to [https://pkg.go.dev](https://pkg.go.dev). - a Makefile to run the tests in a consistent manner - a markdown file in the docs/modules directory including the snippets for both the creation of the container and a simple test. By default, this generated file will contain all the documentation for the module, including: @@ -72,7 +72,7 @@ We have provided a command line tool to generate the scaffolding for the code of | Flag | Short | Type | Required | Description | |---------|-------|--------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------| | --name | -n | string | Yes | Name of the module, use camel-case when needed. Only alphanumerical characters are allowed (leading character must be a letter). | -| --image | -i | string | Yes | Fully-qualified name of the Docker image to be used by the module (i.e. 'docker.io/org/project:tag') | +| --image | -i | string | Yes | Fully-qualified name of the Docker image to be used in the examples and tests (i.e. 'docker.io/org/project:tag') | | --title | -t | string | No | A variant of the name supporting mixed casing (i.e. 'MongoDB'). Only alphanumerical characters are allowed (leading character must be a letter). | @@ -101,10 +101,10 @@ go run . new module --name ${NAME_OF_YOUR_MODULE} --image "${REGISTRY}/${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. + The `StartContainer` function will be eventually deprecated and replaced with `Run`. 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 has to use composition to embed the `testcontainers.Container` type, promoting 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. +- Make sure a `Run` 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 in the function signature, 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 leveraging the `testcontainers.ContainerCustomizer` interface, that has one single method: `Customize(req *GenericContainerRequest) error`. !!!warning @@ -123,7 +123,7 @@ We are going to propose a set of steps to follow when adding types and methods t - We consider that a best practice for the options is define a function using the `With` prefix, that returns a function returning a modified `testcontainers.GenericContainerRequest` type. For that, the library already provides a `testcontainers.CustomizeRequestOption` type implementing the `ContainerCustomizer` interface, and we encourage you to use this type for creating your own customizer functions. - At the same time, you could need to create your own container customizers for your module. Make sure they implement the `testcontainers.ContainerCustomizer` interface. Defining your own customizer functions is useful when you need to transfer a certain state that is not present at the `ContainerRequest` for the container, possibly using an intermediate Config struct. -- 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. +- The options will be passed to the `Run` 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 // Config type represents an intermediate struct for transferring state from the options to the container @@ -131,12 +131,12 @@ type Config struct { data string } -// RunContainer function is the entrypoint to the module -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { +// Run function is the entrypoint to the module +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { cfg := Config{} req := testcontainers.ContainerRequest{ - Image: "my-image", + Image: img, ... } genericContainerReq := testcontainers.GenericContainerRequest{ @@ -191,7 +191,6 @@ func (c *Container) ConnectionString(ctx context.Context) (string, error) {...} In order to simplify the creation of the container for a given module, `Testcontainers for Go` provides a set of `testcontainers.CustomizeRequestOption` functions to customize the container request for the module. These options are: -- `testcontainers.WithImage`: a function that sets the image for the container request. - `testcontainers.WithImageSubstitutors`: a function that sets your own substitutions to the container images. - `testcontainers.WithEnv`: a function that sets the environment variables for the container request. - `testcontainers.WithHostPortAccess`: a function that enables the container to access a port that is already running in the host. diff --git a/docs/modules/influxdb.md b/docs/modules/influxdb.md index c3075c97c9..756af5de0f 100644 --- a/docs/modules/influxdb.md +++ b/docs/modules/influxdb.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/influxdb ## Module Reference -The InfluxDB module exposes one entrypoint function to create the container, and this function receives two parameters: +The InfluxDB module exposes one entrypoint function to create the container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) {} +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -42,10 +43,11 @@ When starting the container, you can pass options in a variadic way to configure #### Image -To use a different Docker image, you can use the `testcontainers.WithImage` option to specify the -image, E.g. `testcontainers.WithImage("influxdb:1.8.0")`. By default, the 1.8.10 image is used. Note that -`influxdb:latest` will get you a version 2 image which is not supported by this module. +To use a different Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "influxdb:1.8.0")`. +!!!info + Note that `influxdb:latest` will get you a version 2 image which is not supported by this module. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/k3s.md b/docs/modules/k3s.md index c6edd0d255..f1bb5517d6 100644 --- a/docs/modules/k3s.md +++ b/docs/modules/k3s.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/k3s ## Module reference -The K3s module exposes one entrypoint function to create the K3s container, and this function receives two parameters: +The K3s module exposes one entrypoint function to create the K3s container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. @@ -44,8 +45,8 @@ When starting the K3s container, you can pass options in a variadic way to confi #### Image -If you need to set a different K3s Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for K3s. E.g. `testcontainers.WithImage("docker.io/rancher/k3s:v1.27.1-k3s1")`. +If you need to set a different K3s Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/rancher/k3s:v1.27.1-k3s1")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/k6.md b/docs/modules/k6.md index ce81d31c1c..f5e721117b 100644 --- a/docs/modules/k6.md +++ b/docs/modules/k6.md @@ -29,13 +29,14 @@ go get github.com/testcontainers/testcontainers-go/modules/k6 ## Module reference -The K6 module exposes one entrypoint function to run the K6 container, and this function receives two parameters: +The K6 module exposes one entrypoint function to run the K6 container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -47,8 +48,8 @@ When starting the K6 container, you can pass options in a variadic way to config !!! warning The K6 module uses a `k6x` image to build a `k6` binary with all the required extensions. Therefore, only the [szkiba/k6x](https://hub.docker.com/r/szkiba/k6x) image should be used with this module. -If you need to set a different K6 Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for k6x. E.g. `testcontainers.WithImage("szkiba/k6x:v0.3.1")`. +If you need to set a different K6 Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "szkiba/k6x:v0.3.1")`. {% include "../features/common_functional_options.md" %} @@ -57,7 +58,7 @@ for k6x. E.g. `testcontainers.WithImage("szkiba/k6x:v0.3.1")`. `SetEnvVar` sets an [environment variable](https://k6.io/docs/using-k6/environment-variables/) for the test script using the '--env' command-line flag in the k6 command in the container. ```golang -k6.RunContainer(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) +k6.New(ctx, k6.SetEnvVar("URL","test.k6.io"), k6.WithTestScript("/tests/test.js")) ``` #### WithCache @@ -70,7 +71,7 @@ By default, a new volume is created and automatically removed when the test sess This is convenient for example for CI/CD environments. In other cases, such as local testing, it can be convenient to reuse the same cache volume across test sessions.In this cases, the TC_K6_BUILD_CACHE environment variables can used to provide the name of a volume to be used and kept across test sessions. If this volume does not exist, it will be created. ```golang -k6.RunContainer(ctx, WithCache(), k6.WithTestScript("/tests/test.js")) +k6.New(ctx, WithCache(), k6.WithTestScript("/tests/test.js")) ``` #### WithCmdOptions @@ -78,7 +79,7 @@ k6.RunContainer(ctx, WithCache(), k6.WithTestScript("/tests/test.js")) Use `WithCmdOptions` to pass a variadic list of strings as [options](https://k6.io/docs/using-k6/k6-options/reference/) to the k6 run command ```golang -k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) +k6.New(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestScript("/tests/test.js")) ``` #### WithTestScript @@ -86,7 +87,7 @@ k6.RunContainer(ctx, WithCmdOptions("--vus=10", "--duration=30s"), k6.WithTestSc Use the `WithTestScript` option to specify the test script to run. The path to the script must be an absolute path. This option copies the script file to the container and pass it to k6's `run` command. At least one `WithTestScript` or `WithRemoteTestScript` option must be specified. ```golang -k6.RunContainer(ctx, k6.WithTestScript("/tests/test.js")) +k6.New(ctx, k6.WithTestScript("/tests/test.js")) ``` #### WithRemoteTestScript @@ -100,7 +101,7 @@ uri, _ := url.Parse(scriptUrl) desc := k6.DownloadableFile{Uri: *uri , DownloadDir: t.TempDir()} options := k6.WithRemoteTestScript(desc) -k6.RunContainer(ctx, k6.WithCache(), options) +k6.New(ctx, k6.WithCache(), options) ``` ### Container Methods diff --git a/docs/modules/kafka.md b/docs/modules/kafka.md index 86bf846de9..71873f6ded 100644 --- a/docs/modules/kafka.md +++ b/docs/modules/kafka.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/kafka ## Module reference -The Kafka module exposes one entrypoint function to create the Kafka container, and this function receives two parameters: +The Kafka module exposes one entrypoint function to create the Kafka container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*KafkaContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*KafkaContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Kafka container, you can pass options in a variadic way to con #### Image -If you need to set a different Kafka Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Kafka. E.g. `testcontainers.WithImage("confluentinc/confluent-local:7.5.0")`. +If you need to set a different Kafka Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "confluentinc/confluent-local:7.5.0")`. !!! warning The minimal required version of Kafka for KRaft mode is `confluentinc/confluent-local:7.4.0`. If you are using an image that diff --git a/docs/modules/localstack.md b/docs/modules/localstack.md index 206f40d82f..8182792f33 100644 --- a/docs/modules/localstack.md +++ b/docs/modules/localstack.md @@ -27,13 +27,14 @@ Use the `testcontainers.WithEnv` option when creating the `LocalStackContainer` ## Module reference -The LocalStack module exposes one single function to create the LocalStack container, and this function receives two parameters: +The LocalStack module exposes one single function to create the LocalStack container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*LocalStackContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*LocalstackContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -42,7 +43,8 @@ When starting the Localstack container, you can pass options in a variadic way t #### Image -By default, the image used is `localstack:1.4.0`. If you need to use a different image, you can use `testcontainers.WithImage` option. +If you need to set a different Localstack Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "localstack:1.4.0")`. {% include "../features/common_functional_options.md" %} @@ -54,7 +56,7 @@ It's possible to entirely override the default LocalStack container request: [Customize container request](../../modules/localstack/examples_test.go) inside_block:withCustomContainerRequest -With simply passing the `testcontainers.CustomizeRequest` functional option to the `RunContainer` function, you'll be able to configure the LocalStack container with your own needs, as this new container request will be merged with the original one. +With simply passing the `testcontainers.CustomizeRequest` functional option to the `New` function, you'll be able to configure the LocalStack container with your own needs, as this new container request will be merged with the original one. In the above example you can check how it's possible to copy files that are needed by the tests. The `flagsFn` function is a helper function that converts Docker labels used by Ryuk to a string with the format requested by LocalStack. diff --git a/docs/modules/mariadb.md b/docs/modules/mariadb.md index bb2eb63de6..f487deb3d6 100644 --- a/docs/modules/mariadb.md +++ b/docs/modules/mariadb.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/mariadb ## Module reference -The MariaDB module exposes one entrypoint function to create the MariaDB container, and this function receives two parameters: +The MariaDB module exposes one entrypoint function to create the MariaDB container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MariaDBContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MariaDBContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -41,8 +42,8 @@ When starting the MariaDB container, you can pass options in a variadic way to c #### Image -If you need to set a different MariaDB Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for MariaDB. E.g. `testcontainers.WithImage("mariadb:11.0.3")`. +If you need to set a different MariaDB Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "mariadb:11.0.3")`. !!!info From MariaDB [docs](https://github.com/docker-library/docs/tree/master/mariadb#environment-variables): diff --git a/docs/modules/milvus.md b/docs/modules/milvus.md index 4051316ff8..7c27391efa 100644 --- a/docs/modules/milvus.md +++ b/docs/modules/milvus.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/milvus ## Module reference -The Milvus module exposes one entrypoint function to create the Milvus container, and this function receives two parameters: +The Milvus module exposes one entrypoint function to create the Milvus container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Milvus container, you can pass options in a variadic way to co #### Image -If you need to set a different Milvus Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Milvus. E.g. `testcontainers.WithImage("milvusdb/milvus:v2.3.9")`. +If you need to set a different Milvus Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "milvusdb/milvus:v2.3.9")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/minio.md b/docs/modules/minio.md index 141aae23fe..aac90e971b 100644 --- a/docs/modules/minio.md +++ b/docs/modules/minio.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/minio ## Module reference -The Minio module exposes one entrypoint function to create the Minio container, and this function receives two parameters: +The Minio module exposes one entrypoint function to create the Minio container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MinioContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MinioContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Minio container, you can pass options in a variadic way to con #### Image -If you need to set a different Minio Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Minio. E.g. `testcontainers.WithImage("minio/minio:RELEASE.2024-01-16T16-07-38Z")`. +If you need to set a different Minio Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "minio/minio:RELEASE.2024-01-16T16-07-38Z")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/mockserver.md b/docs/modules/mockserver.md index 4ebc2bd732..bff1e74140 100644 --- a/docs/modules/mockserver.md +++ b/docs/modules/mockserver.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/mockserver ## Module reference -The MockServer module exposes one entrypoint function to create the MockServer container, and this function receives two parameters: +The MockServer module exposes one entrypoint function to create the MockServer container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MockServerContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MockServerContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the MockServer container, you can pass options in a variadic way t #### Image -If you need to set a different MockServer Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for MockServer. E.g. `testcontainers.WithImage("mockserver/mockserver:5.15.0")`. +If you need to set a different MockServer Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "mockserver/mockserver:5.15.0")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/mongodb.md b/docs/modules/mongodb.md index ba1989042e..6fe7c0a748 100644 --- a/docs/modules/mongodb.md +++ b/docs/modules/mongodb.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/mongodb ## Module reference -The MongoDB module exposes one entrypoint function to create the MongoDB container, and this function receives two parameters: +The MongoDB module exposes one entrypoint function to create the MongoDB container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MongoDBContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MongoDBContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the MongoDB container, you can pass options in a variadic way to c #### Image -If you need to set a different MongoDB Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for MongoDB. E.g. `testcontainers.WithImage("mongo:6")`. +If you need to set a different MongoDB Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "mongo:6")`. #### WithUsername diff --git a/docs/modules/mssql.md b/docs/modules/mssql.md index 80e48d48b1..6debbe8a22 100644 --- a/docs/modules/mssql.md +++ b/docs/modules/mssql.md @@ -27,13 +27,14 @@ go get github.com/testcontainers/testcontainers-go/modules/mssql ## Module reference -The MS SQL Server module exposes one entrypoint function to create the MS SQL Server container, and this function receives two parameters: +The MS SQL Server module exposes one entrypoint function to create the MS SQL Server container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -42,8 +43,8 @@ When starting the MS SQL Server container, you can pass options in a variadic wa #### Image -If you need to set a different MS SQL Server Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for MS SQL Server. E.g. `testcontainers.WithImage("mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04")`. +If you need to set a different MS SQL Server Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04")`. #### End User License Agreement diff --git a/docs/modules/mysql.md b/docs/modules/mysql.md index 5fbaa1bd49..4c16030ec5 100644 --- a/docs/modules/mysql.md +++ b/docs/modules/mysql.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/mysql ## Module Reference -The MySQL module exposes one entrypoint function to create the container, and this function receives two parameters: +The MySQL module exposes one entrypoint function to create the container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MySQLContainer, error) { +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MySQLContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -41,8 +42,8 @@ When starting the MySQL container, you can pass options in a variadic way to con #### Image -If you need to set a different MySQL Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for MySQL. E.g. `testcontainers.WithImage("mysql:8.0.36")`. +If you need to set a different MySQL Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "mysql:8.0.36")`. By default, the container will use the following Docker image: diff --git a/docs/modules/nats.md b/docs/modules/nats.md index 72bd7b4fc5..82bb330ada 100644 --- a/docs/modules/nats.md +++ b/docs/modules/nats.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/nats ## Module reference -The NATS module exposes one entrypoint function to create the NATS container, and this function receives two parameters: +The NATS module exposes one entrypoint function to create the NATS container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the NATS container, you can pass options in a variadic way to conf #### Image -If you need to set a different NATS Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for NATS. E.g. `testcontainers.WithImage("nats:2.9")`. +If you need to set a different NATS Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "nats:2.9")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/neo4j.md b/docs/modules/neo4j.md index f06e475860..f00663b6c1 100644 --- a/docs/modules/neo4j.md +++ b/docs/modules/neo4j.md @@ -24,13 +24,14 @@ Running Neo4j as a single-instance server, with the [APOC plugin](https://neo4j. ## Module Reference -The Neo4j module exposes one entrypoint function to create the Neo4j container, and this function receives two parameters: +The Neo4j module exposes one entrypoint function to create the Neo4j container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Ports @@ -47,8 +48,8 @@ When starting the Neo4j container, you can pass options in a variadic way to con #### Image -If you need to set a different Neo4j Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Neo4j. E.g. `testcontainers.WithImage("docker.io/neo4j:4.4")`. +If you need to set a different Neo4j Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/neo4j:4.4")`. By default, the container will use the following Docker image: diff --git a/docs/modules/ollama.md b/docs/modules/ollama.md index 19cde849c3..edae5d6a39 100644 --- a/docs/modules/ollama.md +++ b/docs/modules/ollama.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/ollama ## Module reference -The Ollama module exposes one entrypoint function to create the Ollama container, and this function receives two parameters: +The Ollama module exposes one entrypoint function to create the Ollama container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OllamaContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OllamaContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Ollama container, you can pass options in a variadic way to co #### Image -If you need to set a different Ollama Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Ollama. E.g. `testcontainers.WithImage("ollama/ollama:0.1.25")`. +If you need to set a different Ollama Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "ollama/ollama:0.1.25")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/openfga.md b/docs/modules/openfga.md index 459be0bfa7..5fe839398b 100644 --- a/docs/modules/openfga.md +++ b/docs/modules/openfga.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/openfga ## Module reference -The OpenFGA module exposes one entrypoint function to create the OpenFGA container, and this function receives two parameters: +The OpenFGA module exposes one entrypoint function to create the OpenFGA container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenFGAContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenFGAContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the OpenFGA container, you can pass options in a variadic way to c #### Image -If you need to set a different OpenFGA Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for OpenFGA. E.g. `testcontainers.WithImage("openfga/openfga:v1.5.0")`. +If you need to set a different OpenFGA Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "openfga/openfga:v1.5.0")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/openldap.md b/docs/modules/openldap.md index b7311a61d0..48e978bbc2 100644 --- a/docs/modules/openldap.md +++ b/docs/modules/openldap.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/openldap ## Module reference -The OpenLDAP module exposes one entrypoint function to create the OpenLDAP container, and this function receives two parameters: +The OpenLDAP module exposes one entrypoint function to create the OpenLDAP container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the OpenLDAP container, you can pass options in a variadic way to #### Image -If you need to set a different OpenLDAP Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for OpenLDAP. E.g. `testcontainers.WithImage("bitnami/openldap:2.6.6")`. +If you need to set a different OpenLDAP Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "bitnami/openldap:2.6.6")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/opensearch.md b/docs/modules/opensearch.md index 2046532db8..21d9073397 100644 --- a/docs/modules/opensearch.md +++ b/docs/modules/opensearch.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/opensearch ## Module reference -The OpenSearch module exposes one entrypoint function to create the OpenSearch container, and this function receives two parameters: +The OpenSearch module exposes one entrypoint function to create the OpenSearch container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenSearchContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenSearchContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the OpenSearch container, you can pass options in a variadic way t #### Image -If you need to set a different OpenSearch Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for OpenSearch. E.g. `testcontainers.WithImage("opensearchproject/opensearch:2.11.1")`. +If you need to set a different OpenSearch Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "opensearchproject/opensearch:2.11.1")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/postgres.md b/docs/modules/postgres.md index c9414daaf2..f052c2ad38 100644 --- a/docs/modules/postgres.md +++ b/docs/modules/postgres.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/postgres ## Module reference -The Postgres module exposes one entrypoint function to create the Postgres container, and this function receives two parameters: +The Postgres module exposes one entrypoint function to create the Postgres container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*PostgresContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*PostgresContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -40,8 +41,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 `testcontainers.WithImage` with a valid Docker image -for Postgres. E.g. `testcontainers.WithImage("docker.io/postgres:16-alpine")`. +If you need to set a different Postgres Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/postgres:16-alpine")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/pulsar.md b/docs/modules/pulsar.md index f4d93621e4..0831b385cd 100644 --- a/docs/modules/pulsar.md +++ b/docs/modules/pulsar.md @@ -28,13 +28,14 @@ Create a `Pulsar` container to use it in your tests: ## Module Reference -The Pulsar module exposes one entrypoint function to create the containerr, and this function receives two parameters: +The Pulsar module exposes one entrypoint function to create the containerr, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -43,8 +44,8 @@ When starting the Pulsar container, you can pass options in a variadic way to co #### Image -If you need to set a different Pulsar Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Pulsar. E.g. `testcontainers.WithImage("docker.io/apachepulsar/pulsar:2.10.2")`. +If you need to set a different Pulsar Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/apachepulsar/pulsar:2.10.2")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/qdrant.md b/docs/modules/qdrant.md index 3d75c35433..4a499e247f 100644 --- a/docs/modules/qdrant.md +++ b/docs/modules/qdrant.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/qdrant ## Module reference -The Qdrant module exposes one entrypoint function to create the Qdrant container, and this function receives two parameters: +The Qdrant module exposes one entrypoint function to create the Qdrant container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*QdrantContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*QdrantContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Qdrant container, you can pass options in a variadic way to co #### Image -If you need to set a different Qdrant Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Qdrant. E.g. `testcontainers.WithImage("qdrant/qdrant:v1.7.4")`. +If you need to set a different Qdrant Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "qdrant/qdrant:v1.7.4")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/rabbitmq.md b/docs/modules/rabbitmq.md index 4dcc201035..64a465f436 100644 --- a/docs/modules/rabbitmq.md +++ b/docs/modules/rabbitmq.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/rabbitmq ## Module reference -The RabbitMQ module exposes one entrypoint function to create the RabbitMQ container, and this function receives two parameters: +The RabbitMQ module exposes one entrypoint function to create the RabbitMQ container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the RabbitMQ container, you can pass options in a variadic way to #### Image -If you need to set a different RabbitMQ Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for RabbitMQ. E.g. `testcontainers.WithImage("rabbitmq:3.7.25-management-alpine")`. +If you need to set a different RabbitMQ Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "rabbitmq:3.7.25-management-alpine")`. !!!warning From [https://hub.docker.com/_/rabbitmq](https://hub.docker.com/_/rabbitmq): "As of RabbitMQ 3.9, all of the docker-specific variables listed below are deprecated and no longer used. Please use a configuration file instead; visit [rabbitmq.com/configure](https://rabbitmq.com/configure) to learn more about the configuration file. For a starting point, the 3.8 images will print out the config file it generated from supplied environment variables." diff --git a/docs/modules/redis.md b/docs/modules/redis.md index 50c5a3025f..1b64b34fd7 100644 --- a/docs/modules/redis.md +++ b/docs/modules/redis.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/redis ## Module Reference -The Redis module exposes one entrypoint function to create the containerr, and this function receives two parameters: +The Redis module exposes one entrypoint function to create the containerr, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -40,8 +41,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 `testcontainers.WithImage` with a valid Docker image -for Redis. E.g. `testcontainers.WithImage("docker.io/redis:7")`. +If you need to set a different Redis Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.io/redis:7")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/redpanda.md b/docs/modules/redpanda.md index ad2223ce83..01df7c4739 100644 --- a/docs/modules/redpanda.md +++ b/docs/modules/redpanda.md @@ -27,13 +27,14 @@ go get github.com/testcontainers/testcontainers-go/modules/redpanda ## Module reference -The Redpanda module exposes one entrypoint function to create the Redpanda container, and this function receives two parameters: +The Redpanda module exposes one entrypoint function to create the Redpanda container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RedpandaContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RedpandaContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -42,8 +43,8 @@ When starting the Redpanda container, you can pass options in a variadic way to #### Image -If you need to set a different Redpanda Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Redpanda. E.g. `testcontainers.WithImage("docker.redpanda.com/redpandadata/redpanda:v23.1.7")`. +If you need to set a different Redpanda Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "docker.redpanda.com/redpandadata/redpanda:v23.1.7")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/registry.md b/docs/modules/registry.md index bc54f27007..3e66d650ba 100644 --- a/docs/modules/registry.md +++ b/docs/modules/registry.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/registry ## Module reference -The Registry module exposes one entrypoint function to create the Registry container, and this function receives two parameters: +The Registry module exposes one entrypoint function to create the Registry container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Registry container, you can pass options in a variadic way to #### Image -If you need to set a different Registry Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Registry. E.g. `testcontainers.WithImage("registry:2.8.3")`. +If you need to set a different Registry Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "registry:2.8.3")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/surrealdb.md b/docs/modules/surrealdb.md index 9d026c0986..9bf34ca05e 100644 --- a/docs/modules/surrealdb.md +++ b/docs/modules/surrealdb.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/surrealdb ## Module reference -The SurrealDB module exposes one entrypoint function to create the SurrealDB container, and this function receives two parameters: +The SurrealDB module exposes one entrypoint function to create the SurrealDB container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the SurrealDB container, you can pass options in a variadic way to #### Image -If you need to set a different SurrealDB Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for SurrealDB. E.g. `testcontainers.WithImage("surrealdb/surrealdb:v1.1.1")`. +If you need to set a different SurrealDB Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "surrealdb/surrealdb:v1.1.1")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/vault.md b/docs/modules/vault.md index 722e3459e7..8e9fd5e7a1 100644 --- a/docs/modules/vault.md +++ b/docs/modules/vault.md @@ -15,7 +15,7 @@ go get github.com/testcontainers/testcontainers-go/modules/vault ``` ## Usage example -The **RunContainer** function is the main entry point to create a new VaultContainer instance. +The **RunWithImage** 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. @@ -27,7 +27,7 @@ It takes a context and zero or more Option values to configure the container. [Use CLI to read data](../../modules/vault/vault_test.go) inside_block:containerCliRead -The `vaultContainer` is the container instance obtained from `RunContainer`. +The `vaultContainer` is the container instance obtained from `RunWithImage`. ### Use HTTP API to read data from Vault container: @@ -48,13 +48,14 @@ go get -u github.com/hashicorp/vault-client-go ## Module Reference -The Vault module exposes one entrypoint function to create the containerr, and this function receives two parameters: +The Vault module exposes one entrypoint function to create the containerr, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -63,15 +64,8 @@ When starting the Vault container, you can pass options in a variadic way to con #### Image -If you need to set a different Vault Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Vault. E.g. `testcontainers.WithImage("hashicorp/vault:1.13.0")`. - -!!!info - Default image name is `hashicorp/vault:1.13.0`. - - -[Set image name](../../modules/vault/vault_test.go) inside_block:WithImageName - +If you need to set a different Vault Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "hashicorp/vault:1.13.0")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/vearch.md b/docs/modules/vearch.md index 87f031c63f..335f747060 100644 --- a/docs/modules/vearch.md +++ b/docs/modules/vearch.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/vearch ## Module reference -The Vearch module exposes one entrypoint function to create the Vearch container, and this function receives two parameters: +The Vearch module exposes one entrypoint function to create the Vearch container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Vearch container, you can pass options in a variadic way to co #### Image -If you need to set a different Vearch Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Vearch. E.g. `testcontainers.WithImage("vearch/vearch:3.5.1")`. +If you need to set a different Vearch Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "vearch/vearch:3.5.1")`. {% include "../features/common_functional_options.md" %} diff --git a/docs/modules/weaviate.md b/docs/modules/weaviate.md index a36c03ce8f..9c7840200a 100644 --- a/docs/modules/weaviate.md +++ b/docs/modules/weaviate.md @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/modules/weaviate ## Module reference -The Weaviate module exposes one entrypoint function to create the Weaviate container, and this function receives two parameters: +The Weaviate module exposes one entrypoint function to create the Weaviate container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*WeaviteContainer, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the Weaviate container, you can pass options in a variadic way to #### Image -If you need to set a different Weaviate Docker image, you can use `testcontainers.WithImage` with a valid Docker image -for Weaviate. E.g. `testcontainers.WithImage("semitechnologies/weaviate:1.23.9")`. +If you need to set a different Weaviate Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "semitechnologies/weaviate:1.23.9")`. {% include "../features/common_functional_options.md" %} diff --git a/modulegen/_template/examples_test.go.tmpl b/modulegen/_template/examples_test.go.tmpl index d386959330..b81cf22c58 100644 --- a/modulegen/_template/examples_test.go.tmpl +++ b/modulegen/_template/examples_test.go.tmpl @@ -5,7 +5,6 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }}" ) @@ -13,7 +12,7 @@ func Example{{ $entrypoint }}() { // run{{ $title }}Container { ctx := context.Background() - {{ $lower }}Container, err := {{ $lower }}.{{ $entrypoint }}(ctx, testcontainers.WithImage("{{ $image }}")) + {{ $lower }}Container, err := {{ $lower }}.{{ $entrypoint }}(ctx, "{{ $image }}") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modulegen/_template/module.go.tmpl b/modulegen/_template/module.go.tmpl index 9cfadde26d..fe988afada 100644 --- a/modulegen/_template/module.go.tmpl +++ b/modulegen/_template/module.go.tmpl @@ -13,9 +13,9 @@ type {{ $containerName }} struct { } // {{ $entrypoint }} creates an instance of the {{ $title }} container type -func {{ $entrypoint }}(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*{{ $containerName }}, error) { +func {{ $entrypoint }}(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*{{ $containerName }}, error) { req := testcontainers.ContainerRequest{ - Image: "{{ .Image }}", + Image: img, } genericContainerReq := testcontainers.GenericContainerRequest{ diff --git a/modulegen/_template/module.md.tmpl b/modulegen/_template/module.md.tmpl index 93825da5c3..d6320a852d 100644 --- a/modulegen/_template/module.md.tmpl +++ b/modulegen/_template/module.md.tmpl @@ -22,13 +22,14 @@ go get github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }} ## Module reference -The {{ $title }} module exposes one entrypoint function to create the {{ $title }} container, and this function receives two parameters: +The {{ $title }} module exposes one entrypoint function to create the {{ $title }} container, and this function receives three parameters: ```golang -func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*{{ $title }}Container, error) +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*{{ $title }}Container, error) ``` - `context.Context`, the Go context. +- `string`, the Docker image to use. - `testcontainers.ContainerCustomizer`, a variadic argument for passing options. ### Container Options @@ -37,8 +38,8 @@ When starting the {{ $title }} container, you can pass options in a variadic way #### 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 }}")`. +If you need to set a different {{ $title }} Docker image, you can set a valid Docker image as the second argument in the `Run` function. +E.g. `Run(context.Background(), "{{ .Image }}")`. {% include "../features/common_functional_options.md" %} diff --git a/modulegen/_template/module_test.go.tmpl b/modulegen/_template/module_test.go.tmpl index 9a0f5391d5..2f7774ad7a 100644 --- a/modulegen/_template/module_test.go.tmpl +++ b/modulegen/_template/module_test.go.tmpl @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/{{ ParentDir }}/{{ $lower }}" ) func Test{{ $title }}(t *testing.T) { ctx := context.Background() - container, err := {{ $lower }}.{{ $entrypoint }}(ctx, testcontainers.WithImage("{{ $image }}")) + container, err := {{ $lower }}.{{ $entrypoint }}(ctx, "{{ $image }}") if err != nil { t.Fatal(err) } diff --git a/modulegen/internal/context/types.go b/modulegen/internal/context/types.go index 6264579ed2..0792c249df 100644 --- a/modulegen/internal/context/types.go +++ b/modulegen/internal/context/types.go @@ -35,13 +35,13 @@ func (m *TestcontainersModule) 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 "RunContainer" +// If the example is a module, the entrypoint will be "Run" func (m *TestcontainersModule) Entrypoint() string { if m.IsModule { - return "RunContainer" + return "Run" } - return "runContainer" + return "run" } func (m *TestcontainersModule) Lower() string { diff --git a/modulegen/main_test.go b/modulegen/main_test.go index 72433eaee4..2c7b29a2e5 100644 --- a/modulegen/main_test.go +++ b/modulegen/main_test.go @@ -32,7 +32,7 @@ func TestModule(t *testing.T) { TitleName: "MongoDB", }, expectedContainerName: "MongoDBContainer", - expectedEntrypoint: "RunContainer", + expectedEntrypoint: "Run", expectedTitle: "MongoDB", }, { @@ -43,7 +43,7 @@ func TestModule(t *testing.T) { Image: "mongodb:latest", }, expectedContainerName: "MongodbContainer", - expectedEntrypoint: "RunContainer", + expectedEntrypoint: "Run", expectedTitle: "Mongodb", }, { @@ -55,7 +55,7 @@ func TestModule(t *testing.T) { TitleName: "MongoDB", }, expectedContainerName: "mongoDBContainer", - expectedEntrypoint: "runContainer", + expectedEntrypoint: "run", expectedTitle: "MongoDB", }, { @@ -66,7 +66,7 @@ func TestModule(t *testing.T) { Image: "mongodb:latest", }, expectedContainerName: "mongodbContainer", - expectedEntrypoint: "runContainer", + expectedEntrypoint: "run", expectedTitle: "Mongodb", }, } @@ -374,9 +374,10 @@ func assertModuleDocContent(t *testing.T, module context.TestcontainersModule, m assert.Equal(t, "", data[18]) assert.Equal(t, "[Creating a "+title+" container](../../"+module.ParentDir()+"/"+lower+"/examples_test.go) inside_block:run"+title+"Container", data[19]) assert.Equal(t, "", data[20]) - assert.Equal(t, "The "+title+" module exposes one entrypoint function to create the "+title+" container, and this function receives two parameters:", data[24]) + assert.Equal(t, "The "+title+" module exposes one entrypoint function to create the "+title+" container, and this function receives three parameters:", data[24]) assert.True(t, strings.HasSuffix(data[27], "(*"+title+"Container, error)")) - assert.Equal(t, "for "+title+". E.g. `testcontainers.WithImage(\""+module.Image+"\")`.", data[40]) + assert.Equal(t, "If you need to set a different "+title+" Docker image, you can set a valid Docker image as the second argument in the `Run` function.", data[40]) + assert.Equal(t, "E.g. `Run(context.Background(), \""+module.Image+"\")`.", data[41]) } // assert content module test @@ -390,14 +391,13 @@ func assertExamplesTestContent(t *testing.T, module context.TestcontainersModule data := sanitiseContent(content) assert.Equal(t, "package "+lower+"_test", data[0]) - assert.Equal(t, "\t\"github.com/testcontainers/testcontainers-go\"", data[7]) - assert.Equal(t, "\t\"github.com/testcontainers/testcontainers-go/modules/"+lower+"\"", data[8]) - assert.Equal(t, "func Example"+entrypoint+"() {", data[11]) - assert.Equal(t, "\t// run"+title+"Container {", data[12]) - assert.Equal(t, "\t"+lower+"Container, err := "+lower+"."+entrypoint+"(ctx, testcontainers.WithImage(\""+module.Image+"\"))", data[15]) - assert.Equal(t, "\tfmt.Println(state.Running)", data[33]) - assert.Equal(t, "\t// Output:", data[35]) - assert.Equal(t, "\t// true", data[36]) + assert.Equal(t, "\t\"github.com/testcontainers/testcontainers-go/modules/"+lower+"\"", data[7]) + assert.Equal(t, "func Example"+entrypoint+"() {", data[10]) + assert.Equal(t, "\t// run"+title+"Container {", data[11]) + assert.Equal(t, "\t"+lower+"Container, err := "+lower+"."+entrypoint+"(ctx, \""+module.Image+"\")", data[14]) + assert.Equal(t, "\tfmt.Println(state.Running)", data[32]) + assert.Equal(t, "\t// Output:", data[34]) + assert.Equal(t, "\t// true", data[35]) } // assert content module test @@ -407,8 +407,8 @@ func assertModuleTestContent(t *testing.T, module context.TestcontainersModule, data := sanitiseContent(content) assert.Equal(t, "package "+module.Lower()+"_test", data[0]) - assert.Equal(t, "func Test"+module.Title()+"(t *testing.T) {", data[10]) - assert.Equal(t, "\tcontainer, err := "+module.Lower()+"."+module.Entrypoint()+"(ctx, testcontainers.WithImage(\""+module.Image+"\"))", data[13]) + assert.Equal(t, "func Test"+module.Title()+"(t *testing.T) {", data[9]) + assert.Equal(t, "\tcontainer, err := "+module.Lower()+"."+module.Entrypoint()+"(ctx, \""+module.Image+"\")", data[12]) } // assert content module @@ -426,8 +426,8 @@ func assertModuleContent(t *testing.T, module context.TestcontainersModule, exam assert.Equal(t, "// "+containerName+" represents the "+exampleName+" container type used in the module", data[9]) assert.Equal(t, "type "+containerName+" struct {", data[10]) assert.Equal(t, "// "+entrypoint+" creates an instance of the "+exampleName+" container type", data[14]) - assert.Equal(t, "func "+entrypoint+"(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*"+containerName+", error) {", data[15]) - assert.Equal(t, "\t\tImage: \""+module.Image+"\",", data[17]) + assert.Equal(t, "func "+entrypoint+"(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*"+containerName+", error) {", data[15]) + assert.Equal(t, "\t\tImage: img,", data[17]) assert.Equal(t, "\t\tif err := opt.Customize(&genericContainerReq); err != nil {", data[26]) assert.Equal(t, "\t\t\treturn nil, fmt.Errorf(\"customize: %w\", err)", data[27]) assert.Equal(t, "\treturn &"+containerName+"{Container: container}, nil", data[36]) diff --git a/modules/artemis/artemis.go b/modules/artemis/artemis.go index 33e03583cc..9edfcaa527 100644 --- a/modules/artemis/artemis.go +++ b/modules/artemis/artemis.go @@ -78,11 +78,17 @@ func WithExtraArgs(args string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead. // RunContainer creates an instance of the Artemis container type. func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { + return Run(ctx, "docker.io/apache/activemq-artemis:2.30.0-alpine", opts...) +} + +// Run creates an instance of the Artemis container type with a given image +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "docker.io/apache/activemq-artemis:2.30.0-alpine", + Image: img, Env: map[string]string{ "ARTEMIS_USER": "artemis", "ARTEMIS_PASSWORD": "artemis", diff --git a/modules/artemis/artemis_test.go b/modules/artemis/artemis_test.go index 4cf70db556..c2767790ad 100644 --- a/modules/artemis/artemis_test.go +++ b/modules/artemis/artemis_test.go @@ -64,7 +64,7 @@ func TestArtemis(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - container, err := artemis.RunContainer(ctx, test.opts...) + container, err := artemis.Run(ctx, "docker.io/apache/activemq-artemis:2.30.0-alpine", test.opts...) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, container.Terminate(ctx), "failed to terminate container") }) diff --git a/modules/artemis/examples_test.go b/modules/artemis/examples_test.go index 2b17776bb1..e1c21f3afc 100644 --- a/modules/artemis/examples_test.go +++ b/modules/artemis/examples_test.go @@ -7,16 +7,15 @@ import ( "github.com/go-stomp/stomp/v3" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/artemis" ) -func ExampleRunContainer() { +func ExampleRun() { // runArtemisContainer { ctx := context.Background() - artemisContainer, err := artemis.RunContainer(ctx, - testcontainers.WithImage("docker.io/apache/activemq-artemis:2.30.0"), + artemisContainer, err := artemis.Run(ctx, + "docker.io/apache/activemq-artemis:2.30.0", artemis.WithCredentials("test", "test"), ) if err != nil { diff --git a/modules/azurite/azurite.go b/modules/azurite/azurite.go index d193042460..1dcdae4709 100644 --- a/modules/azurite/azurite.go +++ b/modules/azurite/azurite.go @@ -68,10 +68,16 @@ func (c *AzuriteContainer) MustServiceURL(ctx context.Context, srv Service) stri return url } +// Deprecated: use Run instead // RunContainer creates an instance of the Azurite container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) { + return Run(ctx, "mcr.microsoft.com/azure-storage/azurite:3.28.0", opts...) +} + +// Run creates an instance of the Azurite container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*AzuriteContainer, error) { req := testcontainers.ContainerRequest{ - Image: "mcr.microsoft.com/azure-storage/azurite:3.28.0", + Image: img, ExposedPorts: []string{BlobPort, QueuePort, TablePort}, Env: map[string]string{}, Entrypoint: []string{"azurite"}, diff --git a/modules/azurite/azurite_test.go b/modules/azurite/azurite_test.go index f33ddd27c3..8fe5946e2f 100644 --- a/modules/azurite/azurite_test.go +++ b/modules/azurite/azurite_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/azurite" ) func TestAzurite(t *testing.T) { ctx := context.Background() - container, err := azurite.RunContainer(ctx, testcontainers.WithImage("mcr.microsoft.com/azure-storage/azurite:3.23.0")) + container, err := azurite.Run(ctx, "mcr.microsoft.com/azure-storage/azurite:3.23.0") if err != nil { t.Fatal(err) } diff --git a/modules/azurite/examples_test.go b/modules/azurite/examples_test.go index d3c53b524f..d2fc9965f0 100644 --- a/modules/azurite/examples_test.go +++ b/modules/azurite/examples_test.go @@ -12,17 +12,16 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/Azure/azure-sdk-for-go/sdk/storage/azqueue" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/azurite" ) -func ExampleRunContainer() { +func ExampleRun() { // runAzuriteContainer { ctx := context.Background() - azuriteContainer, err := azurite.RunContainer( + azuriteContainer, err := azurite.Run( ctx, - testcontainers.WithImage("mcr.microsoft.com/azure-storage/azurite:3.28.0"), + "mcr.microsoft.com/azure-storage/azurite:3.28.0", ) if err != nil { log.Fatalf("failed to start container: %s", err) @@ -49,13 +48,13 @@ func ExampleRunContainer() { // This example demonstrates how to create a container, upload a blob, list blobs, and delete the container. // Inspired by https://github.com/Azure/azure-sdk-for-go/blob/718000938221915fb2f3c7522d4fd09f7d74cafb/sdk/storage/azblob/examples_test.go#L36 -func ExampleRunContainer_blobOperations() { +func ExampleRun_blobOperations() { // blobOperations { ctx := context.Background() - azuriteContainer, err := azurite.RunContainer( + azuriteContainer, err := azurite.Run( ctx, - testcontainers.WithImage("mcr.microsoft.com/azure-storage/azurite:3.28.0"), + "mcr.microsoft.com/azure-storage/azurite:3.28.0", azurite.WithInMemoryPersistence(64), ) if err != nil { @@ -161,13 +160,13 @@ func ExampleRunContainer_blobOperations() { // This example demonstrates how to create, list and delete queues. // Inspired by https://github.com/Azure/azure-sdk-for-go/blob/718000938221915fb2f3c7522d4fd09f7d74cafb/sdk/storage/azqueue/samples_test.go#L1 -func ExampleRunContainer_queueOperations() { +func ExampleRun_queueOperations() { // queueOperations { ctx := context.Background() - azuriteContainer, err := azurite.RunContainer( + azuriteContainer, err := azurite.Run( ctx, - testcontainers.WithImage("mcr.microsoft.com/azure-storage/azurite:3.28.0"), + "mcr.microsoft.com/azure-storage/azurite:3.28.0", azurite.WithInMemoryPersistence(64), ) if err != nil { @@ -233,13 +232,13 @@ func ExampleRunContainer_queueOperations() { // This example demonstrates how to create, list and delete tables. // Inspired by https://github.com/Azure/azure-sdk-for-go/blob/718000938221915fb2f3c7522d4fd09f7d74cafb/sdk/data/aztables/example_test.go#L1 -func ExampleRunContainer_tableOperations() { +func ExampleRun_tableOperations() { // tableOperations { ctx := context.Background() - azuriteContainer, err := azurite.RunContainer( + azuriteContainer, err := azurite.Run( ctx, - testcontainers.WithImage("mcr.microsoft.com/azure-storage/azurite:3.28.0"), + "mcr.microsoft.com/azure-storage/azurite:3.28.0", azurite.WithInMemoryPersistence(64), ) if err != nil { diff --git a/modules/cassandra/cassandra.go b/modules/cassandra/cassandra.go index 10df6e991c..c5dbfc61d6 100644 --- a/modules/cassandra/cassandra.go +++ b/modules/cassandra/cassandra.go @@ -74,10 +74,16 @@ func WithInitScripts(scripts ...string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the Cassandra container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) { + return Run(ctx, "cassandra:4.1.3", opts...) +} + +// Run creates an instance of the Cassandra container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CassandraContainer, error) { req := testcontainers.ContainerRequest{ - Image: "cassandra:4.1.3", + Image: img, ExposedPorts: []string{string(port)}, Env: map[string]string{ "CASSANDRA_SNITCH": "GossipingPropertyFileSnitch", diff --git a/modules/cassandra/cassandra_test.go b/modules/cassandra/cassandra_test.go index 831ce01d32..a878db4f6f 100644 --- a/modules/cassandra/cassandra_test.go +++ b/modules/cassandra/cassandra_test.go @@ -20,7 +20,7 @@ type Test struct { func TestCassandra(t *testing.T) { ctx := context.Background() - container, err := cassandra.RunContainer(ctx) + container, err := cassandra.Run(ctx, "cassandra:4.1.3") if err != nil { t.Fatal(err) } @@ -60,7 +60,7 @@ func TestCassandra(t *testing.T) { func TestCassandraWithConfigFile(t *testing.T) { ctx := context.Background() - container, err := cassandra.RunContainer(ctx, cassandra.WithConfigFile(filepath.Join("testdata", "config.yaml"))) + container, err := cassandra.Run(ctx, "cassandra:4.1.3", cassandra.WithConfigFile(filepath.Join("testdata", "config.yaml"))) if err != nil { t.Fatal(err) } @@ -91,7 +91,7 @@ func TestCassandraWithInitScripts(t *testing.T) { ctx := context.Background() // withInitScripts { - container, err := cassandra.RunContainer(ctx, cassandra.WithInitScripts(filepath.Join("testdata", "init.cql"))) + container, err := cassandra.Run(ctx, "cassandra:4.1.3", cassandra.WithInitScripts(filepath.Join("testdata", "init.cql"))) // } if err != nil { t.Fatal(err) @@ -123,7 +123,7 @@ func TestCassandraWithInitScripts(t *testing.T) { t.Run("with init bash script", func(t *testing.T) { ctx := context.Background() - container, err := cassandra.RunContainer(ctx, cassandra.WithInitScripts(filepath.Join("testdata", "init.sh"))) + container, err := cassandra.Run(ctx, "cassandra:4.1.3", cassandra.WithInitScripts(filepath.Join("testdata", "init.sh"))) if err != nil { t.Fatal(err) } diff --git a/modules/cassandra/examples_test.go b/modules/cassandra/examples_test.go index 97d1e6a9ec..f80cb3f666 100644 --- a/modules/cassandra/examples_test.go +++ b/modules/cassandra/examples_test.go @@ -8,16 +8,15 @@ import ( "github.com/gocql/gocql" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/cassandra" ) -func ExampleRunContainer() { +func ExampleRun() { // runCassandraContainer { ctx := context.Background() - cassandraContainer, err := cassandra.RunContainer(ctx, - testcontainers.WithImage("cassandra:4.1.3"), + cassandraContainer, err := cassandra.Run(ctx, + "cassandra:4.1.3", cassandra.WithInitScripts(filepath.Join("testdata", "init.cql")), cassandra.WithConfigFile(filepath.Join("testdata", "config.yaml")), ) diff --git a/modules/chroma/chroma.go b/modules/chroma/chroma.go index 16488b1cb5..d0d633f390 100644 --- a/modules/chroma/chroma.go +++ b/modules/chroma/chroma.go @@ -13,10 +13,16 @@ type ChromaContainer struct { testcontainers.Container } +// Deprecated: use Run instead // RunContainer creates an instance of the Chroma container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) { + return Run(ctx, "chromadb/chroma:0.4.24", opts...) +} + +// Run creates an instance of the Chroma container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ChromaContainer, error) { req := testcontainers.ContainerRequest{ - Image: "chromadb/chroma:0.4.24", + Image: img, ExposedPorts: []string{"8000/tcp"}, WaitingFor: wait.ForAll( wait.ForListeningPort("8000/tcp"), diff --git a/modules/chroma/chroma_test.go b/modules/chroma/chroma_test.go index deea10be23..0e33d059f7 100644 --- a/modules/chroma/chroma_test.go +++ b/modules/chroma/chroma_test.go @@ -8,14 +8,13 @@ import ( chromago "github.com/amikos-tech/chroma-go" "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/chroma" ) func TestChroma(t *testing.T) { ctx := context.Background() - container, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24")) + container, err := chroma.Run(ctx, "chromadb/chroma:0.4.24") if err != nil { t.Fatal(err) } diff --git a/modules/chroma/examples_test.go b/modules/chroma/examples_test.go index 07bf04813c..1828c1eef4 100644 --- a/modules/chroma/examples_test.go +++ b/modules/chroma/examples_test.go @@ -12,11 +12,11 @@ import ( "github.com/testcontainers/testcontainers-go/modules/chroma" ) -func ExampleRunContainer() { +func ExampleRun() { // runChromaContainer { ctx := context.Background() - chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24")) + chromaContainer, err := chroma.Run(ctx, "chromadb/chroma:0.4.24") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -44,7 +44,7 @@ func ExampleChromaContainer_connectWithClient() { // createClient { ctx := context.Background() - chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24")) + chromaContainer, err := chroma.Run(ctx, "chromadb/chroma:0.4.24") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -81,7 +81,7 @@ func ExampleChromaContainer_connectWithClient() { func ExampleChromaContainer_collections() { ctx := context.Background() - chromaContainer, err := chroma.RunContainer(ctx, testcontainers.WithImage("chromadb/chroma:0.4.24"), testcontainers.WithEnv(map[string]string{"ALLOW_RESET": "true"})) + chromaContainer, err := chroma.Run(ctx, "chromadb/chroma:0.4.24", testcontainers.WithEnv(map[string]string{"ALLOW_RESET": "true"})) if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/clickhouse/clickhouse.go b/modules/clickhouse/clickhouse.go index 5c74ffa488..88b8b82d4b 100644 --- a/modules/clickhouse/clickhouse.go +++ b/modules/clickhouse/clickhouse.go @@ -24,8 +24,6 @@ const ( defaultDatabaseName = "clickhouse" ) -const defaultImage = "clickhouse/clickhouse-server:23.3.8.21-alpine" - const ( // containerPorts { httpPort = nat.Port("8123/tcp") @@ -216,10 +214,16 @@ func WithUsername(user string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the ClickHouse container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error) { + return Run(ctx, "clickhouse/clickhouse-server:23.3.8.21-alpine", opts...) +} + +// Run creates an instance of the ClickHouse container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ClickHouseContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, Env: map[string]string{ "CLICKHOUSE_USER": defaultUser, "CLICKHOUSE_PASSWORD": defaultUser, diff --git a/modules/clickhouse/clickhouse_test.go b/modules/clickhouse/clickhouse_test.go index 970106a471..9aa338eaaf 100644 --- a/modules/clickhouse/clickhouse_test.go +++ b/modules/clickhouse/clickhouse_test.go @@ -30,7 +30,7 @@ type Test struct { func TestClickHouseDefaultConfig(t *testing.T) { ctx := context.Background() - container, err := clickhouse.RunContainer(ctx) + container, err := clickhouse.Run(ctx, "clickhouse/clickhouse-server:23.3.8.21-alpine") if err != nil { t.Fatal(err) } @@ -62,7 +62,8 @@ func TestClickHouseDefaultConfig(t *testing.T) { func TestClickHouseConnectionHost(t *testing.T) { ctx := context.Background() - container, err := clickhouse.RunContainer(ctx, + container, err := clickhouse.Run(ctx, + "clickhouse/clickhouse-server:23.3.8.21-alpine", clickhouse.WithUsername(user), clickhouse.WithPassword(password), clickhouse.WithDatabase(dbname), @@ -102,7 +103,12 @@ func TestClickHouseConnectionHost(t *testing.T) { func TestClickHouseDSN(t *testing.T) { ctx := context.Background() - container, err := clickhouse.RunContainer(ctx, clickhouse.WithUsername(user), clickhouse.WithPassword(password), clickhouse.WithDatabase(dbname)) + container, err := clickhouse.Run(ctx, + "clickhouse/clickhouse-server:23.3.8.21-alpine", + clickhouse.WithUsername(user), + clickhouse.WithPassword(password), + clickhouse.WithDatabase(dbname), + ) if err != nil { t.Fatal(err) } @@ -135,7 +141,8 @@ func TestClickHouseWithInitScripts(t *testing.T) { ctx := context.Background() // withInitScripts { - container, err := clickhouse.RunContainer(ctx, + container, err := clickhouse.Run(ctx, + "clickhouse/clickhouse-server:23.3.8.21-alpine", clickhouse.WithUsername(user), clickhouse.WithPassword(password), clickhouse.WithDatabase(dbname), @@ -184,7 +191,8 @@ func TestClickHouseWithConfigFile(t *testing.T) { } for _, tC := range testCases { t.Run(tC.desc, func(t *testing.T) { - container, err := clickhouse.RunContainer(ctx, + container, err := clickhouse.Run(ctx, + "clickhouse/clickhouse-server:23.3.8.21-alpine", clickhouse.WithUsername(user), clickhouse.WithPassword(""), clickhouse.WithDatabase(dbname), @@ -245,7 +253,8 @@ func TestClickHouseWithZookeeper(t *testing.T) { t.Fatal(err) } - container, err := clickhouse.RunContainer(ctx, + container, err := clickhouse.Run(ctx, + "clickhouse/clickhouse-server:23.3.8.21-alpine", clickhouse.WithUsername(user), clickhouse.WithPassword(password), clickhouse.WithDatabase(dbname), diff --git a/modules/clickhouse/examples_test.go b/modules/clickhouse/examples_test.go index 8eccfc7aa7..d63c440541 100644 --- a/modules/clickhouse/examples_test.go +++ b/modules/clickhouse/examples_test.go @@ -9,11 +9,10 @@ import ( ch "github.com/ClickHouse/clickhouse-go/v2" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/clickhouse" ) -func ExampleRunContainer() { +func ExampleRun() { // runClickHouseContainer { ctx := context.Background() @@ -21,8 +20,8 @@ func ExampleRunContainer() { password := "password" dbname := "testdb" - clickHouseContainer, err := clickhouse.RunContainer(ctx, - testcontainers.WithImage("clickhouse/clickhouse-server:23.3.8.21-alpine"), + clickHouseContainer, err := clickhouse.Run(ctx, + "clickhouse/clickhouse-server:23.3.8.21-alpine", clickhouse.WithUsername(user), clickhouse.WithPassword(password), clickhouse.WithDatabase(dbname), diff --git a/modules/cockroachdb/cockroachdb.go b/modules/cockroachdb/cockroachdb.go index bf113a60d0..e53ef08c6a 100644 --- a/modules/cockroachdb/cockroachdb.go +++ b/modules/cockroachdb/cockroachdb.go @@ -26,7 +26,6 @@ const ( defaultSQLPort = "26257/tcp" defaultAdminPort = "8080/tcp" - defaultImage = "cockroachdb/cockroach:latest-v23.1" defaultUser = "root" defaultPassword = "" defaultDatabase = "defaultdb" @@ -68,12 +67,18 @@ func (c *CockroachDBContainer) TLSConfig() (*tls.Config, error) { return connTLS(c.opts) } +// Deprecated: use Run instead // RunContainer creates an instance of the CockroachDB container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) { + return Run(ctx, "cockroachdb/cockroach:latest-v23.1", opts...) +} + +// Run creates an instance of the CockroachDB container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CockroachDBContainer, error) { o := defaultOptions() req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{ defaultSQLPort, defaultAdminPort, diff --git a/modules/cockroachdb/cockroachdb_test.go b/modules/cockroachdb/cockroachdb_test.go index f332c9d013..1f5a6df0ad 100644 --- a/modules/cockroachdb/cockroachdb_test.go +++ b/modules/cockroachdb/cockroachdb_test.go @@ -63,7 +63,7 @@ type AuthNSuite struct { func (suite *AuthNSuite) TestConnectionString() { ctx := context.Background() - container, err := cockroachdb.RunContainer(ctx, suite.opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", suite.opts...) suite.Require().NoError(err) suite.T().Cleanup(func() { @@ -101,7 +101,7 @@ func (suite *AuthNSuite) TestPing() { opts := suite.opts opts = append(opts, input.opts...) - container, err := cockroachdb.RunContainer(ctx, opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", opts...) suite.Require().NoError(err) suite.T().Cleanup(func() { @@ -122,7 +122,7 @@ func (suite *AuthNSuite) TestPing() { func (suite *AuthNSuite) TestQuery() { ctx := context.Background() - container, err := cockroachdb.RunContainer(ctx, suite.opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", suite.opts...) suite.Require().NoError(err) suite.T().Cleanup(func() { @@ -155,7 +155,7 @@ func (suite *AuthNSuite) TestWithWaitStrategyAndDeadline() { // This will never match a log statement suite.opts = append(suite.opts, testcontainers.WithWaitStrategyAndDeadline(time.Millisecond*250, wait.ForLog("Won't Exist In Logs"))) - container, err := cockroachdb.RunContainer(ctx, suite.opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", suite.opts...) suite.Require().ErrorIs(err, context.DeadlineExceeded) suite.T().Cleanup(func() { @@ -171,7 +171,7 @@ func (suite *AuthNSuite) TestWithWaitStrategyAndDeadline() { // This will timeout as we didn't give enough time for intialization, but would have succeeded otherwise suite.opts = append(suite.opts, testcontainers.WithWaitStrategyAndDeadline(time.Millisecond*20, wait.ForLog(nodeStartUpCompleted))) - container, err := cockroachdb.RunContainer(ctx, suite.opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", suite.opts...) suite.Require().ErrorIs(err, context.DeadlineExceeded) suite.T().Cleanup(func() { @@ -187,7 +187,7 @@ func (suite *AuthNSuite) TestWithWaitStrategyAndDeadline() { // This will succeed suite.opts = append(suite.opts, testcontainers.WithWaitStrategyAndDeadline(time.Second*60, wait.ForLog(nodeStartUpCompleted))) - container, err := cockroachdb.RunContainer(ctx, suite.opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", suite.opts...) suite.Require().NoError(err) conn, err := conn(ctx, container) @@ -209,7 +209,7 @@ func (suite *AuthNSuite) TestWithWaitStrategyAndDeadline() { // This will succeed suite.opts = append(suite.opts, testcontainers.WithWaitStrategyAndDeadline(time.Second*60, wait.ForHTTP("/health").WithPort("8080/tcp"))) - container, err := cockroachdb.RunContainer(ctx, suite.opts...) + container, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1", suite.opts...) suite.Require().NoError(err) conn, err := conn(ctx, container) diff --git a/modules/cockroachdb/examples_test.go b/modules/cockroachdb/examples_test.go index 97e1d7b2dd..b427846d4b 100644 --- a/modules/cockroachdb/examples_test.go +++ b/modules/cockroachdb/examples_test.go @@ -9,11 +9,11 @@ import ( "github.com/testcontainers/testcontainers-go/modules/cockroachdb" ) -func ExampleRunContainer() { +func ExampleRun() { // runCockroachDBContainer { ctx := context.Background() - cockroachdbContainer, err := cockroachdb.RunContainer(ctx) + cockroachdbContainer, err := cockroachdb.Run(ctx, "cockroachdb/cockroach:latest-v23.1") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/consul/consul.go b/modules/consul/consul.go index b1c79630b9..fab3c5b29d 100644 --- a/modules/consul/consul.go +++ b/modules/consul/consul.go @@ -14,6 +14,7 @@ const ( ) const ( + // Deprecated: it will be removed in the next major version. DefaultBaseImage = "docker.io/hashicorp/consul:1.15" ) @@ -61,11 +62,17 @@ func WithConfigFile(configPath string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the Consul container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ConsulContainer, error) { + return Run(ctx, "docker.io/hashicorp/consul:1.15", opts...) +} + +// Run creates an instance of the Consul container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ConsulContainer, error) { containerReq := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: DefaultBaseImage, + Image: img, ExposedPorts: []string{ defaultHttpApiPort + "/tcp", defaultBrokerPort + "/tcp", diff --git a/modules/consul/consul_test.go b/modules/consul/consul_test.go index e9f6bfa860..2b24457785 100644 --- a/modules/consul/consul_test.go +++ b/modules/consul/consul_test.go @@ -40,7 +40,7 @@ func TestConsul(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - container, err := consul.RunContainer(ctx, test.opts...) + container, err := consul.Run(ctx, "docker.io/hashicorp/consul:1.15", test.opts...) require.NoError(t, err) t.Cleanup(func() { require.NoError(t, container.Terminate(ctx), "failed to terminate container") }) diff --git a/modules/consul/examples_test.go b/modules/consul/examples_test.go index 002c143c95..a65a30c066 100644 --- a/modules/consul/examples_test.go +++ b/modules/consul/examples_test.go @@ -7,17 +7,14 @@ import ( capi "github.com/hashicorp/consul/api" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/consul" ) -func ExampleRunContainer() { +func ExampleRun() { // runConsulContainer { ctx := context.Background() - consulContainer, err := consul.RunContainer(ctx, - testcontainers.WithImage("docker.io/hashicorp/consul:1.15"), - ) + consulContainer, err := consul.Run(ctx, "docker.io/hashicorp/consul:1.15") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -41,13 +38,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connect() { +func ExampleRun_connect() { // connectConsul { ctx := context.Background() - consulContainer, err := consul.RunContainer(ctx, - testcontainers.WithImage("docker.io/hashicorp/consul:1.15"), - ) + consulContainer, err := consul.Run(ctx, "docker.io/hashicorp/consul:1.15") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/couchbase/couchbase.go b/modules/couchbase/couchbase.go index d9b468edb0..b0889f54b2 100644 --- a/modules/couchbase/couchbase.go +++ b/modules/couchbase/couchbase.go @@ -45,11 +45,6 @@ const ( // } ) -// defaultImage { -const defaultImage = "couchbase:6.5.1" - -// } - // initialServices is the list of services that are enabled by default var initialServices = []Service{kv, query, search, index} @@ -61,8 +56,14 @@ type CouchbaseContainer struct { config *Config } +// Deprecated: use Run instead // RunContainer creates an instance of the Couchbase container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error) { + return Run(ctx, "couchbase:6.5.1", opts...) +} + +// Run creates an instance of the Couchbase container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*CouchbaseContainer, error) { config := &Config{ enabledServices: make([]Service, 0), username: "Administrator", @@ -71,7 +72,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize } req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{MGMT_PORT + "/tcp", MGMT_SSL_PORT + "/tcp"}, } @@ -145,7 +146,6 @@ func StartContainer(ctx context.Context, opts ...Option) (*CouchbaseContainer, e } customizers := []testcontainers.ContainerCustomizer{ - testcontainers.WithImage(config.imageName), WithAdminCredentials(config.username, config.password), WithIndexStorage(config.indexStorageMode), WithBuckets(config.buckets...), @@ -155,7 +155,7 @@ func StartContainer(ctx context.Context, opts ...Option) (*CouchbaseContainer, e customizers = append(customizers, withService(srv)) } - return RunContainer(ctx, customizers...) + return Run(ctx, config.imageName, customizers...) } // ConnectionString returns the connection string to connect to the Couchbase container instance. diff --git a/modules/couchbase/couchbase_test.go b/modules/couchbase/couchbase_test.go index d416fa60ab..f05c08d16c 100644 --- a/modules/couchbase/couchbase_test.go +++ b/modules/couchbase/couchbase_test.go @@ -7,7 +7,6 @@ import ( "github.com/couchbase/gocb/v2" - "github.com/testcontainers/testcontainers-go" tccouchbase "github.com/testcontainers/testcontainers-go/modules/couchbase" ) @@ -30,7 +29,7 @@ func TestCouchbaseWithCommunityContainer(t *testing.T) { WithFlushEnabled(false). WithPrimaryIndex(true) - container, err := tccouchbase.RunContainer(ctx, testcontainers.WithImage(communityEdition), tccouchbase.WithBuckets(bucket)) + container, err := tccouchbase.Run(ctx, communityEdition, tccouchbase.WithBuckets(bucket)) if err != nil { t.Fatal(err) } @@ -55,7 +54,7 @@ func TestCouchbaseWithEnterpriseContainer(t *testing.T) { ctx := context.Background() bucketName := "testBucket" - container, err := tccouchbase.RunContainer(ctx, testcontainers.WithImage(enterpriseEdition), tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) + container, err := tccouchbase.Run(ctx, enterpriseEdition, tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) if err != nil { t.Fatal(err) } @@ -79,8 +78,8 @@ func TestWithCredentials(t *testing.T) { ctx := context.Background() bucketName := "testBucket" - _, err := tccouchbase.RunContainer(ctx, - testcontainers.WithImage(communityEdition), + _, err := tccouchbase.Run(ctx, + communityEdition, tccouchbase.WithAdminCredentials("testcontainers", "testcontainers.IS.cool!"), tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) if err != nil { @@ -92,8 +91,8 @@ func TestWithCredentials_Password_LessThan_6(t *testing.T) { ctx := context.Background() bucketName := "testBucket" - _, err := tccouchbase.RunContainer(ctx, - testcontainers.WithImage(communityEdition), + _, err := tccouchbase.Run(ctx, + communityEdition, tccouchbase.WithAdminCredentials("testcontainers", "12345"), tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) @@ -106,8 +105,8 @@ func TestAnalyticsServiceWithCommunityContainer(t *testing.T) { ctx := context.Background() bucketName := "testBucket" - _, err := tccouchbase.RunContainer(ctx, - testcontainers.WithImage(communityEdition), + _, err := tccouchbase.Run(ctx, + communityEdition, tccouchbase.WithServiceAnalytics(), tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) @@ -120,8 +119,8 @@ func TestEventingServiceWithCommunityContainer(t *testing.T) { ctx := context.Background() bucketName := "testBucket" - _, err := tccouchbase.RunContainer(ctx, - testcontainers.WithImage(communityEdition), + _, err := tccouchbase.Run(ctx, + communityEdition, tccouchbase.WithServiceEventing(), tccouchbase.WithBuckets(tccouchbase.NewBucket(bucketName))) diff --git a/modules/couchbase/examples_test.go b/modules/couchbase/examples_test.go index e89363d3ac..518b270613 100644 --- a/modules/couchbase/examples_test.go +++ b/modules/couchbase/examples_test.go @@ -7,11 +7,10 @@ import ( "github.com/couchbase/gocb/v2" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/couchbase" ) -func ExampleRunContainer() { +func ExampleRun() { // runCouchbaseContainer { ctx := context.Background() @@ -23,8 +22,8 @@ func ExampleRunContainer() { WithFlushEnabled(false). WithPrimaryIndex(true) - couchbaseContainer, err := couchbase.RunContainer(ctx, - testcontainers.WithImage("couchbase:community-7.1.1"), + couchbaseContainer, err := couchbase.Run(ctx, + "couchbase:community-7.1.1", couchbase.WithAdminCredentials("testcontainers", "testcontainers.IS.cool!"), couchbase.WithBuckets(bucket), ) diff --git a/modules/dolt/dolt.go b/modules/dolt/dolt.go index 2c5ca497ae..d819e18f5c 100644 --- a/modules/dolt/dolt.go +++ b/modules/dolt/dolt.go @@ -18,8 +18,6 @@ const ( defaultDatabaseName = "test" ) -const defaultImage = "dolthub/dolt-sql-server:1.32.4" - // DoltContainer represents the Dolt container type used in the module type DoltContainer struct { testcontainers.Container @@ -40,10 +38,16 @@ func WithDefaultCredentials() testcontainers.CustomizeRequestOption { } } -// RunContainer creates an instance of the Dolt container type +// Deprecated: use Run instead +// RunContainer creates an instance of the Couchbase container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error) { + return Run(ctx, "dolthub/dolt-sql-server:1.32.4", opts...) +} + +// Run creates an instance of the Dolt container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*DoltContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"3306/tcp", "33060/tcp"}, Env: map[string]string{ "DOLT_USER": defaultUser, diff --git a/modules/dolt/dolt_test.go b/modules/dolt/dolt_test.go index 253eb356fb..a24ace2919 100644 --- a/modules/dolt/dolt_test.go +++ b/modules/dolt/dolt_test.go @@ -16,7 +16,7 @@ import ( func TestDolt(t *testing.T) { ctx := context.Background() - container, err := dolt.RunContainer(ctx) + container, err := dolt.Run(ctx, "dolthub/dolt-sql-server:1.32.4") if err != nil { t.Fatal(err) } @@ -58,7 +58,8 @@ func TestDolt(t *testing.T) { func TestDoltWithNonRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - _, err := dolt.RunContainer(ctx, + _, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithDatabase("foo"), dolt.WithUsername("test"), dolt.WithPassword("")) @@ -70,7 +71,8 @@ func TestDoltWithNonRootUserAndEmptyPassword(t *testing.T) { func TestDoltWithPublicRemoteCloneUrl(t *testing.T) { ctx := context.Background() - _, err := dolt.RunContainer(ctx, + _, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithDatabase("foo"), dolt.WithUsername("test"), dolt.WithPassword("test"), @@ -99,7 +101,8 @@ func TestDoltWithPrivateRemoteCloneUrl(t *testing.T) { filename := createTestCredsFile(t) defer os.RemoveAll(filename) - _, err := dolt.RunContainer(ctx, + _, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithDatabase("foo"), dolt.WithUsername("test"), dolt.WithPassword("test"), @@ -115,7 +118,8 @@ func TestDoltWithPrivateRemoteCloneUrl(t *testing.T) { func TestDoltWithRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - container, err := dolt.RunContainer(ctx, + container, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithDatabase("foo"), dolt.WithUsername("root"), dolt.WithPassword("")) @@ -155,7 +159,8 @@ func TestDoltWithRootUserAndEmptyPassword(t *testing.T) { func TestDoltWithScripts(t *testing.T) { ctx := context.Background() - container, err := dolt.RunContainer(ctx, + container, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) diff --git a/modules/dolt/examples_test.go b/modules/dolt/examples_test.go index ceb6a79a14..73e430d871 100644 --- a/modules/dolt/examples_test.go +++ b/modules/dolt/examples_test.go @@ -7,16 +7,15 @@ import ( "log" "path/filepath" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/dolt" ) -func ExampleRunContainer() { +func ExampleRun() { // runDoltContainer { ctx := context.Background() - doltContainer, err := dolt.RunContainer(ctx, - testcontainers.WithImage("dolthub/dolt-sql-server:1.32.4"), + doltContainer, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithConfigFile(filepath.Join("testdata", "dolt_1_32_4.cnf")), dolt.WithDatabase("foo"), dolt.WithUsername("root"), @@ -46,11 +45,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connect() { +func ExampleRun_connect() { ctx := context.Background() - doltContainer, err := dolt.RunContainer(ctx, - testcontainers.WithImage("dolthub/dolt-sql-server:1.32.4"), + doltContainer, err := dolt.Run(ctx, + "dolthub/dolt-sql-server:1.32.4", dolt.WithConfigFile(filepath.Join("testdata", "dolt_1_32_4.cnf")), dolt.WithDatabase("foo"), dolt.WithUsername("bar"), diff --git a/modules/elasticsearch/elasticsearch.go b/modules/elasticsearch/elasticsearch.go index 2ea0a8b8ba..10a863c589 100644 --- a/modules/elasticsearch/elasticsearch.go +++ b/modules/elasticsearch/elasticsearch.go @@ -19,7 +19,9 @@ const ( ) const ( - DefaultBaseImage = "docker.elastic.co/elasticsearch/elasticsearch" + // Deprecated: it will be removed in the next major version + DefaultBaseImage = "docker.elastic.co/elasticsearch/elasticsearch" + // Deprecated: it will be removed in the next major version DefaultBaseImageOSS = "docker.elastic.co/elasticsearch/elasticsearch-oss" ) @@ -29,11 +31,17 @@ type ElasticsearchContainer struct { Settings Options } -// RunContainer creates an instance of the Elasticsearch container type +// Deprecated: use Run instead +// RunContainer creates an instance of the Couchbase container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error) { + return Run(ctx, "docker.elastic.co/elasticsearch/elasticsearch:7.9.2", opts...) +} + +// Run creates an instance of the Elasticsearch container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*ElasticsearchContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: fmt.Sprintf("%s:%s", DefaultBaseImage, minimalImageVersion), + Image: img, Env: map[string]string{ "discovery.type": "single-node", "cluster.routing.allocation.disk.threshold_enabled": "false", diff --git a/modules/elasticsearch/elasticsearch_test.go b/modules/elasticsearch/elasticsearch_test.go index 9141558dc8..1bc7d79456 100644 --- a/modules/elasticsearch/elasticsearch_test.go +++ b/modules/elasticsearch/elasticsearch_test.go @@ -73,13 +73,13 @@ func TestElasticsearch(t *testing.T) { t.Run(tt.name, func(t *testing.T) { ctx := context.Background() - opts := []testcontainers.ContainerCustomizer{testcontainers.WithImage(tt.image)} + opts := []testcontainers.ContainerCustomizer{} if tt.passwordCustomiser != nil { opts = append(opts, tt.passwordCustomiser) } - esContainer, err := elasticsearch.RunContainer(ctx, opts...) + esContainer, err := elasticsearch.Run(ctx, tt.image, opts...) if err != nil { t.Fatal(err) } @@ -184,9 +184,9 @@ func TestElasticsearch8WithoutSSL(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { ctx := context.Background() - container, err := elasticsearch.RunContainer( + container, err := elasticsearch.Run( ctx, - testcontainers.WithImage(baseImage8), + baseImage8, testcontainers.WithEnv(map[string]string{ test.configKey: "false", })) @@ -210,7 +210,7 @@ func TestElasticsearch8WithoutSSL(t *testing.T) { func TestElasticsearch8WithoutCredentials(t *testing.T) { ctx := context.Background() - container, err := elasticsearch.RunContainer(ctx, testcontainers.WithImage(baseImage8)) + container, err := elasticsearch.Run(ctx, baseImage8) if err != nil { t.Fatal(err) } @@ -253,7 +253,7 @@ func TestElasticsearchOSSCannotuseWithPassword(t *testing.T) { ossImage := elasticsearch.DefaultBaseImageOSS + ":7.9.2" - _, err := elasticsearch.RunContainer(ctx, testcontainers.WithImage(ossImage), elasticsearch.WithPassword("foo")) + _, err := elasticsearch.Run(ctx, ossImage, elasticsearch.WithPassword("foo")) if err == nil { t.Fatal(err, "Should not be able to use WithPassword with OSS image.") } diff --git a/modules/elasticsearch/examples_test.go b/modules/elasticsearch/examples_test.go index 09ba893e43..db578a46ee 100644 --- a/modules/elasticsearch/examples_test.go +++ b/modules/elasticsearch/examples_test.go @@ -9,14 +9,13 @@ import ( es "github.com/elastic/go-elasticsearch/v8" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/elasticsearch" ) -func ExampleRunContainer() { +func ExampleRun() { // runElasticsearchContainer { ctx := context.Background() - elasticsearchContainer, err := elasticsearch.RunContainer(ctx, testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.9.0")) + elasticsearchContainer, err := elasticsearch.Run(ctx, "docker.elastic.co/elasticsearch/elasticsearch:8.9.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -38,12 +37,12 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_withUsingPassword() { +func ExampleRun_withUsingPassword() { // usingPassword { ctx := context.Background() - elasticsearchContainer, err := elasticsearch.RunContainer( + elasticsearchContainer, err := elasticsearch.Run( ctx, - testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:7.9.2"), + "docker.elastic.co/elasticsearch/elasticsearch:7.9.2", elasticsearch.WithPassword("foo"), ) if err != nil { @@ -65,12 +64,12 @@ func ExampleRunContainer_withUsingPassword() { // foo } -func ExampleRunContainer_connectUsingElasticsearchClient() { +func ExampleRun_connectUsingElasticsearchClient() { // elasticsearchClient { ctx := context.Background() - elasticsearchContainer, err := elasticsearch.RunContainer( + elasticsearchContainer, err := elasticsearch.Run( ctx, - testcontainers.WithImage("docker.elastic.co/elasticsearch/elasticsearch:8.9.0"), + "docker.elastic.co/elasticsearch/elasticsearch:8.9.0", elasticsearch.WithPassword("foo"), ) if err != nil { diff --git a/modules/gcloud/bigquery.go b/modules/gcloud/bigquery.go index d06562a7ad..54363dc2f2 100644 --- a/modules/gcloud/bigquery.go +++ b/modules/gcloud/bigquery.go @@ -8,12 +8,18 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) +// Deprecated: use RunBigQuery instead // RunBigQueryContainer creates an instance of the GCloud container type for BigQuery. -// The URI will always use http:// as the protocol. func RunBigQueryContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { + return RunBigQuery(ctx, "ghcr.io/goccy/bigquery-emulator:0.4.3", opts...) +} + +// RunBigQuery creates an instance of the GCloud container type for BigQuery. +// The URI will always use http:// as the protocol. +func RunBigQuery(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "ghcr.io/goccy/bigquery-emulator:0.4.3", + Image: img, ExposedPorts: []string{"9050/tcp", "9060/tcp"}, WaitingFor: wait.ForHTTP("/discovery/v1/apis/bigquery/v2/rest").WithPort("9050/tcp").WithStartupTimeout(time.Second * 5), }, diff --git a/modules/gcloud/bigquery_test.go b/modules/gcloud/bigquery_test.go index 08bbd46a3a..a39347a23f 100644 --- a/modules/gcloud/bigquery_test.go +++ b/modules/gcloud/bigquery_test.go @@ -13,7 +13,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/gcloud" ) @@ -21,9 +20,9 @@ func ExampleRunBigQueryContainer() { // runBigQueryContainer { ctx := context.Background() - bigQueryContainer, err := gcloud.RunBigQueryContainer( + bigQueryContainer, err := gcloud.RunBigQuery( ctx, - testcontainers.WithImage("ghcr.io/goccy/bigquery-emulator:0.4.3"), + "ghcr.io/goccy/bigquery-emulator:0.4.3", gcloud.WithProjectID("bigquery-project"), ) if err != nil { diff --git a/modules/gcloud/bigtable.go b/modules/gcloud/bigtable.go index 8294ad2678..4bea521ff1 100644 --- a/modules/gcloud/bigtable.go +++ b/modules/gcloud/bigtable.go @@ -8,11 +8,17 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// RunBigTableContainer creates an instance of the GCloud container type for BigTable +// Deprecated: use RunBigTable instead +// RunBigTableContainer creates an instance of the GCloud container type for BigTable. func RunBigTableContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { + return RunBigQuery(ctx, "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", opts...) +} + +// RunBigTable creates an instance of the GCloud container type for BigTable. +func RunBigTable(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", + Image: img, ExposedPorts: []string{"9000/tcp"}, WaitingFor: wait.ForLog("running"), }, diff --git a/modules/gcloud/bigtable_test.go b/modules/gcloud/bigtable_test.go index 0504d68fc0..15409e2b0e 100644 --- a/modules/gcloud/bigtable_test.go +++ b/modules/gcloud/bigtable_test.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/gcloud" ) @@ -18,9 +17,9 @@ func ExampleRunBigTableContainer() { // runBigTableContainer { ctx := context.Background() - bigTableContainer, err := gcloud.RunBigTableContainer( + bigTableContainer, err := gcloud.RunBigTable( ctx, - testcontainers.WithImage("gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators"), + "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", gcloud.WithProjectID("bigtable-project"), ) if err != nil { diff --git a/modules/gcloud/datastore.go b/modules/gcloud/datastore.go index 72b487f12b..92ab671842 100644 --- a/modules/gcloud/datastore.go +++ b/modules/gcloud/datastore.go @@ -8,11 +8,17 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// RunDatastoreContainer creates an instance of the GCloud container type for Datastore +// Deprecated: use RunDatastore instead +// RunDatastoreContainer creates an instance of the GCloud container type for Datastore. func RunDatastoreContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { + return RunDatastore(ctx, "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", opts...) +} + +// RunDatastore creates an instance of the GCloud container type for Datastore. +func RunDatastore(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", + Image: img, ExposedPorts: []string{"8081/tcp"}, WaitingFor: wait.ForHTTP("/").WithPort("8081/tcp"), }, diff --git a/modules/gcloud/datastore_test.go b/modules/gcloud/datastore_test.go index e9db5116d3..0cf04780ef 100644 --- a/modules/gcloud/datastore_test.go +++ b/modules/gcloud/datastore_test.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/gcloud" ) @@ -18,9 +17,9 @@ func ExampleRunDatastoreContainer() { // runDatastoreContainer { ctx := context.Background() - datastoreContainer, err := gcloud.RunDatastoreContainer( + datastoreContainer, err := gcloud.RunDatastore( ctx, - testcontainers.WithImage("gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators"), + "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", gcloud.WithProjectID("datastore-project"), ) if err != nil { diff --git a/modules/gcloud/firestore.go b/modules/gcloud/firestore.go index ee998a55b3..7f9ced72f7 100644 --- a/modules/gcloud/firestore.go +++ b/modules/gcloud/firestore.go @@ -8,11 +8,17 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// RunFirestoreContainer creates an instance of the GCloud container type for Firestore +// Deprecated: use RunFirestore instead +// RunFirestoreContainer creates an instance of the GCloud container type for Firestore. func RunFirestoreContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { + return RunFirestore(ctx, "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", opts...) +} + +// RunFirestore creates an instance of the GCloud container type for Firestore. +func RunFirestore(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", + Image: img, ExposedPorts: []string{"8080/tcp"}, WaitingFor: wait.ForLog("running"), }, diff --git a/modules/gcloud/firestore_test.go b/modules/gcloud/firestore_test.go index 3e1c6f7977..bf9a4d2770 100644 --- a/modules/gcloud/firestore_test.go +++ b/modules/gcloud/firestore_test.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/gcloud" ) @@ -28,9 +27,9 @@ func ExampleRunFirestoreContainer() { // runFirestoreContainer { ctx := context.Background() - firestoreContainer, err := gcloud.RunFirestoreContainer( + firestoreContainer, err := gcloud.RunFirestore( ctx, - testcontainers.WithImage("gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators"), + "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", gcloud.WithProjectID("firestore-project"), ) if err != nil { diff --git a/modules/gcloud/pubsub.go b/modules/gcloud/pubsub.go index bf83f3a2f5..a2a4e74a1c 100644 --- a/modules/gcloud/pubsub.go +++ b/modules/gcloud/pubsub.go @@ -8,11 +8,17 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// RunPubsubContainer creates an instance of the GCloud container type for Pubsub +// Deprecated: use RunPubsub instead +// RunPubsubContainer creates an instance of the GCloud container type for Pubsub. func RunPubsubContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { + return RunPubsub(ctx, "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", opts...) +} + +// RunPubsub creates an instance of the GCloud container type for Pubsub. +func RunPubsub(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", + Image: img, ExposedPorts: []string{"8085/tcp"}, WaitingFor: wait.ForLog("started"), }, diff --git a/modules/gcloud/pubsub_test.go b/modules/gcloud/pubsub_test.go index 5d46424f42..5aeaee6def 100644 --- a/modules/gcloud/pubsub_test.go +++ b/modules/gcloud/pubsub_test.go @@ -10,7 +10,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/gcloud" ) @@ -18,9 +17,9 @@ func ExampleRunPubsubContainer() { // runPubsubContainer { ctx := context.Background() - pubsubContainer, err := gcloud.RunPubsubContainer( + pubsubContainer, err := gcloud.RunPubsub( ctx, - testcontainers.WithImage("gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators"), + "gcr.io/google.com/cloudsdktool/cloud-sdk:367.0.0-emulators", gcloud.WithProjectID("pubsub-project"), ) if err != nil { diff --git a/modules/gcloud/spanner.go b/modules/gcloud/spanner.go index eb7d10ea8c..d57154ab1d 100644 --- a/modules/gcloud/spanner.go +++ b/modules/gcloud/spanner.go @@ -7,11 +7,17 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// RunSpannerContainer creates an instance of the GCloud container type for Spanner +// Deprecated: use RunSpanner instead +// RunSpannerContainer creates an instance of the GCloud container type for Spanner. func RunSpannerContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { + return RunSpanner(ctx, "gcr.io/cloud-spanner-emulator/emulator:1.4.0", opts...) +} + +// RunSpanner creates an instance of the GCloud container type for Spanner. +func RunSpanner(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*GCloudContainer, error) { req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "gcr.io/cloud-spanner-emulator/emulator:1.4.0", + Image: img, ExposedPorts: []string{"9010/tcp"}, WaitingFor: wait.ForLog("Cloud Spanner emulator running"), }, diff --git a/modules/gcloud/spanner_test.go b/modules/gcloud/spanner_test.go index e50777142a..10fdec441f 100644 --- a/modules/gcloud/spanner_test.go +++ b/modules/gcloud/spanner_test.go @@ -15,7 +15,6 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/gcloud" ) @@ -23,9 +22,9 @@ func ExampleRunSpannerContainer() { // runSpannerContainer { ctx := context.Background() - spannerContainer, err := gcloud.RunSpannerContainer( + spannerContainer, err := gcloud.RunSpanner( ctx, - testcontainers.WithImage("gcr.io/cloud-spanner-emulator/emulator:1.4.0"), + "gcr.io/cloud-spanner-emulator/emulator:1.4.0", gcloud.WithProjectID("spanner-project"), ) if err != nil { diff --git a/modules/inbucket/examples_test.go b/modules/inbucket/examples_test.go index b5c72d12b4..7680a9563a 100644 --- a/modules/inbucket/examples_test.go +++ b/modules/inbucket/examples_test.go @@ -5,15 +5,14 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/inbucket" ) -func ExampleRunContainer() { +func ExampleRun() { // runInbucketContainer { ctx := context.Background() - inbucketContainer, err := inbucket.RunContainer(ctx, testcontainers.WithImage("inbucket/inbucket:sha-2d409bb")) + inbucketContainer, err := inbucket.Run(ctx, "inbucket/inbucket:sha-2d409bb") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/inbucket/inbucket.go b/modules/inbucket/inbucket.go index c446404df3..214e1c619c 100644 --- a/modules/inbucket/inbucket.go +++ b/modules/inbucket/inbucket.go @@ -47,10 +47,16 @@ func (c *InbucketContainer) WebInterface(ctx context.Context) (string, error) { return fmt.Sprintf("http://%s", net.JoinHostPort(host, containerPort.Port())), nil } +// Deprecated: use Run instead // RunContainer creates an instance of the Inbucket container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InbucketContainer, error) { + return Run(ctx, "inbucket/inbucket:sha-2d409bb", opts...) +} + +// Run creates an instance of the Inbucket container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InbucketContainer, error) { req := testcontainers.ContainerRequest{ - Image: "inbucket/inbucket:sha-2d409bb", + Image: img, ExposedPorts: []string{"2500/tcp", "9000/tcp"}, WaitingFor: wait.ForLog("SMTP listening on tcp4"), } diff --git a/modules/inbucket/inbucket_test.go b/modules/inbucket/inbucket_test.go index 16b5bd90e9..8c2c479aed 100644 --- a/modules/inbucket/inbucket_test.go +++ b/modules/inbucket/inbucket_test.go @@ -6,14 +6,12 @@ import ( "testing" "github.com/inbucket/inbucket/pkg/rest/client" - - "github.com/testcontainers/testcontainers-go" ) func TestInbucket(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("inbucket/inbucket:sha-2d409bb")) + container, err := Run(ctx, "inbucket/inbucket:sha-2d409bb") if err != nil { t.Fatal(err) } diff --git a/modules/influxdb/examples_test.go b/modules/influxdb/examples_test.go index 23923882f8..2d37117993 100644 --- a/modules/influxdb/examples_test.go +++ b/modules/influxdb/examples_test.go @@ -5,16 +5,15 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/influxdb" ) -func ExampleRunContainer() { +func ExampleRun() { // runInfluxContainer { ctx := context.Background() - influxdbContainer, err := influxdb.RunContainer( - ctx, testcontainers.WithImage("influxdb:1.8.10"), + influxdbContainer, err := influxdb.Run(ctx, + "influxdb:1.8.10", influxdb.WithDatabase("influx"), influxdb.WithUsername("root"), influxdb.WithPassword("password"), diff --git a/modules/influxdb/influxdb.go b/modules/influxdb/influxdb.go index 446cf2d1b7..d359c8cbbc 100644 --- a/modules/influxdb/influxdb.go +++ b/modules/influxdb/influxdb.go @@ -10,20 +10,21 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// defaultImage { -const defaultImage = "influxdb:1.8" - -// } - // InfluxDbContainer represents the MySQL container type used in the module type InfluxDbContainer struct { testcontainers.Container } +// Deprecated: use Run instead // RunContainer creates an instance of the InfluxDB container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) { + return Run(ctx, "influxdb:1.8", opts...) +} + +// Run creates an instance of the InfluxDB container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*InfluxDbContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"8086/tcp", "8088/tcp"}, Env: map[string]string{ "INFLUXDB_BIND_ADDRESS": ":8088", diff --git a/modules/influxdb/influxdb_test.go b/modules/influxdb/influxdb_test.go index 92311057d5..6ec5ec7399 100644 --- a/modules/influxdb/influxdb_test.go +++ b/modules/influxdb/influxdb_test.go @@ -22,9 +22,7 @@ func containerCleanup(t *testing.T, container testcontainers.Container) { func TestV1Container(t *testing.T) { ctx := context.Background() - influxDbContainer, err := influxdb.RunContainer(ctx, - testcontainers.WithImage("influxdb:1.8.10"), - ) + influxDbContainer, err := influxdb.Run(ctx, "influxdb:1.8.10") require.NoError(t, err) t.Cleanup(func() { containerCleanup(t, influxDbContainer) @@ -40,8 +38,8 @@ func TestV1Container(t *testing.T) { func TestV2Container(t *testing.T) { ctx := context.Background() - influxDbContainer, err := influxdb.RunContainer(ctx, - testcontainers.WithImage("influxdb:2.7.5-alpine"), + influxDbContainer, err := influxdb.Run(ctx, + "influxdb:2.7.5-alpine", influxdb.WithDatabase("foo"), influxdb.WithUsername("root"), influxdb.WithPassword("password"), @@ -61,8 +59,8 @@ func TestV2Container(t *testing.T) { func TestWithInitDb(t *testing.T) { ctx := context.Background() - influxDbContainer, err := influxdb.RunContainer(ctx, - testcontainers.WithImage("influxdb:1.8.10"), + influxDbContainer, err := influxdb.Run(ctx, + "influxdb:1.8.10", influxdb.WithInitDb("testdata"), ) require.NoError(t, err) @@ -97,8 +95,8 @@ func TestWithInitDb(t *testing.T) { func TestWithConfigFile(t *testing.T) { influxVersion := "1.8.10" - influxDbContainer, err := influxdb.RunContainer(context.Background(), - testcontainers.WithImage("influxdb:"+influxVersion), + influxDbContainer, err := influxdb.Run(context.Background(), + "influxdb:"+influxVersion, influxdb.WithConfigFile(filepath.Join("testdata", "influxdb.conf")), ) require.NoError(t, err) diff --git a/modules/k3s/k3s.go b/modules/k3s/k3s.go index 4190cfba71..f6cfb055c4 100644 --- a/modules/k3s/k3s.go +++ b/modules/k3s/k3s.go @@ -47,15 +47,21 @@ func WithManifest(manifestPath string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the K3s container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error) { + return Run(ctx, "docker.io/rancher/k3s:v1.27.1-k3s1", opts...) +} + +// Run creates an instance of the K3s container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K3sContainer, error) { host, err := getContainerHost(ctx, opts...) if err != nil { return nil, err } req := testcontainers.ContainerRequest{ - Image: "docker.io/rancher/k3s:v1.27.1-k3s1", + Image: img, ExposedPorts: []string{ defaultKubeSecurePort, defaultRancherWebhookPort, diff --git a/modules/k3s/k3s_example_test.go b/modules/k3s/k3s_example_test.go index 2d065bc70a..eef8f87280 100644 --- a/modules/k3s/k3s_example_test.go +++ b/modules/k3s/k3s_example_test.go @@ -9,17 +9,14 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/k3s" ) -func ExampleRunContainer() { +func ExampleRun() { // runK3sContainer { ctx := context.Background() - k3sContainer, err := k3s.RunContainer(ctx, - testcontainers.WithImage("docker.io/rancher/k3s:v1.27.1-k3s1"), - ) + k3sContainer, err := k3s.Run(ctx, "docker.io/rancher/k3s:v1.27.1-k3s1") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/k3s/k3s_test.go b/modules/k3s/k3s_test.go index 38d41094de..7a5fe0d94b 100644 --- a/modules/k3s/k3s_test.go +++ b/modules/k3s/k3s_test.go @@ -22,9 +22,7 @@ func Test_LoadImages(t *testing.T) { ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(3*time.Minute)) defer cancel() - k3sContainer, err := k3s.RunContainer(ctx, - testcontainers.WithImage("docker.io/rancher/k3s:v1.27.1-k3s1"), - ) + k3sContainer, err := k3s.Run(ctx, "docker.io/rancher/k3s:v1.27.1-k3s1") if err != nil { t.Fatal(err) } @@ -136,9 +134,7 @@ func getTestPodState(ctx context.Context, k8s *kubernetes.Clientset) (corev1.Con func Test_APIServerReady(t *testing.T) { ctx := context.Background() - k3sContainer, err := k3s.RunContainer(ctx, - testcontainers.WithImage("docker.io/rancher/k3s:v1.27.1-k3s1"), - ) + k3sContainer, err := k3s.Run(ctx, "docker.io/rancher/k3s:v1.27.1-k3s1") if err != nil { t.Fatal(err) } @@ -192,8 +188,8 @@ func Test_APIServerReady(t *testing.T) { func Test_WithManifestOption(t *testing.T) { ctx := context.Background() - k3sContainer, err := k3s.RunContainer(ctx, - testcontainers.WithImage("docker.io/rancher/k3s:v1.27.1-k3s1"), + k3sContainer, err := k3s.Run(ctx, + "docker.io/rancher/k3s:v1.27.1-k3s1", k3s.WithManifest("nginx-manifest.yaml"), testcontainers.WithWaitStrategy(wait.ForExec([]string{"kubectl", "wait", "pod", "nginx", "--for=condition=Ready"})), ) diff --git a/modules/k6/examples_test.go b/modules/k6/examples_test.go index 99cc77dcde..468d113450 100644 --- a/modules/k6/examples_test.go +++ b/modules/k6/examples_test.go @@ -11,7 +11,7 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -func ExampleRunContainer() { +func ExampleRun() { // runHTTPBin { ctx := context.Background() @@ -54,8 +54,9 @@ func ExampleRunContainer() { // runK6Container { // run the httpbin.js test scripts passing the IP address the httpbin container - k6, err := k6.RunContainer( + k6, err := k6.Run( ctx, + "szkiba/k6x:v0.3.1", k6.WithCache(), k6.WithTestScript(absPath), k6.SetEnvVar("HTTPBIN", httpbinIP), diff --git a/modules/k6/k6.go b/modules/k6/k6.go index 4e0decb2db..591cd48f0c 100644 --- a/modules/k6/k6.go +++ b/modules/k6/k6.go @@ -160,10 +160,16 @@ func WithCache() testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the K6 container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { + return Run(ctx, "szkiba/k6x:v0.3.1", opts...) +} + +// Run creates an instance of the K6 container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*K6Container, error) { req := testcontainers.ContainerRequest{ - Image: "szkiba/k6x:v0.3.1", + Image: img, Cmd: []string{"run"}, WaitingFor: wait.ForExit(), } diff --git a/modules/k6/k6_test.go b/modules/k6/k6_test.go index 29a7c2bcce..ead72dcac4 100644 --- a/modules/k6/k6_test.go +++ b/modules/k6/k6_test.go @@ -62,7 +62,7 @@ func TestK6(t *testing.T) { options = k6.WithRemoteTestScript(desc) } - container, err := k6.RunContainer(ctx, k6.WithCache(), options) + container, err := k6.Run(ctx, "szkiba/k6x:v0.3.1", k6.WithCache(), options) if err != nil { t.Fatal(err) } diff --git a/modules/kafka/examples_test.go b/modules/kafka/examples_test.go index ee68cca9ff..2b547970fc 100644 --- a/modules/kafka/examples_test.go +++ b/modules/kafka/examples_test.go @@ -5,17 +5,16 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/kafka" ) -func ExampleRunContainer() { +func ExampleRun() { // runKafkaContainer { ctx := context.Background() - kafkaContainer, err := kafka.RunContainer(ctx, + kafkaContainer, err := kafka.Run(ctx, + "confluentinc/confluent-local:7.5.0", kafka.WithClusterID("test-cluster"), - testcontainers.WithImage("confluentinc/confluent-local:7.5.0"), ) if err != nil { log.Fatalf("failed to start container: %s", err) diff --git a/modules/kafka/kafka.go b/modules/kafka/kafka.go index 34758e8824..b2b0e831b5 100644 --- a/modules/kafka/kafka.go +++ b/modules/kafka/kafka.go @@ -36,10 +36,16 @@ type KafkaContainer struct { ClusterID string } +// Deprecated: use Run instead // RunContainer creates an instance of the Kafka container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*KafkaContainer, error) { + return Run(ctx, "confluentinc/confluent-local:7.5.0", opts...) +} + +// Run creates an instance of the Kafka container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*KafkaContainer, error) { req := testcontainers.ContainerRequest{ - Image: "confluentinc/confluent-local:7.5.0", + Image: img, ExposedPorts: []string{string(publicPort)}, Env: map[string]string{ // envVars { diff --git a/modules/kafka/kafka_test.go b/modules/kafka/kafka_test.go index 16b8b76355..1e2e009b58 100644 --- a/modules/kafka/kafka_test.go +++ b/modules/kafka/kafka_test.go @@ -17,7 +17,7 @@ func TestKafka(t *testing.T) { ctx := context.Background() - kafkaContainer, err := kafka.RunContainer(ctx, kafka.WithClusterID("kraftCluster"), testcontainers.WithImage("confluentinc/confluent-local:7.5.0")) + kafkaContainer, err := kafka.Run(ctx, "confluentinc/confluent-local:7.5.0", kafka.WithClusterID("kraftCluster")) if err != nil { t.Fatal(err) } @@ -91,7 +91,7 @@ func TestKafka(t *testing.T) { func TestKafka_invalidVersion(t *testing.T) { ctx := context.Background() - _, err := kafka.RunContainer(ctx, kafka.WithClusterID("kraftCluster"), testcontainers.WithImage("confluentinc/confluent-local:6.3.3")) + _, err := kafka.Run(ctx, "confluentinc/confluent-local:6.3.3", kafka.WithClusterID("kraftCluster")) if err == nil { t.Fatal(err) } diff --git a/modules/localstack/examples_test.go b/modules/localstack/examples_test.go index f745ae61ae..65a55c317b 100644 --- a/modules/localstack/examples_test.go +++ b/modules/localstack/examples_test.go @@ -19,13 +19,11 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -func ExampleRunContainer() { +func ExampleRun() { // runLocalstackContainer { ctx := context.Background() - localstackContainer, err := localstack.RunContainer(ctx, - testcontainers.WithImage("localstack/localstack:1.4.0"), - ) + localstackContainer, err := localstack.Run(ctx, "localstack/localstack:1.4.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -49,7 +47,7 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_withNetwork() { +func ExampleRun_withNetwork() { // localstackWithNetwork { ctx := context.Background() @@ -60,9 +58,9 @@ func ExampleRunContainer_withNetwork() { nwName := newNetwork.Name - localstackContainer, err := localstack.RunContainer( + localstackContainer, err := localstack.Run( ctx, - testcontainers.WithImage("localstack/localstack:0.13.0"), + "localstack/localstack:0.13.0", testcontainers.WithEnv(map[string]string{"SERVICES": "s3,sqs"}), network.WithNetwork([]string{nwName}, newNetwork), ) @@ -89,12 +87,12 @@ func ExampleRunContainer_withNetwork() { // 1 } -func ExampleRunContainer_legacyMode() { +func ExampleRun_legacyMode() { ctx := context.Background() - _, err := localstack.RunContainer( + _, err := localstack.Run( ctx, - testcontainers.WithImage("localstack/localstack:0.10.0"), + "localstack/localstack:0.10.0", testcontainers.WithEnv(map[string]string{"SERVICES": "s3,sqs"}), testcontainers.WithWaitStrategy(wait.ForLog("Ready.").WithStartupTimeout(5*time.Minute).WithOccurrence(1)), ) @@ -108,7 +106,7 @@ func ExampleRunContainer_legacyMode() { // version=localstack/localstack:0.10.0. Testcontainers for Go does not support running LocalStack in legacy mode. Please use a version >= 0.11.0 } -func ExampleRunContainer_usingLambdas() { +func ExampleRun_usingLambdas() { ctx := context.Background() flagsFn := func() string { @@ -125,8 +123,8 @@ func ExampleRunContainer_usingLambdas() { lambdaName := "localstack-lambda-url-example" // withCustomContainerRequest { - container, err := localstack.RunContainer(ctx, - testcontainers.WithImage("localstack/localstack:2.3.0"), + container, err := localstack.Run(ctx, + "localstack/localstack:2.3.0", testcontainers.WithEnv(map[string]string{ "SERVICES": "lambda", "LAMBDA_DOCKER_FLAGS": flagsFn(), diff --git a/modules/localstack/localstack.go b/modules/localstack/localstack.go index 47cbc6375a..f06054e83b 100644 --- a/modules/localstack/localstack.go +++ b/modules/localstack/localstack.go @@ -16,7 +16,6 @@ import ( const ( defaultPort = 4566 - defaultVersion = "1.4.0" hostnameExternalEnvVar = "HOSTNAME_EXTERNAL" localstackHostEnvVar = "LOCALSTACK_HOST" ) @@ -66,13 +65,19 @@ func WithNetwork(networkName string, alias string) testcontainers.CustomizeReque return network.WithNewNetwork(context.Background(), []string{alias}) } -// RunContainer creates an instance of the LocalStack container type, being possible to pass a custom request and options: -// - overrideReq: a function that can be used to override the default container request, usually used to set the image version, environment variables for localstack, etc. +// Deprecated: use Run instead +// RunContainer creates an instance of the LocalStack container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*LocalStackContainer, error) { + return Run(ctx, "localstack/localstack:1.4.0", opts...) +} + +// Run creates an instance of the LocalStack container type +// - overrideReq: a function that can be used to override the default container request, usually used to set the image version, environment variables for localstack, etc. +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*LocalStackContainer, error) { dockerHost := testcontainers.ExtractDockerSocket() req := testcontainers.ContainerRequest{ - Image: fmt.Sprintf("localstack/localstack:%s", defaultVersion), + Image: img, WaitingFor: wait.ForHTTP("/_localstack/health").WithPort("4566/tcp").WithStartupTimeout(120 * time.Second), ExposedPorts: []string{fmt.Sprintf("%d/tcp", defaultPort)}, Env: map[string]string{}, diff --git a/modules/localstack/localstack_test.go b/modules/localstack/localstack_test.go index e8bf32484d..70797fe3cd 100644 --- a/modules/localstack/localstack_test.go +++ b/modules/localstack/localstack_test.go @@ -111,16 +111,16 @@ func TestRunContainer(t *testing.T) { tests := []struct { version string }{ - {defaultVersion}, + {"1.4.0"}, {"2.0.0"}, } for _, tt := range tests { ctx := context.Background() - container, err := RunContainer( + container, err := Run( ctx, - testcontainers.WithImage(fmt.Sprintf("localstack/localstack:%s", tt.version)), + fmt.Sprintf("localstack/localstack:%s", tt.version), ) t.Run("Localstack:"+tt.version+" - multiple services exposed on same port", func(t *testing.T) { @@ -148,7 +148,7 @@ func TestRunContainer(t *testing.T) { func TestStartWithoutOverride(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx) + container, err := Run(ctx, "localstack/localstack:2.0.0") require.NoError(t, err) assert.NotNil(t, container) } @@ -159,10 +159,10 @@ func TestStartV2WithNetwork(t *testing.T) { nw, err := network.New(ctx) require.NoError(t, err) - localstack, err := RunContainer( + localstack, err := Run( ctx, + "localstack/localstack:2.0.0", network.WithNetwork([]string{"localstack"}, nw), - testcontainers.WithImage("localstack/localstack:2.0.0"), testcontainers.WithEnv(map[string]string{"SERVICES": "s3,sqs"}), ) require.NoError(t, err) diff --git a/modules/localstack/v1/s3_test.go b/modules/localstack/v1/s3_test.go index 2ab12c704b..be643228f6 100644 --- a/modules/localstack/v1/s3_test.go +++ b/modules/localstack/v1/s3_test.go @@ -62,7 +62,7 @@ func awsSession(ctx context.Context, l *localstack.LocalStackContainer) (*sessio func TestS3(t *testing.T) { ctx := context.Background() - container, err := localstack.RunContainer(ctx) + container, err := localstack.Run(ctx, "localstack/localstack:1.4.0") require.NoError(t, err) session, err := awsSession(ctx, container) diff --git a/modules/localstack/v2/s3_test.go b/modules/localstack/v2/s3_test.go index 6acb7240c4..2b5308ddd8 100644 --- a/modules/localstack/v2/s3_test.go +++ b/modules/localstack/v2/s3_test.go @@ -73,7 +73,7 @@ func s3Client(ctx context.Context, l *localstack.LocalStackContainer) (*s3.Clien func TestS3(t *testing.T) { ctx := context.Background() - container, err := localstack.RunContainer(ctx) + container, err := localstack.Run(ctx, "localstack/localstack:1.4.0") require.NoError(t, err) s3Client, err := s3Client(ctx, container) diff --git a/modules/mariadb/examples_test.go b/modules/mariadb/examples_test.go index 36209a2deb..d33970df14 100644 --- a/modules/mariadb/examples_test.go +++ b/modules/mariadb/examples_test.go @@ -6,16 +6,15 @@ import ( "log" "path/filepath" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mariadb" ) -func ExampleRunContainer() { +func ExampleRun() { // runMariaDBContainer { ctx := context.Background() - mariadbContainer, err := mariadb.RunContainer(ctx, - testcontainers.WithImage("mariadb:11.0.3"), + mariadbContainer, err := mariadb.Run(ctx, + "mariadb:11.0.3", mariadb.WithConfigFile(filepath.Join("testdata", "my.cnf")), mariadb.WithScripts(filepath.Join("testdata", "schema.sql")), mariadb.WithDatabase("foo"), diff --git a/modules/mariadb/mariadb.go b/modules/mariadb/mariadb.go index a3512f60c3..fae71c7871 100644 --- a/modules/mariadb/mariadb.go +++ b/modules/mariadb/mariadb.go @@ -17,11 +17,6 @@ const ( defaultDatabaseName = "test" ) -// defaultImage { -const defaultImage = "mariadb:11.0.3" - -// } - // MariaDBContainer represents the MariaDB container type used in the module type MariaDBContainer struct { testcontainers.Container @@ -124,10 +119,16 @@ func WithScripts(scripts ...string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the MariaDB container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MariaDBContainer, error) { + return Run(ctx, "mariadb:11.0.3", opts...) +} + +// Run creates an instance of the MariaDB container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MariaDBContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"3306/tcp", "33060/tcp"}, Env: map[string]string{ "MARIADB_USER": defaultUser, diff --git a/modules/mariadb/mariadb_test.go b/modules/mariadb/mariadb_test.go index 1e978e2f3a..f1863f472c 100644 --- a/modules/mariadb/mariadb_test.go +++ b/modules/mariadb/mariadb_test.go @@ -9,14 +9,13 @@ import ( // Import mysql into the scope of this package (required) _ "github.com/go-sql-driver/mysql" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mariadb" ) func TestMariaDB(t *testing.T) { ctx := context.Background() - container, err := mariadb.RunContainer(ctx) + container, err := mariadb.Run(ctx, "mariadb:11.0.3") if err != nil { t.Fatal(err) } @@ -63,7 +62,8 @@ func TestMariaDB(t *testing.T) { func TestMariaDBWithNonRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - _, err := mariadb.RunContainer(ctx, + _, err := mariadb.Run(ctx, + "mariadb:11.0.3", mariadb.WithDatabase("foo"), mariadb.WithUsername("test"), mariadb.WithPassword("")) @@ -75,7 +75,8 @@ func TestMariaDBWithNonRootUserAndEmptyPassword(t *testing.T) { func TestMariaDBWithRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - container, err := mariadb.RunContainer(ctx, + container, err := mariadb.Run(ctx, + "mariadb:11.0.3", mariadb.WithDatabase("foo"), mariadb.WithUsername("root"), mariadb.WithPassword("")) @@ -117,7 +118,7 @@ func TestMariaDBWithRootUserAndEmptyPassword(t *testing.T) { func TestMariaDBWithMySQLEnvVars(t *testing.T) { ctx := context.Background() - container, err := mariadb.RunContainer(ctx, testcontainers.WithImage("mariadb:10.3.29"), + container, err := mariadb.Run(ctx, "mariadb:10.3.29", mariadb.WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) @@ -135,7 +136,7 @@ func TestMariaDBWithMySQLEnvVars(t *testing.T) { func TestMariaDBWithConfigFile(t *testing.T) { ctx := context.Background() - container, err := mariadb.RunContainer(ctx, testcontainers.WithImage("mariadb:11.0.3"), + container, err := mariadb.Run(ctx, "mariadb:11.0.3", mariadb.WithConfigFile(filepath.Join("testdata", "my.cnf"))) if err != nil { t.Fatal(err) @@ -186,7 +187,8 @@ func TestMariaDBWithConfigFile(t *testing.T) { func TestMariaDBWithScripts(t *testing.T) { ctx := context.Background() - container, err := mariadb.RunContainer(ctx, + container, err := mariadb.Run(ctx, + "mariadb:11.0.3", mariadb.WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) diff --git a/modules/milvus/examples_test.go b/modules/milvus/examples_test.go index f4fab25376..79ca1b9812 100644 --- a/modules/milvus/examples_test.go +++ b/modules/milvus/examples_test.go @@ -8,15 +8,14 @@ import ( "github.com/milvus-io/milvus-sdk-go/v2/client" "github.com/milvus-io/milvus-sdk-go/v2/entity" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/milvus" ) -func ExampleRunContainer() { +func ExampleRun() { // runMilvusContainer { ctx := context.Background() - milvusContainer, err := milvus.RunContainer(ctx, testcontainers.WithImage("milvusdb/milvus:v2.3.9")) + milvusContainer, err := milvus.Run(ctx, "milvusdb/milvus:v2.3.9") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -44,7 +43,7 @@ func ExampleMilvusContainer_collections() { // createCollections { ctx := context.Background() - milvusContainer, err := milvus.RunContainer(ctx, testcontainers.WithImage("milvusdb/milvus:v2.3.9")) + milvusContainer, err := milvus.Run(ctx, "milvusdb/milvus:v2.3.9") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/milvus/milvus.go b/modules/milvus/milvus.go index a33ae27935..85af5aac04 100644 --- a/modules/milvus/milvus.go +++ b/modules/milvus/milvus.go @@ -37,10 +37,16 @@ func (c *MilvusContainer) ConnectionString(ctx context.Context) (string, error) return fmt.Sprintf("%s:%s", host, port.Port()), nil } +// Deprecated: use Run instead // RunContainer creates an instance of the Milvus container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error) { + return Run(ctx, "milvusdb/milvus:v2.3.9", opts...) +} + +// Run creates an instance of the Milvus container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MilvusContainer, error) { req := testcontainers.ContainerRequest{ - Image: "milvusdb/milvus:v2.3.9", + Image: img, ExposedPorts: []string{"19530/tcp", "9091/tcp", "2379/tcp"}, Env: map[string]string{ "ETCD_USE_EMBED": "true", diff --git a/modules/milvus/milvus_test.go b/modules/milvus/milvus_test.go index 43465ffa77..849722ba90 100644 --- a/modules/milvus/milvus_test.go +++ b/modules/milvus/milvus_test.go @@ -6,14 +6,13 @@ import ( "github.com/milvus-io/milvus-sdk-go/v2/client" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/milvus" ) func TestMilvus(t *testing.T) { ctx := context.Background() - container, err := milvus.RunContainer(ctx, testcontainers.WithImage("milvusdb/milvus:v2.3.9")) + container, err := milvus.Run(ctx, "milvusdb/milvus:v2.3.9") if err != nil { t.Fatal(err) } diff --git a/modules/minio/examples_test.go b/modules/minio/examples_test.go index ce72eb515a..c13e679388 100644 --- a/modules/minio/examples_test.go +++ b/modules/minio/examples_test.go @@ -5,15 +5,14 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/minio" ) -func ExampleRunContainer() { +func ExampleRun() { // runMinioContainer { ctx := context.Background() - minioContainer, err := minio.RunContainer(ctx, testcontainers.WithImage("minio/minio:RELEASE.2024-01-16T16-07-38Z")) + minioContainer, err := minio.Run(ctx, "minio/minio:RELEASE.2024-01-16T16-07-38Z") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/minio/minio.go b/modules/minio/minio.go index b81586934a..c7e2898d9f 100644 --- a/modules/minio/minio.go +++ b/modules/minio/minio.go @@ -11,7 +11,6 @@ import ( const ( defaultUser = "minioadmin" defaultPassword = "minioadmin" - defaultImage = "docker.io/minio/minio:RELEASE.2024-01-16T16-07-38Z" ) // MinioContainer represents the Minio container type used in the module @@ -57,10 +56,16 @@ func (c *MinioContainer) ConnectionString(ctx context.Context) (string, error) { return fmt.Sprintf("%s:%s", host, port.Port()), nil } +// Deprecated: use Run instead // RunContainer creates an instance of the Minio container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MinioContainer, error) { + return Run(ctx, "docker.io/minio/minio:RELEASE.2024-01-16T16-07-38Z", opts...) +} + +// Run creates an instance of the Minio container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MinioContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"9000/tcp"}, WaitingFor: wait.ForHTTP("/minio/health/live").WithPort("9000"), Env: map[string]string{ diff --git a/modules/minio/minio_test.go b/modules/minio/minio_test.go index 0cb5a7fc2e..60bf8034b3 100644 --- a/modules/minio/minio_test.go +++ b/modules/minio/minio_test.go @@ -9,15 +9,14 @@ import ( "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" - "github.com/testcontainers/testcontainers-go" tcminio "github.com/testcontainers/testcontainers-go/modules/minio" ) func TestMinio(t *testing.T) { ctx := context.Background() - container, err := tcminio.RunContainer(ctx, - testcontainers.WithImage("minio/minio:RELEASE.2024-01-16T16-07-38Z"), + container, err := tcminio.Run(ctx, + "minio/minio:RELEASE.2024-01-16T16-07-38Z", tcminio.WithUsername("thisismyuser"), tcminio.WithPassword("thisismypassword")) if err != nil { t.Fatal(err) diff --git a/modules/mockserver/examples_test.go b/modules/mockserver/examples_test.go index 9125114375..17f4cfffea 100644 --- a/modules/mockserver/examples_test.go +++ b/modules/mockserver/examples_test.go @@ -10,15 +10,14 @@ import ( client "github.com/BraspagDevelopers/mock-server-client" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mockserver" ) -func ExampleRunContainer() { +func ExampleRun() { // runMockServerContainer { ctx := context.Background() - mockserverContainer, err := mockserver.RunContainer(ctx, testcontainers.WithImage("mockserver/mockserver:5.15.0")) + mockserverContainer, err := mockserver.Run(ctx, "mockserver/mockserver:5.15.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -42,11 +41,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connect() { +func ExampleRun_connect() { // connectToMockServer { ctx := context.Background() - mockserverContainer, err := mockserver.RunContainer(ctx, testcontainers.WithImage("mockserver/mockserver:5.15.0")) + mockserverContainer, err := mockserver.Run(ctx, "mockserver/mockserver:5.15.0") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/mockserver/mockserver.go b/modules/mockserver/mockserver.go index e3bb5fbd28..7fb5674755 100644 --- a/modules/mockserver/mockserver.go +++ b/modules/mockserver/mockserver.go @@ -8,18 +8,21 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// defaultImage is the default MockServer container image -const defaultImage = "mockserver/mockserver:5.15.0" - // MockServerContainer represents the MockServer container type used in the module type MockServerContainer struct { testcontainers.Container } +// Deprecated: use Run instead // RunContainer creates an instance of the MockServer container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MockServerContainer, error) { + return Run(ctx, "mockserver/mockserver:5.15.0", opts...) +} + +// Run creates an instance of the MockServer container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MockServerContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"1080/tcp"}, WaitingFor: wait.ForAll( wait.ForLog("started on port: 1080"), diff --git a/modules/mongodb/examples_test.go b/modules/mongodb/examples_test.go index 8e936a7c64..5e8cbe8009 100644 --- a/modules/mongodb/examples_test.go +++ b/modules/mongodb/examples_test.go @@ -14,11 +14,11 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -func ExampleRunContainer() { +func ExampleRun() { // runMongoDBContainer { ctx := context.Background() - mongodbContainer, err := mongodb.RunContainer(ctx, testcontainers.WithImage("mongo:6")) + mongodbContainer, err := mongodb.Run(ctx, "mongo:6") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -42,11 +42,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connect() { +func ExampleRun_connect() { // connectToMongo { ctx := context.Background() - mongodbContainer, err := mongodb.RunContainer(ctx, testcontainers.WithImage("mongo:6")) + mongodbContainer, err := mongodb.Run(ctx, "mongo:6") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -80,11 +80,11 @@ func ExampleRunContainer_connect() { // test } -func ExampleRunContainer_withCredentials() { +func ExampleRun_withCredentials() { ctx := context.Background() - container, err := mongodb.RunContainer(ctx, - testcontainers.WithImage("mongo:6"), + container, err := mongodb.Run(ctx, + "mongo:6", mongodb.WithUsername("root"), mongodb.WithPassword("password"), testcontainers.WithWaitStrategy(wait.ForLog("Waiting for connections")), diff --git a/modules/mongodb/mongodb.go b/modules/mongodb/mongodb.go index 8d6f5c98e4..c27a5a4bf4 100644 --- a/modules/mongodb/mongodb.go +++ b/modules/mongodb/mongodb.go @@ -8,9 +8,6 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// defaultImage is the default MongoDB container image -const defaultImage = "mongo:6" - // MongoDBContainer represents the MongoDB container type used in the module type MongoDBContainer struct { testcontainers.Container @@ -18,10 +15,16 @@ type MongoDBContainer struct { password string } +// Deprecated: use Run instead // RunContainer creates an instance of the MongoDB container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MongoDBContainer, error) { + return Run(ctx, "mongo:6", opts...) +} + +// Run creates an instance of the MongoDB container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MongoDBContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"27017/tcp"}, WaitingFor: wait.ForAll( wait.ForLog("Waiting for connections"), diff --git a/modules/mongodb/mongodb_test.go b/modules/mongodb/mongodb_test.go index f55fb762ed..36bd907e32 100644 --- a/modules/mongodb/mongodb_test.go +++ b/modules/mongodb/mongodb_test.go @@ -15,38 +15,36 @@ import ( func TestMongoDB(t *testing.T) { type tests struct { name string + img string opts []testcontainers.ContainerCustomizer } testCases := []tests{ { name: "From Docker Hub", - opts: []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("mongo:6"), - }, + img: "mongo:6", + opts: []testcontainers.ContainerCustomizer{}, }, { name: "Community Server", - opts: []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("mongodb/mongodb-community-server:7.0.2-ubi8"), - }, + img: "mongodb/mongodb-community-server:7.0.2-ubi8", + opts: []testcontainers.ContainerCustomizer{}, }, { name: "Enterprise Server", - opts: []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("mongodb/mongodb-enterprise-server:7.0.0-ubi8"), - }, + img: "mongodb/mongodb-enterprise-server:7.0.0-ubi8", + opts: []testcontainers.ContainerCustomizer{}, }, { name: "With Replica set and mongo:4", + img: "mongo:4", opts: []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("mongo:4"), mongodb.WithReplicaSet("rs"), }, }, { name: "With Replica set and mongo:6", + img: "mongo:6", opts: []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("mongo:6"), mongodb.WithReplicaSet("rs"), }, }, @@ -59,7 +57,7 @@ func TestMongoDB(t *testing.T) { ctx := context.Background() - mongodbContainer, err := mongodb.RunContainer(ctx, tc.opts...) + mongodbContainer, err := mongodb.Run(ctx, tc.img, tc.opts...) if err != nil { tt.Fatalf("failed to start container: %s", err) } diff --git a/modules/mssql/examples_test.go b/modules/mssql/examples_test.go index 2d7af8f0c7..10363d9b48 100644 --- a/modules/mssql/examples_test.go +++ b/modules/mssql/examples_test.go @@ -5,18 +5,17 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mssql" ) -func ExampleRunContainer() { +func ExampleRun() { // runMSSQLServerContainer { ctx := context.Background() password := "SuperStrong@Passw0rd" - mssqlContainer, err := mssql.RunContainer(ctx, - testcontainers.WithImage("mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04"), + mssqlContainer, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04", mssql.WithAcceptEULA(), mssql.WithPassword(password), ) diff --git a/modules/mssql/mssql.go b/modules/mssql/mssql.go index 78321beab3..ca30d02385 100644 --- a/modules/mssql/mssql.go +++ b/modules/mssql/mssql.go @@ -10,7 +10,6 @@ import ( ) const ( - defaultImage = "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04" defaultPort = "1433/tcp" defaultUsername = "sa" // default microsoft system administrator defaultPassword = "Strong@Passw0rd" @@ -42,10 +41,16 @@ func WithPassword(password string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the MSSQLServer container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error) { + return Run(ctx, "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04", opts...) +} + +// Run creates an instance of the MSSQLServer container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MSSQLServerContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{defaultPort}, Env: map[string]string{ "MSSQL_SA_PASSWORD": defaultPassword, diff --git a/modules/mssql/mssql_test.go b/modules/mssql/mssql_test.go index b691935eaa..4e2050385a 100644 --- a/modules/mssql/mssql_test.go +++ b/modules/mssql/mssql_test.go @@ -15,7 +15,8 @@ import ( func TestMSSQLServer(t *testing.T) { ctx := context.Background() - container, err := mssql.RunContainer(ctx, + container, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04", mssql.WithAcceptEULA(), ) if err != nil { @@ -58,8 +59,11 @@ func TestMSSQLServer(t *testing.T) { func TestMSSQLServerWithMissingEulaOption(t *testing.T) { ctx := context.Background() - container, err := mssql.RunContainer(ctx, testcontainers.WithWaitStrategy( - wait.ForLog("The SQL Server End-User License Agreement (EULA) must be accepted"))) + container, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04", + testcontainers.WithWaitStrategy( + wait.ForLog("The SQL Server End-User License Agreement (EULA) must be accepted")), + ) if err != nil { t.Fatalf("Expected a log to confirm missing EULA but got error: %s", err) } @@ -77,7 +81,8 @@ func TestMSSQLServerWithMissingEulaOption(t *testing.T) { func TestMSSQLServerWithConnectionStringParameters(t *testing.T) { ctx := context.Background() - container, err := mssql.RunContainer(ctx, + container, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04", mssql.WithAcceptEULA(), ) if err != nil { @@ -120,7 +125,8 @@ func TestMSSQLServerWithConnectionStringParameters(t *testing.T) { func TestMSSQLServerWithCustomStrongPassword(t *testing.T) { ctx := context.Background() - container, err := mssql.RunContainer(ctx, + container, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04", mssql.WithAcceptEULA(), mssql.WithPassword("Strong@Passw0rd"), ) @@ -156,7 +162,8 @@ func TestMSSQLServerWithCustomStrongPassword(t *testing.T) { func TestMSSQLServerWithInvalidPassword(t *testing.T) { ctx := context.Background() - container, err := mssql.RunContainer(ctx, + container, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-CU10-ubuntu-22.04", testcontainers.WithWaitStrategy( wait.ForLog("Password validation failed")), mssql.WithAcceptEULA(), @@ -180,8 +187,8 @@ func TestMSSQLServerWithInvalidPassword(t *testing.T) { func TestMSSQLServerWithAlternativeImage(t *testing.T) { ctx := context.Background() - container, err := mssql.RunContainer(ctx, - testcontainers.WithImage("mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04"), + container, err := mssql.Run(ctx, + "mcr.microsoft.com/mssql/server:2022-RTM-GDR1-ubuntu-20.04", mssql.WithAcceptEULA(), ) if err != nil { diff --git a/modules/mysql/examples_test.go b/modules/mysql/examples_test.go index a6be342643..6872415fbe 100644 --- a/modules/mysql/examples_test.go +++ b/modules/mysql/examples_test.go @@ -7,16 +7,15 @@ import ( "log" "path/filepath" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/mysql" ) -func ExampleRunContainer() { +func ExampleRun() { // runMySQLContainer { ctx := context.Background() - mysqlContainer, err := mysql.RunContainer(ctx, - testcontainers.WithImage("mysql:8.0.36"), + mysqlContainer, err := mysql.Run(ctx, + "mysql:8.0.36", mysql.WithConfigFile(filepath.Join("testdata", "my_8.cnf")), mysql.WithDatabase("foo"), mysql.WithUsername("root"), @@ -46,11 +45,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connect() { +func ExampleRun_connect() { ctx := context.Background() - mysqlContainer, err := mysql.RunContainer(ctx, - testcontainers.WithImage("mysql:8.0.36"), + mysqlContainer, err := mysql.Run(ctx, + "mysql:8.0.36", mysql.WithConfigFile(filepath.Join("testdata", "my_8.cnf")), mysql.WithDatabase("foo"), mysql.WithUsername("root"), diff --git a/modules/mysql/mysql.go b/modules/mysql/mysql.go index 8b3f50deff..7bc6bf7e25 100644 --- a/modules/mysql/mysql.go +++ b/modules/mysql/mysql.go @@ -17,11 +17,6 @@ const ( defaultDatabaseName = "test" ) -// defaultImage { -const defaultImage = "mysql:8.0.36" - -// } - // MySQLContainer represents the MySQL container type used in the module type MySQLContainer struct { testcontainers.Container @@ -48,10 +43,16 @@ func WithDefaultCredentials() testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the MySQL container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*MySQLContainer, error) { + return Run(ctx, "mysql:8.0.36", opts...) +} + +// Run creates an instance of the MySQL container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*MySQLContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"3306/tcp", "33060/tcp"}, Env: map[string]string{ "MYSQL_USER": defaultUser, diff --git a/modules/mysql/mysql_test.go b/modules/mysql/mysql_test.go index 1d7de18f37..e40ce9bf58 100644 --- a/modules/mysql/mysql_test.go +++ b/modules/mysql/mysql_test.go @@ -15,7 +15,7 @@ import ( func TestMySQL(t *testing.T) { ctx := context.Background() - container, err := mysql.RunContainer(ctx) + container, err := mysql.Run(ctx, "mysql:8.0.36") if err != nil { t.Fatal(err) } @@ -61,7 +61,8 @@ func TestMySQL(t *testing.T) { func TestMySQLWithNonRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - _, err := mysql.RunContainer(ctx, + _, err := mysql.Run(ctx, + "mysql:8.0.36", mysql.WithDatabase("foo"), mysql.WithUsername("test"), mysql.WithPassword("")) @@ -73,7 +74,8 @@ func TestMySQLWithNonRootUserAndEmptyPassword(t *testing.T) { func TestMySQLWithRootUserAndEmptyPassword(t *testing.T) { ctx := context.Background() - container, err := mysql.RunContainer(ctx, + container, err := mysql.Run(ctx, + "mysql:8.0.36", mysql.WithDatabase("foo"), mysql.WithUsername("root"), mysql.WithPassword("")) @@ -113,7 +115,8 @@ func TestMySQLWithRootUserAndEmptyPassword(t *testing.T) { func TestMySQLWithScripts(t *testing.T) { ctx := context.Background() - container, err := mysql.RunContainer(ctx, + container, err := mysql.Run(ctx, + "mysql:8.0.36", mysql.WithScripts(filepath.Join("testdata", "schema.sql"))) if err != nil { t.Fatal(err) diff --git a/modules/nats/examples_test.go b/modules/nats/examples_test.go index 63e1c2b956..56ade42187 100644 --- a/modules/nats/examples_test.go +++ b/modules/nats/examples_test.go @@ -8,18 +8,15 @@ import ( natsgo "github.com/nats-io/nats.go" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/nats" "github.com/testcontainers/testcontainers-go/network" ) -func ExampleRunContainer() { +func ExampleRun() { // runNATSContainer { ctx := context.Background() - natsContainer, err := nats.RunContainer(ctx, - testcontainers.WithImage("nats:2.9"), - ) + natsContainer, err := nats.Run(ctx, "nats:2.9") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -43,11 +40,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connectWithCredentials() { +func ExampleRun_connectWithCredentials() { // natsConnect { ctx := context.Background() - container, err := nats.RunContainer(ctx, nats.WithUsername("foo"), nats.WithPassword("bar")) + container, err := nats.Run(ctx, "nats:2.9", nats.WithUsername("foo"), nats.WithPassword("bar")) if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -77,7 +74,7 @@ func ExampleRunContainer_connectWithCredentials() { // true } -func ExampleRunContainer_cluster() { +func ExampleRun_cluster() { ctx := context.Background() nwr, err := network.New(ctx) @@ -86,7 +83,8 @@ func ExampleRunContainer_cluster() { } // withArguments { - natsContainer1, err := nats.RunContainer(ctx, + natsContainer1, err := nats.Run(ctx, + "nats:2.9", network.WithNetwork([]string{"nats1"}, nwr), nats.WithArgument("name", "nats1"), nats.WithArgument("cluster_name", "c1"), @@ -105,7 +103,8 @@ func ExampleRunContainer_cluster() { } }() - natsContainer2, err := nats.RunContainer(ctx, + natsContainer2, err := nats.Run(ctx, + "nats:2.9", network.WithNetwork([]string{"nats2"}, nwr), nats.WithArgument("name", "nats2"), nats.WithArgument("cluster_name", "c1"), @@ -123,7 +122,8 @@ func ExampleRunContainer_cluster() { } }() - natsContainer3, err := nats.RunContainer(ctx, + natsContainer3, err := nats.Run(ctx, + "nats:2.9", network.WithNetwork([]string{"nats3"}, nwr), nats.WithArgument("name", "nats3"), nats.WithArgument("cluster_name", "c1"), diff --git a/modules/nats/nats.go b/modules/nats/nats.go index 343a300d9b..0ded01dd09 100644 --- a/modules/nats/nats.go +++ b/modules/nats/nats.go @@ -21,10 +21,16 @@ type NATSContainer struct { Password string } +// Deprecated: use Run instead // RunContainer creates an instance of the NATS container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error) { + return Run(ctx, "nats:2.9", opts...) +} + +// Run creates an instance of the NATS container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*NATSContainer, error) { req := testcontainers.ContainerRequest{ - Image: "nats:2.9", + Image: img, ExposedPorts: []string{defaultClientPort, defaultRoutingPort, defaultMonitoringPort}, Cmd: []string{"-DV", "-js"}, WaitingFor: wait.ForLog("Listening for client connections on 0.0.0.0:4222"), diff --git a/modules/nats/nats_test.go b/modules/nats/nats_test.go index 50b33f478d..e223f0aa24 100644 --- a/modules/nats/nats_test.go +++ b/modules/nats/nats_test.go @@ -13,7 +13,7 @@ func TestNATS(t *testing.T) { ctx := context.Background() // createNATSContainer { - container, err := tcnats.RunContainer(ctx) + container, err := tcnats.Run(ctx, "nats:2.9") // } if err != nil { t.Fatal(err) diff --git a/modules/neo4j/examples_test.go b/modules/neo4j/examples_test.go index fcddfa7c41..375184a1d6 100644 --- a/modules/neo4j/examples_test.go +++ b/modules/neo4j/examples_test.go @@ -5,18 +5,17 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/neo4j" ) -func ExampleRunContainer() { +func ExampleRun() { // runNeo4jContainer { ctx := context.Background() testPassword := "letmein!" - neo4jContainer, err := neo4j.RunContainer(ctx, - testcontainers.WithImage("docker.io/neo4j:4.4"), + neo4jContainer, err := neo4j.Run(ctx, + "docker.io/neo4j:4.4", neo4j.WithAdminPassword(testPassword), neo4j.WithLabsPlugin(neo4j.Apoc), neo4j.WithNeo4jSetting("dbms.tx_log.rotation.size", "42M"), diff --git a/modules/neo4j/neo4j.go b/modules/neo4j/neo4j.go index 70566aa0cd..e4f7fc3314 100644 --- a/modules/neo4j/neo4j.go +++ b/modules/neo4j/neo4j.go @@ -11,13 +11,6 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -const ( - // defaultImage { - defaultImageName = "neo4j" - defaultTag = "4.4" - // } -) - const ( // containerPorts { defaultBoltPort = "7687" @@ -48,11 +41,17 @@ func (c Neo4jContainer) BoltUrl(ctx context.Context) (string, error) { return fmt.Sprintf("neo4j://%s:%d", host, mappedPort.Int()), nil } +// Deprecated: use Run instead // RunContainer creates an instance of the Neo4j container type -func RunContainer(ctx context.Context, options ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) { +func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) { + return Run(ctx, "neo4j:4.4", opts...) +} + +// Run creates an instance of the Neo4j container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Neo4jContainer, error) { httpPort, _ := nat.NewPort("tcp", defaultHttpPort) request := testcontainers.ContainerRequest{ - Image: fmt.Sprintf("docker.io/%s:%s", defaultImageName, defaultTag), + Image: img, Env: map[string]string{ "NEO4J_AUTH": "none", }, @@ -78,11 +77,11 @@ func RunContainer(ctx context.Context, options ...testcontainers.ContainerCustom Started: true, } - if len(options) == 0 { - options = append(options, WithoutAuthentication()) + if len(opts) == 0 { + opts = append(opts, WithoutAuthentication()) } - for _, option := range options { + for _, option := range opts { if err := option.Customize(&genericContainerReq); err != nil { return nil, err } diff --git a/modules/neo4j/neo4j_test.go b/modules/neo4j/neo4j_test.go index 23717d4585..20bd17188b 100644 --- a/modules/neo4j/neo4j_test.go +++ b/modules/neo4j/neo4j_test.go @@ -9,7 +9,6 @@ import ( neo "github.com/neo4j/neo4j-go-driver/v5/neo4j" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/neo4j" ) @@ -70,12 +69,12 @@ func TestNeo4jWithEnterpriseLicense(t *testing.T) { "EnterpriseEdition": "docker.io/neo4j:4.4-enterprise", } - for edition, image := range images { - edition, image := edition, image + for edition, img := range images { + edition, img := edition, img t.Run(edition, func(t *testing.T) { t.Parallel() - container, err := neo4j.RunContainer(ctx, - testcontainers.WithImage(image), + container, err := neo4j.Run(ctx, + img, neo4j.WithAdminPassword(testPassword), neo4j.WithAcceptCommercialLicenseAgreement(), ) @@ -104,7 +103,7 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { ctx := context.Background() outer.Run("without authentication", func(t *testing.T) { - container, err := neo4j.RunContainer(ctx) + container, err := neo4j.Run(ctx, "neo4j:4.4") if err != nil { t.Fatalf("expected env to successfully run but did not: %s", err) } @@ -116,7 +115,8 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { }) outer.Run("auth setting outside WithAdminPassword raises error", func(t *testing.T) { - container, err := neo4j.RunContainer(ctx, + container, err := neo4j.Run(ctx, + "neo4j:4.4", neo4j.WithAdminPassword(testPassword), neo4j.WithNeo4jSetting("AUTH", "neo4j/thisisgonnafail"), ) @@ -131,7 +131,8 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { outer.Run("warns about overwrites of setting keys", func(t *testing.T) { // withSettings { logger := &inMemoryLogger{} - container, err := neo4j.RunContainer(ctx, + container, err := neo4j.Run(ctx, + "neo4j:4.4", neo4j.WithLogger(logger), // needs to go before WithNeo4jSetting and WithNeo4jSettings neo4j.WithAdminPassword(testPassword), neo4j.WithNeo4jSetting("some.key", "value1"), @@ -159,7 +160,7 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { }) outer.Run("rejects nil logger", func(t *testing.T) { - container, err := neo4j.RunContainer(ctx, neo4j.WithLogger(nil)) + container, err := neo4j.Run(ctx, "neo4j:4.4", neo4j.WithLogger(nil)) if container != nil { t.Fatalf("container must not be created with nil logger") @@ -171,7 +172,8 @@ func TestNeo4jWithWrongSettings(outer *testing.T) { } func setupNeo4j(ctx context.Context, t *testing.T) *neo4j.Neo4jContainer { - container, err := neo4j.RunContainer(ctx, + container, err := neo4j.Run(ctx, + "neo4j:4.4", neo4j.WithAdminPassword(testPassword), // withLabsPlugin { neo4j.WithLabsPlugin(neo4j.Apoc), diff --git a/modules/ollama/examples_test.go b/modules/ollama/examples_test.go index f10acf61b3..3e2a273854 100644 --- a/modules/ollama/examples_test.go +++ b/modules/ollama/examples_test.go @@ -10,15 +10,14 @@ import ( "github.com/tmc/langchaingo/llms" langchainollama "github.com/tmc/langchaingo/llms/ollama" - "github.com/testcontainers/testcontainers-go" tcollama "github.com/testcontainers/testcontainers-go/modules/ollama" ) -func ExampleRunContainer() { +func ExampleRun() { // runOllamaContainer { ctx := context.Background() - ollamaContainer, err := tcollama.RunContainer(ctx, testcontainers.WithImage("ollama/ollama:0.1.25")) + ollamaContainer, err := tcollama.Run(ctx, "ollama/ollama:0.1.25") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -42,14 +41,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_withModel_llama2_http() { +func ExampleRun_withModel_llama2_http() { // withHTTPModelLlama2 { ctx := context.Background() - ollamaContainer, err := tcollama.RunContainer( - ctx, - testcontainers.WithImage("ollama/ollama:0.1.25"), - ) + ollamaContainer, err := tcollama.Run(ctx, "ollama/ollama:0.1.25") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -100,14 +96,11 @@ func ExampleRunContainer_withModel_llama2_http() { // Intentionally not asserting the output, as we don't want to run this example in the tests. } -func ExampleRunContainer_withModel_llama2_langchain() { +func ExampleRun_withModel_llama2_langchain() { // withLangchainModelLlama2 { ctx := context.Background() - ollamaContainer, err := tcollama.RunContainer( - ctx, - testcontainers.WithImage("ollama/ollama:0.1.25"), - ) + ollamaContainer, err := tcollama.Run(ctx, "ollama/ollama:0.1.25") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/ollama/ollama.go b/modules/ollama/ollama.go index 8b40a405c3..b8a2fc1de6 100644 --- a/modules/ollama/ollama.go +++ b/modules/ollama/ollama.go @@ -14,6 +14,7 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) +// Deprecated: it will be removed in the next major version. const DefaultOllamaImage = "ollama/ollama:0.1.25" // OllamaContainer represents the Ollama container type used in the module @@ -71,10 +72,16 @@ func (c *OllamaContainer) Commit(ctx context.Context, targetImage string) error return nil } +// Deprecated: use Run instead // RunContainer creates an instance of the Ollama container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OllamaContainer, error) { + return Run(ctx, "ollama/ollama:0.1.25", opts...) +} + +// Run creates an instance of the Ollama container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OllamaContainer, error) { req := testcontainers.ContainerRequest{ - Image: DefaultOllamaImage, + Image: img, ExposedPorts: []string{"11434/tcp"}, WaitingFor: wait.ForListeningPort("11434/tcp").WithStartupTimeout(60 * time.Second), } diff --git a/modules/ollama/ollama_test.go b/modules/ollama/ollama_test.go index bece78f0a8..b60538835b 100644 --- a/modules/ollama/ollama_test.go +++ b/modules/ollama/ollama_test.go @@ -11,7 +11,6 @@ import ( "github.com/google/uuid" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/exec" "github.com/testcontainers/testcontainers-go/modules/ollama" ) @@ -19,7 +18,7 @@ import ( func TestOllama(t *testing.T) { ctx := context.Background() - container, err := ollama.RunContainer(ctx, testcontainers.WithImage("ollama/ollama:0.1.25")) + container, err := ollama.Run(ctx, "ollama/ollama:0.1.25") if err != nil { t.Fatal(err) } @@ -80,9 +79,9 @@ func TestOllama(t *testing.T) { t.Fatal(err) } - newOllamaContainer, err := ollama.RunContainer( + newOllamaContainer, err := ollama.Run( context.Background(), - testcontainers.WithImage(targetImage), + targetImage, ) if err != nil { t.Fatal(err) @@ -131,9 +130,9 @@ func assertLoadedModel(t *testing.T, c *ollama.OllamaContainer) { func TestRunContainer_withModel_error(t *testing.T) { ctx := context.Background() - ollamaContainer, err := ollama.RunContainer( + ollamaContainer, err := ollama.Run( ctx, - testcontainers.WithImage("ollama/ollama:0.1.25"), + "ollama/ollama:0.1.25", ) if err != nil { t.Fatalf("expected error to be nil, got %s", err) diff --git a/modules/openfga/examples_test.go b/modules/openfga/examples_test.go index 9d66965998..38609451ef 100644 --- a/modules/openfga/examples_test.go +++ b/modules/openfga/examples_test.go @@ -17,11 +17,11 @@ import ( "github.com/testcontainers/testcontainers-go/modules/openfga" ) -func ExampleRunContainer() { +func ExampleRun() { // runOpenFGAContainer { ctx := context.Background() - openfgaContainer, err := openfga.RunContainer(ctx, testcontainers.WithImage("openfga/openfga:v1.5.0")) + openfgaContainer, err := openfga.Run(ctx, "openfga/openfga:v1.5.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -45,8 +45,8 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connectToPlayground() { - openfgaContainer, err := openfga.RunContainer(context.Background(), testcontainers.WithImage("openfga/openfga:v1.5.0")) +func ExampleRun_connectToPlayground() { + openfgaContainer, err := openfga.Run(context.Background(), "openfga/openfga:v1.5.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -78,8 +78,8 @@ func ExampleRunContainer_connectToPlayground() { // 200 } -func ExampleRunContainer_connectWithSDKClient() { - openfgaContainer, err := openfga.RunContainer(context.Background(), testcontainers.WithImage("openfga/openfga:v1.5.0")) +func ExampleRun_connectWithSDKClient() { + openfgaContainer, err := openfga.Run(context.Background(), "openfga/openfga:v1.5.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -133,12 +133,12 @@ func ExampleRunContainer_connectWithSDKClient() { // 1 } -func ExampleRunContainer_writeModel() { +func ExampleRun_writeModel() { // openFGAwriteModel { secret := "openfga-secret" - openfgaContainer, err := openfga.RunContainer( + openfgaContainer, err := openfga.Run( context.Background(), - testcontainers.WithImage("openfga/openfga:v1.5.0"), + "openfga/openfga:v1.5.0", testcontainers.WithEnv(map[string]string{ "OPENFGA_LOG_LEVEL": "warn", "OPENFGA_AUTHN_METHOD": "preshared", diff --git a/modules/openfga/openfga.go b/modules/openfga/openfga.go index 1f1fbbd3bd..ccdaab71cb 100644 --- a/modules/openfga/openfga.go +++ b/modules/openfga/openfga.go @@ -39,10 +39,16 @@ func (c *OpenFGAContainer) PlaygroundEndpoint(ctx context.Context) (string, erro return fmt.Sprintf("%s/playground", endpoint), nil } +// Deprecated: use Run instead // RunContainer creates an instance of the OpenFGA container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenFGAContainer, error) { + return Run(ctx, "openfga/openfga:v1.5.0", opts...) +} + +// Run creates an instance of the OpenFGA container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenFGAContainer, error) { req := testcontainers.ContainerRequest{ - Image: "openfga/openfga:v1.5.0", + Image: img, Cmd: []string{"run"}, ExposedPorts: []string{"3000/tcp", "8080/tcp", "8081/tcp"}, WaitingFor: wait.ForAll( diff --git a/modules/openfga/openfga_test.go b/modules/openfga/openfga_test.go index 476c077dcc..ec0a16bf1b 100644 --- a/modules/openfga/openfga_test.go +++ b/modules/openfga/openfga_test.go @@ -4,14 +4,13 @@ import ( "context" "testing" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/openfga" ) func TestOpenFGA(t *testing.T) { ctx := context.Background() - container, err := openfga.RunContainer(ctx, testcontainers.WithImage("openfga/openfga:v1.5.0")) + container, err := openfga.Run(ctx, "openfga/openfga:v1.5.0") if err != nil { t.Fatal(err) } diff --git a/modules/openldap/examples_test.go b/modules/openldap/examples_test.go index 6c6ed6d672..f3bf2f40f5 100644 --- a/modules/openldap/examples_test.go +++ b/modules/openldap/examples_test.go @@ -7,15 +7,14 @@ import ( "github.com/go-ldap/ldap/v3" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/openldap" ) -func ExampleRunContainer() { +func ExampleRun() { // runOpenLDAPContainer { ctx := context.Background() - openldapContainer, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) + openldapContainer, err := openldap.Run(ctx, "bitnami/openldap:2.6.6") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -39,11 +38,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connect() { +func ExampleRun_connect() { // connectToOpenLdap { ctx := context.Background() - openldapContainer, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) + openldapContainer, err := openldap.Run(ctx, "bitnami/openldap:2.6.6") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/openldap/openldap.go b/modules/openldap/openldap.go index 8e0cc271de..dc215226c1 100644 --- a/modules/openldap/openldap.go +++ b/modules/openldap/openldap.go @@ -122,10 +122,16 @@ func WithInitialLdif(ldif string) testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the OpenLDAP container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error) { + return Run(ctx, "bitnami/openldap:2.6.6", opts...) +} + +// Run creates an instance of the OpenLDAP container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenLDAPContainer, error) { req := testcontainers.ContainerRequest{ - Image: "bitnami/openldap:2.6.6", + Image: img, Env: map[string]string{ "LDAP_ADMIN_USERNAME": defaultUser, "LDAP_ADMIN_PASSWORD": defaultPassword, diff --git a/modules/openldap/openldap_test.go b/modules/openldap/openldap_test.go index 9407a5716a..92f10fa211 100644 --- a/modules/openldap/openldap_test.go +++ b/modules/openldap/openldap_test.go @@ -7,14 +7,13 @@ import ( "github.com/go-ldap/ldap/v3" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/openldap" ) func TestOpenLDAP(t *testing.T) { ctx := context.Background() - container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) + container, err := openldap.Run(ctx, "bitnami/openldap:2.6.6") if err != nil { t.Fatal(err) } @@ -30,8 +29,8 @@ func TestOpenLDAP(t *testing.T) { func TestOpenLDAPWithAdminUsernameAndPassword(t *testing.T) { ctx := context.Background() - container, err := openldap.RunContainer(ctx, - testcontainers.WithImage("bitnami/openldap:2.6.6"), + container, err := openldap.Run(ctx, + "bitnami/openldap:2.6.6", openldap.WithAdminUsername("openldap"), openldap.WithAdminPassword("openldap"), ) @@ -67,7 +66,7 @@ func TestOpenLDAPWithAdminUsernameAndPassword(t *testing.T) { func TestOpenLDAPWithDifferentRoot(t *testing.T) { ctx := context.Background() - container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), openldap.WithRoot("dc=mydomain,dc=com")) + container, err := openldap.Run(ctx, "bitnami/openldap:2.6.6", openldap.WithRoot("dc=mydomain,dc=com")) if err != nil { t.Fatal(err) } @@ -102,7 +101,7 @@ func TestOpenLDAPWithDifferentRoot(t *testing.T) { func TestOpenLDAPLoadLdif(t *testing.T) { ctx := context.Background() - container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6")) + container, err := openldap.Run(ctx, "bitnami/openldap:2.6.6") if err != nil { t.Fatal(err) } @@ -193,7 +192,7 @@ userPassword: Password1 t.Fatal(err) } - container, err := openldap.RunContainer(ctx, testcontainers.WithImage("bitnami/openldap:2.6.6"), openldap.WithInitialLdif(f.Name())) + container, err := openldap.Run(ctx, "bitnami/openldap:2.6.6", openldap.WithInitialLdif(f.Name())) if err != nil { t.Fatal(err) } diff --git a/modules/opensearch/examples_test.go b/modules/opensearch/examples_test.go index bb9a855c2a..89bc9cb7c6 100644 --- a/modules/opensearch/examples_test.go +++ b/modules/opensearch/examples_test.go @@ -5,17 +5,16 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/opensearch" ) -func ExampleRunContainer() { +func ExampleRun() { // runOpenSearchContainer { ctx := context.Background() - opensearchContainer, err := opensearch.RunContainer( + opensearchContainer, err := opensearch.Run( ctx, - testcontainers.WithImage("opensearchproject/opensearch:2.11.1"), + "opensearchproject/opensearch:2.11.1", opensearch.WithUsername("new-username"), opensearch.WithPassword("new-password"), ) diff --git a/modules/opensearch/opensearch.go b/modules/opensearch/opensearch.go index 61290c9ed2..83177c8471 100644 --- a/modules/opensearch/opensearch.go +++ b/modules/opensearch/opensearch.go @@ -27,10 +27,16 @@ type OpenSearchContainer struct { Password string } +// Deprecated: use Run instead // RunContainer creates an instance of the OpenSearch container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*OpenSearchContainer, error) { + return Run(ctx, "opensearchproject/opensearch:2.11.1", opts...) +} + +// Run creates an instance of the OpenSearch container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*OpenSearchContainer, error) { req := testcontainers.ContainerRequest{ - Image: "opensearchproject/opensearch:2.11.1", + Image: img, ExposedPorts: []string{defaultHTTPPort, "9600/tcp"}, Env: map[string]string{ "discovery.type": "single-node", diff --git a/modules/opensearch/opensearch_test.go b/modules/opensearch/opensearch_test.go index 4d62638af6..64d0db37a5 100644 --- a/modules/opensearch/opensearch_test.go +++ b/modules/opensearch/opensearch_test.go @@ -5,14 +5,13 @@ import ( "net/http" "testing" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/opensearch" ) func TestOpenSearch(t *testing.T) { ctx := context.Background() - container, err := opensearch.RunContainer(ctx, testcontainers.WithImage("opensearchproject/opensearch:2.11.1")) + container, err := opensearch.Run(ctx, "opensearchproject/opensearch:2.11.1") if err != nil { t.Fatal(err) } diff --git a/modules/postgres/examples_test.go b/modules/postgres/examples_test.go index 20fc50d696..d579068686 100644 --- a/modules/postgres/examples_test.go +++ b/modules/postgres/examples_test.go @@ -12,7 +12,7 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -func ExampleRunContainer() { +func ExampleRun() { // runPostgresContainer { ctx := context.Background() @@ -20,8 +20,8 @@ func ExampleRunContainer() { dbUser := "user" dbPassword := "password" - postgresContainer, err := postgres.RunContainer(ctx, - testcontainers.WithImage("docker.io/postgres:16-alpine"), + postgresContainer, err := postgres.Run(ctx, + "docker.io/postgres:16-alpine", postgres.WithInitScripts(filepath.Join("testdata", "init-user-db.sh")), postgres.WithConfigFile(filepath.Join("testdata", "my-postgres.conf")), postgres.WithDatabase(dbName), diff --git a/modules/postgres/postgres.go b/modules/postgres/postgres.go index 8986935bb0..0ab4d889d1 100644 --- a/modules/postgres/postgres.go +++ b/modules/postgres/postgres.go @@ -13,10 +13,9 @@ import ( ) const ( - defaultUser = "postgres" - defaultPassword = "postgres" - defaultPostgresImage = "docker.io/postgres:16-alpine" - defaultSnapshotName = "migrated_template" + defaultUser = "postgres" + defaultPassword = "postgres" + defaultSnapshotName = "migrated_template" ) // PostgresContainer represents the postgres container type used in the module @@ -134,10 +133,16 @@ func WithUsername(user string) testcontainers.CustomizeRequestOption { } } -// RunContainer creates an instance of the postgres container type +// Deprecated: use Run instead +// RunContainer creates an instance of the Postgres container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*PostgresContainer, error) { + return Run(ctx, "docker.io/postgres:16-alpine", opts...) +} + +// Run creates an instance of the Postgres container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*PostgresContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultPostgresImage, + Image: img, Env: map[string]string{ "POSTGRES_USER": defaultUser, "POSTGRES_PASSWORD": defaultPassword, diff --git a/modules/postgres/postgres_test.go b/modules/postgres/postgres_test.go index a645872991..bcc6dac2a4 100644 --- a/modules/postgres/postgres_test.go +++ b/modules/postgres/postgres_test.go @@ -60,8 +60,8 @@ func TestPostgres(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - container, err := postgres.RunContainer(ctx, - testcontainers.WithImage(tt.image), + container, err := postgres.Run(ctx, + tt.image, postgres.WithDatabase(dbname), postgres.WithUsername(user), postgres.WithPassword(password), @@ -120,8 +120,9 @@ func TestContainerWithWaitForSQL(t *testing.T) { } t.Run("default query", func(t *testing.T) { - container, err := postgres.RunContainer( + container, err := postgres.Run( ctx, + "docker.io/postgres:16-alpine", postgres.WithDatabase(dbname), postgres.WithUsername(user), postgres.WithPassword(password), @@ -131,8 +132,9 @@ func TestContainerWithWaitForSQL(t *testing.T) { require.NotNil(t, container) }) t.Run("custom query", func(t *testing.T) { - container, err := postgres.RunContainer( + container, err := postgres.Run( ctx, + "docker.io/postgres:16-alpine", postgres.WithDatabase(dbname), postgres.WithUsername(user), postgres.WithPassword(password), @@ -142,8 +144,9 @@ func TestContainerWithWaitForSQL(t *testing.T) { require.NotNil(t, container) }) t.Run("custom bad query", func(t *testing.T) { - container, err := postgres.RunContainer( + container, err := postgres.Run( ctx, + "docker.io/postgres:16-alpine", postgres.WithDatabase(dbname), postgres.WithUsername(user), postgres.WithPassword(password), @@ -157,7 +160,8 @@ func TestContainerWithWaitForSQL(t *testing.T) { func TestWithConfigFile(t *testing.T) { ctx := context.Background() - container, err := postgres.RunContainer(ctx, + container, err := postgres.Run(ctx, + "docker.io/postgres:16-alpine", postgres.WithConfigFile(filepath.Join("testdata", "my-postgres.conf")), postgres.WithDatabase(dbname), postgres.WithUsername(user), @@ -187,8 +191,8 @@ func TestWithConfigFile(t *testing.T) { func TestWithInitScript(t *testing.T) { ctx := context.Background() - container, err := postgres.RunContainer(ctx, - testcontainers.WithImage("docker.io/postgres:15.2-alpine"), + container, err := postgres.Run(ctx, + "docker.io/postgres:15.2-alpine", postgres.WithInitScripts(filepath.Join("testdata", "init-user-db.sh")), postgres.WithDatabase(dbname), postgres.WithUsername(user), @@ -225,9 +229,9 @@ func TestSnapshot(t *testing.T) { ctx := context.Background() // 1. Start the postgres container and run any migrations on it - container, err := postgres.RunContainer( + container, err := postgres.Run( ctx, - testcontainers.WithImage("docker.io/postgres:16-alpine"), + "docker.io/postgres:16-alpine", postgres.WithDatabase(dbname), postgres.WithUsername(user), postgres.WithPassword(password), @@ -329,9 +333,9 @@ func TestSnapshotWithOverrides(t *testing.T) { user := "other-user" password := "other-password" - container, err := postgres.RunContainer( + container, err := postgres.Run( ctx, - testcontainers.WithImage("docker.io/postgres:16-alpine"), + "docker.io/postgres:16-alpine", postgres.WithDatabase(dbname), postgres.WithUsername(user), postgres.WithPassword(password), diff --git a/modules/pulsar/examples_test.go b/modules/pulsar/examples_test.go index 94e76c5f19..2ee1f3c38e 100644 --- a/modules/pulsar/examples_test.go +++ b/modules/pulsar/examples_test.go @@ -5,17 +5,14 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/pulsar" ) -func ExampleRunContainer() { +func ExampleRun() { // runPulsarContainer { ctx := context.Background() - pulsarContainer, err := pulsar.RunContainer(ctx, - testcontainers.WithImage("docker.io/apachepulsar/pulsar:2.10.2"), - ) + pulsarContainer, err := pulsar.Run(ctx, "docker.io/apachepulsar/pulsar:2.10.2") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/pulsar/pulsar.go b/modules/pulsar/pulsar.go index bdb45ab69e..c1c5c94517 100644 --- a/modules/pulsar/pulsar.go +++ b/modules/pulsar/pulsar.go @@ -13,7 +13,6 @@ import ( ) const ( - defaultPulsarImage = "docker.io/apachepulsar/pulsar:2.10.2" defaultPulsarPort = "6650/tcp" defaultPulsarAdminPort = "8080/tcp" defaultPulsarCmd = "/pulsar/bin/apply-config-from-env.py /pulsar/conf/standalone.conf && bin/pulsar standalone" @@ -130,7 +129,13 @@ func WithTransactions() testcontainers.CustomizeRequestOption { } } -// RunContainer creates an instance of the Pulsar container type, being possible to pass a custom request and options +// Deprecated: use Run instead +// RunContainer creates an instance of the Pulsar container type +func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { + return Run(ctx, "docker.io/apachepulsar/pulsar:2.10.2", opts...) +} + +// Run 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 @@ -139,9 +144,9 @@ func WithTransactions() testcontainers.CustomizeRequestOption { // - 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 RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { req := testcontainers.ContainerRequest{ - Image: defaultPulsarImage, + Image: img, Env: map[string]string{}, ExposedPorts: []string{defaultPulsarPort, defaultPulsarAdminPort}, WaitingFor: defaultWaitStrategies, diff --git a/modules/pulsar/pulsar_test.go b/modules/pulsar/pulsar_test.go index 3a94f78ac3..6d911bf9e5 100644 --- a/modules/pulsar/pulsar_test.go +++ b/modules/pulsar/pulsar_test.go @@ -40,7 +40,6 @@ func TestPulsar(t *testing.T) { { name: "with modifiers", opts: []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("docker.io/apachepulsar/pulsar:2.10.2"), // addPulsarEnv { testcontainerspulsar.WithPulsarEnv("brokerDeduplicationEnabled", "true"), // } @@ -89,8 +88,9 @@ func TestPulsar(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - c, err := testcontainerspulsar.RunContainer( + c, err := testcontainerspulsar.Run( ctx, + "docker.io/apachepulsar/pulsar:2.10.2", tt.opts..., ) require.NoError(t, err) diff --git a/modules/qdrant/examples_test.go b/modules/qdrant/examples_test.go index c21f5812ab..e718d77398 100644 --- a/modules/qdrant/examples_test.go +++ b/modules/qdrant/examples_test.go @@ -10,15 +10,14 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/qdrant" ) -func ExampleRunContainer() { +func ExampleRun() { // runQdrantContainer { ctx := context.Background() - qdrantContainer, err := qdrant.RunContainer(ctx, testcontainers.WithImage("qdrant/qdrant:v1.7.4")) + qdrantContainer, err := qdrant.Run(ctx, "qdrant/qdrant:v1.7.4") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -42,9 +41,9 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_createPoints() { +func ExampleRun_createPoints() { // fullExample { - qdrantContainer, err := qdrant.RunContainer(context.Background(), testcontainers.WithImage("qdrant/qdrant:v1.7.4")) + qdrantContainer, err := qdrant.Run(context.Background(), "qdrant/qdrant:v1.7.4") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/qdrant/qdrant.go b/modules/qdrant/qdrant.go index c5a4244707..e934403f96 100644 --- a/modules/qdrant/qdrant.go +++ b/modules/qdrant/qdrant.go @@ -14,10 +14,16 @@ type QdrantContainer struct { testcontainers.Container } +// Deprecated: use Run instead // RunContainer creates an instance of the Qdrant container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*QdrantContainer, error) { + return Run(ctx, "qdrant/qdrant:v1.7.4", opts...) +} + +// Run creates an instance of the Qdrant container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*QdrantContainer, error) { req := testcontainers.ContainerRequest{ - Image: "qdrant/qdrant:v1.7.4", + Image: img, ExposedPorts: []string{"6333/tcp", "6334/tcp"}, WaitingFor: wait.ForAll( wait.ForListeningPort("6333/tcp").WithStartupTimeout(5*time.Second), diff --git a/modules/qdrant/qdrant_test.go b/modules/qdrant/qdrant_test.go index 7295580c73..c40a54bb8b 100644 --- a/modules/qdrant/qdrant_test.go +++ b/modules/qdrant/qdrant_test.go @@ -8,14 +8,13 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/qdrant" ) func TestQdrant(t *testing.T) { ctx := context.Background() - container, err := qdrant.RunContainer(ctx, testcontainers.WithImage("qdrant/qdrant:v1.7.4")) + container, err := qdrant.Run(ctx, "qdrant/qdrant:v1.7.4") if err != nil { t.Fatal(err) } diff --git a/modules/rabbitmq/examples_test.go b/modules/rabbitmq/examples_test.go index 64c3dd95a7..4471d512d4 100644 --- a/modules/rabbitmq/examples_test.go +++ b/modules/rabbitmq/examples_test.go @@ -15,12 +15,12 @@ import ( "github.com/testcontainers/testcontainers-go/modules/rabbitmq" ) -func ExampleRunContainer() { +func ExampleRun() { // runRabbitMQContainer { ctx := context.Background() - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, - testcontainers.WithImage("rabbitmq:3.12.11-management-alpine"), + rabbitmqContainer, err := rabbitmq.Run(ctx, + "rabbitmq:3.12.11-management-alpine", rabbitmq.WithAdminUsername("admin"), rabbitmq.WithAdminPassword("password"), ) @@ -47,11 +47,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connectUsingAmqp() { +func ExampleRun_connectUsingAmqp() { ctx := context.Background() - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, - testcontainers.WithImage("rabbitmq:3.7.25-management-alpine"), + rabbitmqContainer, err := rabbitmq.Run(ctx, + "rabbitmq:3.7.25-management-alpine", rabbitmq.WithAdminUsername("admin"), rabbitmq.WithAdminPassword("password"), ) @@ -86,7 +86,7 @@ func ExampleRunContainer_connectUsingAmqp() { // false } -func ExampleRunContainer_withSSL() { +func ExampleRun_withSSL() { // enableSSL { ctx := context.Background() @@ -128,8 +128,8 @@ func ExampleRunContainer_withSSL() { VerificationDepth: 1, } - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, - testcontainers.WithImage("rabbitmq:3.7.25-management-alpine"), + rabbitmqContainer, err := rabbitmq.Run(ctx, + "rabbitmq:3.7.25-management-alpine", rabbitmq.WithSSL(sslSettings), ) if err != nil { @@ -154,11 +154,11 @@ func ExampleRunContainer_withSSL() { // true } -func ExampleRunContainer_withPlugins() { +func ExampleRun_withPlugins() { ctx := context.Background() - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, - testcontainers.WithImage("rabbitmq:3.7.25-management-alpine"), + rabbitmqContainer, err := rabbitmq.Run(ctx, + "rabbitmq:3.7.25-management-alpine", // Multiple test implementations of the Executable interface, specific to RabbitMQ, exist in the types_test.go file. // Please refer to them for more examples. testcontainers.WithAfterReadyCommand( @@ -182,11 +182,11 @@ func ExampleRunContainer_withPlugins() { // true } -func ExampleRunContainer_withCustomConfigFile() { +func ExampleRun_withCustomConfigFile() { ctx := context.Background() - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, - testcontainers.WithImage("rabbitmq:3.7.25-management-alpine"), + rabbitmqContainer, err := rabbitmq.Run(ctx, + "rabbitmq:3.7.25-management-alpine", ) if err != nil { log.Fatalf("failed to start container: %s", err) diff --git a/modules/rabbitmq/rabbitmq.go b/modules/rabbitmq/rabbitmq.go index 612c760d90..bcc1a849d7 100644 --- a/modules/rabbitmq/rabbitmq.go +++ b/modules/rabbitmq/rabbitmq.go @@ -66,10 +66,16 @@ func (c *RabbitMQContainer) HttpsURL(ctx context.Context) (string, error) { return c.PortEndpoint(ctx, nat.Port(DefaultHTTPSPort), "https") } +// Deprecated: use Run instead // RunContainer creates an instance of the RabbitMQ container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error) { + return Run(ctx, "rabbitmq:3.12.11-management-alpine", opts...) +} + +// Run creates an instance of the RabbitMQ container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RabbitMQContainer, error) { req := testcontainers.ContainerRequest{ - Image: "rabbitmq:3.12.11-management-alpine", + Image: img, Env: map[string]string{ "RABBITMQ_DEFAULT_USER": defaultUser, "RABBITMQ_DEFAULT_PASS": defaultPassword, diff --git a/modules/rabbitmq/rabbitmq_test.go b/modules/rabbitmq/rabbitmq_test.go index f1f03f8ba9..9b024d7b5a 100644 --- a/modules/rabbitmq/rabbitmq_test.go +++ b/modules/rabbitmq/rabbitmq_test.go @@ -20,7 +20,7 @@ import ( func TestRunContainer_connectUsingAmqp(t *testing.T) { ctx := context.Background() - rabbitmqContainer, err := rabbitmq.RunContainer(ctx) + rabbitmqContainer, err := rabbitmq.Run(ctx, "rabbitmq:3.12.11-management-alpine") if err != nil { t.Fatal(err) } @@ -81,7 +81,7 @@ func TestRunContainer_connectUsingAmqps(t *testing.T) { VerificationDepth: 1, } - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, rabbitmq.WithSSL(sslSettings)) + rabbitmqContainer, err := rabbitmq.Run(ctx, "rabbitmq:3.12.11-management-alpine", rabbitmq.WithSSL(sslSettings)) if err != nil { t.Fatal(err) } @@ -125,8 +125,8 @@ func TestRunContainer_connectUsingAmqps(t *testing.T) { func TestRunContainer_withAllSettings(t *testing.T) { ctx := context.Background() - rabbitmqContainer, err := rabbitmq.RunContainer(ctx, - testcontainers.WithImage("rabbitmq:3.12.11-management-alpine"), + rabbitmqContainer, err := rabbitmq.Run(ctx, + "rabbitmq:3.12.11-management-alpine", // addVirtualHosts { testcontainers.WithAfterReadyCommand(VirtualHost{Name: "vhost1"}), testcontainers.WithAfterReadyCommand(VirtualHostLimit{VHost: "vhost1", Name: "max-connections", Value: 1}), diff --git a/modules/redis/examples_test.go b/modules/redis/examples_test.go index 90b6d30bde..9fb7c2cf11 100644 --- a/modules/redis/examples_test.go +++ b/modules/redis/examples_test.go @@ -6,16 +6,15 @@ import ( "log" "path/filepath" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/redis" ) -func ExampleRunContainer() { +func ExampleRun() { // runRedisContainer { ctx := context.Background() - redisContainer, err := redis.RunContainer(ctx, - testcontainers.WithImage("docker.io/redis:7"), + redisContainer, err := redis.Run(ctx, + "docker.io/redis:7", redis.WithSnapshotting(10, 1), redis.WithLogLevel(redis.LogLevelVerbose), redis.WithConfigFile(filepath.Join("testdata", "redis7.conf")), diff --git a/modules/redis/redis.go b/modules/redis/redis.go index d24cfac676..33ce823994 100644 --- a/modules/redis/redis.go +++ b/modules/redis/redis.go @@ -8,9 +8,6 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -// defaultImage is the default image used for the redis container -const defaultImage = "docker.io/redis:7" - // redisServerProcess is the name of the redis server process const redisServerProcess = "redis-server" @@ -46,10 +43,16 @@ func (c *RedisContainer) ConnectionString(ctx context.Context) (string, error) { return uri, nil } +// Deprecated: use Run instead // RunContainer creates an instance of the Redis container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error) { + return Run(ctx, "docker.io/redis:7", opts...) +} + +// Run creates an instance of the Redis container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RedisContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImage, + Image: img, ExposedPorts: []string{"6379/tcp"}, WaitingFor: wait.ForLog("* Ready to accept connections"), } diff --git a/modules/redis/redis_test.go b/modules/redis/redis_test.go index e66e6e37d5..f98079685f 100644 --- a/modules/redis/redis_test.go +++ b/modules/redis/redis_test.go @@ -11,14 +11,13 @@ import ( "github.com/google/uuid" "github.com/stretchr/testify/require" - "github.com/testcontainers/testcontainers-go" tcredis "github.com/testcontainers/testcontainers-go/modules/redis" ) func TestIntegrationSetGet(t *testing.T) { ctx := context.Background() - redisContainer, err := tcredis.RunContainer(ctx) + redisContainer, err := tcredis.Run(ctx, "docker.io/redis:7") require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -32,7 +31,7 @@ func TestIntegrationSetGet(t *testing.T) { func TestRedisWithConfigFile(t *testing.T) { ctx := context.Background() - redisContainer, err := tcredis.RunContainer(ctx, tcredis.WithConfigFile(filepath.Join("testdata", "redis7.conf"))) + redisContainer, err := tcredis.Run(ctx, "docker.io/redis:7", tcredis.WithConfigFile(filepath.Join("testdata", "redis7.conf"))) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -74,7 +73,7 @@ func TestRedisWithImage(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - redisContainer, err := tcredis.RunContainer(ctx, testcontainers.WithImage(tt.image), tcredis.WithConfigFile(filepath.Join("testdata", "redis6.conf"))) + redisContainer, err := tcredis.Run(ctx, tt.image, tcredis.WithConfigFile(filepath.Join("testdata", "redis6.conf"))) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -90,7 +89,7 @@ func TestRedisWithImage(t *testing.T) { func TestRedisWithLogLevel(t *testing.T) { ctx := context.Background() - redisContainer, err := tcredis.RunContainer(ctx, tcredis.WithLogLevel(tcredis.LogLevelVerbose)) + redisContainer, err := tcredis.Run(ctx, "docker.io/redis:7", tcredis.WithLogLevel(tcredis.LogLevelVerbose)) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { @@ -104,7 +103,7 @@ func TestRedisWithLogLevel(t *testing.T) { func TestRedisWithSnapshotting(t *testing.T) { ctx := context.Background() - redisContainer, err := tcredis.RunContainer(ctx, tcredis.WithSnapshotting(10, 1)) + redisContainer, err := tcredis.Run(ctx, "docker.io/redis:7", tcredis.WithSnapshotting(10, 1)) require.NoError(t, err) t.Cleanup(func() { if err := redisContainer.Terminate(ctx); err != nil { diff --git a/modules/redpanda/examples_test.go b/modules/redpanda/examples_test.go index 21913f95ff..822522255c 100644 --- a/modules/redpanda/examples_test.go +++ b/modules/redpanda/examples_test.go @@ -8,11 +8,12 @@ import ( "github.com/testcontainers/testcontainers-go/modules/redpanda" ) -func ExampleRunContainer() { +func ExampleRun() { // runRedpandaContainer { ctx := context.Background() - redpandaContainer, err := redpanda.RunContainer(ctx, + redpandaContainer, err := redpanda.Run(ctx, + "docker.redpanda.com/redpandadata/redpanda:v23.3.3", redpanda.WithEnableSASL(), redpanda.WithEnableKafkaAuthorization(), redpanda.WithEnableWasmTransform(), diff --git a/modules/redpanda/redpanda.go b/modules/redpanda/redpanda.go index f6b4603fde..608396ec29 100644 --- a/modules/redpanda/redpanda.go +++ b/modules/redpanda/redpanda.go @@ -52,8 +52,14 @@ type Container struct { urlScheme string } -// RunContainer creates an instance of the Redpanda container type. +// Deprecated: use Run instead +// RunContainer creates an instance of the Redpanda container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*Container, error) { + return Run(ctx, "docker.redpanda.com/redpandadata/redpanda:v23.3.3", opts...) +} + +// Run creates an instance of the Redpanda container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error) { tmpDir, err := os.MkdirTemp("", "redpanda") if err != nil { return nil, fmt.Errorf("failed to create directory: %w", err) @@ -64,7 +70,7 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize // Some (e.g. Image) may be overridden by providing an option argument to this function. req := testcontainers.GenericContainerRequest{ ContainerRequest: testcontainers.ContainerRequest{ - Image: "docker.redpanda.com/redpandadata/redpanda:v23.3.3", + Image: img, User: "root:root", // Files: Will be added later after we've rendered our YAML templates. ExposedPorts: []string{ diff --git a/modules/redpanda/redpanda_test.go b/modules/redpanda/redpanda_test.go index fab679bfed..948ea4c741 100644 --- a/modules/redpanda/redpanda_test.go +++ b/modules/redpanda/redpanda_test.go @@ -26,7 +26,7 @@ import ( func TestRedpanda(t *testing.T) { ctx := context.Background() - container, err := redpanda.RunContainer(ctx) + container, err := redpanda.Run(ctx, "docker.redpanda.com/redpandadata/redpanda:v23.3.3") require.NoError(t, err) // Clean up the container after the test is complete @@ -82,7 +82,8 @@ func TestRedpanda(t *testing.T) { func TestRedpandaWithAuthentication(t *testing.T) { ctx := context.Background() // redpandaCreateContainer { - container, err := redpanda.RunContainer(ctx, + container, err := redpanda.Run(ctx, + "docker.redpanda.com/redpandadata/redpanda:v23.3.3", redpanda.WithEnableSASL(), redpanda.WithEnableKafkaAuthorization(), redpanda.WithEnableWasmTransform(), @@ -193,8 +194,8 @@ func TestRedpandaWithOldVersionAndWasm(t *testing.T) { ctx := context.Background() // redpandaCreateContainer { // this would fail to start if we weren't ignoring wasm transforms for older versions - container, err := redpanda.RunContainer(ctx, - testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), + container, err := redpanda.Run(ctx, + "redpandadata/redpanda:v23.2.18", redpanda.WithEnableSASL(), redpanda.WithEnableKafkaAuthorization(), redpanda.WithEnableWasmTransform(), @@ -321,7 +322,7 @@ func TestRedpandaWithOldVersionAndWasm(t *testing.T) { func TestRedpandaProduceWithAutoCreateTopics(t *testing.T) { ctx := context.Background() - container, err := redpanda.RunContainer(ctx, redpanda.WithAutoCreateTopics()) + container, err := redpanda.Run(ctx, "docker.redpanda.com/redpandadata/redpanda:v23.3.3", redpanda.WithAutoCreateTopics()) require.NoError(t, err) t.Cleanup(func() { @@ -355,7 +356,7 @@ func TestRedpandaWithTLS(t *testing.T) { ctx := context.Background() - container, err := redpanda.RunContainer(ctx, redpanda.WithTLS(cert.Bytes, cert.KeyBytes)) + container, err := redpanda.Run(ctx, "docker.redpanda.com/redpandadata/redpanda:v23.3.3", redpanda.WithTLS(cert.Bytes, cert.KeyBytes)) require.NoError(t, err) t.Cleanup(func() { @@ -424,7 +425,8 @@ func TestRedpandaWithTLSAndSASL(t *testing.T) { ctx := context.Background() - container, err := redpanda.RunContainer(ctx, + container, err := redpanda.Run(ctx, + "docker.redpanda.com/redpandadata/redpanda:v23.3.3", redpanda.WithTLS(cert.Bytes, cert.KeyBytes), redpanda.WithEnableSASL(), redpanda.WithEnableKafkaAuthorization(), @@ -468,8 +470,8 @@ func TestRedpandaListener_Simple(t *testing.T) { // 2. Start Redpanda container // withListenerRP { - container, err := redpanda.RunContainer(ctx, - testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), + container, err := redpanda.Run(ctx, + "redpandadata/redpanda:v23.2.18", network.WithNetwork([]string{"redpanda-host"}, rpNetwork), redpanda.WithListener("redpanda:29092"), redpanda.WithAutoCreateTopics(), ) @@ -541,8 +543,8 @@ func TestRedpandaListener_InvalidPort(t *testing.T) { require.NoError(t, err) // 2. Attempt Start Redpanda container - _, err = redpanda.RunContainer(ctx, - testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), + _, err = redpanda.Run(ctx, + "redpandadata/redpanda:v23.2.18", redpanda.WithListener("redpanda:99092"), network.WithNetwork([]string{"redpanda-host"}, RPNetwork), ) @@ -562,8 +564,8 @@ func TestRedpandaListener_NoNetwork(t *testing.T) { ctx := context.Background() // 1. Attempt Start Redpanda container - _, err := redpanda.RunContainer(ctx, - testcontainers.WithImage("redpandadata/redpanda:v23.2.18"), + _, err := redpanda.Run(ctx, + "redpandadata/redpanda:v23.2.18", redpanda.WithListener("redpanda:99092"), ) diff --git a/modules/registry/examples_test.go b/modules/registry/examples_test.go index efb0aff126..3b9f55099d 100644 --- a/modules/registry/examples_test.go +++ b/modules/registry/examples_test.go @@ -12,9 +12,9 @@ import ( "github.com/testcontainers/testcontainers-go/wait" ) -func ExampleRunContainer() { +func ExampleRun() { // runRegistryContainer { - registryContainer, err := registry.RunContainer(context.Background(), testcontainers.WithImage("registry:2.8.3")) + registryContainer, err := registry.Run(context.Background(), "registry:2.8.3") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -38,11 +38,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_withAuthentication() { +func ExampleRun_withAuthentication() { // htpasswdFile { - registryContainer, err := registry.RunContainer( + registryContainer, err := registry.Run( context.Background(), - testcontainers.WithImage("registry:2.8.3"), + "registry:2.8.3", registry.WithHtpasswdFile(filepath.Join("testdata", "auth", "htpasswd")), registry.WithData(filepath.Join("testdata", "data")), ) @@ -117,10 +117,10 @@ func ExampleRunContainer_withAuthentication() { // true } -func ExampleRunContainer_pushImage() { - registryContainer, err := registry.RunContainer( +func ExampleRun_pushImage() { + registryContainer, err := registry.Run( context.Background(), - testcontainers.WithImage("registry:2.8.3"), + "registry:2.8.3", registry.WithHtpasswdFile(filepath.Join("testdata", "auth", "htpasswd")), registry.WithData(filepath.Join("testdata", "data")), ) diff --git a/modules/registry/registry.go b/modules/registry/registry.go index a329093ff4..22e1aa1532 100644 --- a/modules/registry/registry.go +++ b/modules/registry/registry.go @@ -155,10 +155,16 @@ func (c *RegistryContainer) PushImage(ctx context.Context, ref string) error { return c.ImageExists(ctx, ref) } +// Deprecated: use Run instead // RunContainer creates an instance of the Registry container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) { + return Run(ctx, "registry:2.8.3", opts...) +} + +// Run creates an instance of the Registry container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*RegistryContainer, error) { req := testcontainers.ContainerRequest{ - Image: "registry:2.8.3", + Image: img, ExposedPorts: []string{"5000/tcp"}, Env: map[string]string{ // convenient for testing diff --git a/modules/registry/registry_test.go b/modules/registry/registry_test.go index 62c1ebf6e6..1b6849ebbe 100644 --- a/modules/registry/registry_test.go +++ b/modules/registry/registry_test.go @@ -13,7 +13,7 @@ import ( ) func TestRegistry_unauthenticated(t *testing.T) { - container, err := registry.RunContainer(context.Background(), testcontainers.WithImage("registry:2.8.3")) + container, err := registry.Run(context.Background(), "registry:2.8.3") if err != nil { t.Fatal(err) } @@ -42,9 +42,9 @@ func TestRegistry_unauthenticated(t *testing.T) { } func TestRunContainer_authenticated(t *testing.T) { - registryContainer, err := registry.RunContainer( + registryContainer, err := registry.Run( context.Background(), - testcontainers.WithImage("registry:2.8.3"), + "registry:2.8.3", registry.WithHtpasswdFile(filepath.Join("testdata", "auth", "htpasswd")), registry.WithData(filepath.Join("testdata", "data")), ) @@ -221,9 +221,9 @@ func TestRunContainer_authenticated(t *testing.T) { func TestRunContainer_authenticated_withCredentials(t *testing.T) { // htpasswdString { - registryContainer, err := registry.RunContainer( + registryContainer, err := registry.Run( context.Background(), - testcontainers.WithImage("registry:2.8.3"), + "registry:2.8.3", registry.WithHtpasswd("testuser:$2y$05$tTymaYlWwJOqie.bcSUUN.I.kxmo1m5TLzYQ4/ejJ46UMXGtq78EO"), ) // } @@ -261,9 +261,9 @@ func TestRunContainer_authenticated_withCredentials(t *testing.T) { } func TestRunContainer_wrongData(t *testing.T) { - registryContainer, err := registry.RunContainer( + registryContainer, err := registry.Run( context.Background(), - testcontainers.WithImage("registry:2.8.3"), + "registry:2.8.3", registry.WithHtpasswdFile(filepath.Join("testdata", "auth", "htpasswd")), registry.WithData(filepath.Join("testdata", "wrongdata")), ) diff --git a/modules/surrealdb/examples_test.go b/modules/surrealdb/examples_test.go index ad27e3ac0e..2063903d42 100644 --- a/modules/surrealdb/examples_test.go +++ b/modules/surrealdb/examples_test.go @@ -5,15 +5,14 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/surrealdb" ) -func ExampleRunContainer() { +func ExampleRun() { // runSurrealDBContainer { ctx := context.Background() - surrealdbContainer, err := surrealdb.RunContainer(ctx, testcontainers.WithImage("surrealdb/surrealdb:v1.1.1")) + surrealdbContainer, err := surrealdb.Run(ctx, "surrealdb/surrealdb:v1.1.1") if err != nil { log.Fatal(err) } diff --git a/modules/surrealdb/surrealdb.go b/modules/surrealdb/surrealdb.go index 78d0707fe1..1968ca5d98 100644 --- a/modules/surrealdb/surrealdb.go +++ b/modules/surrealdb/surrealdb.go @@ -79,10 +79,16 @@ func WithAllowAllCaps() testcontainers.CustomizeRequestOption { } } +// Deprecated: use Run instead // RunContainer creates an instance of the SurrealDB container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error) { + return Run(ctx, "surrealdb/surrealdb:v1.1.1", opts...) +} + +// Run creates an instance of the SurrealDB container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*SurrealDBContainer, error) { req := testcontainers.ContainerRequest{ - Image: "surrealdb/surrealdb:v1.1.1", + Image: img, Env: map[string]string{ "SURREAL_USER": "root", "SURREAL_PASS": "root", diff --git a/modules/surrealdb/surrealdb_test.go b/modules/surrealdb/surrealdb_test.go index 27ed38017b..7a3de29bfd 100644 --- a/modules/surrealdb/surrealdb_test.go +++ b/modules/surrealdb/surrealdb_test.go @@ -5,14 +5,12 @@ import ( "testing" "github.com/surrealdb/surrealdb.go" - - "github.com/testcontainers/testcontainers-go" ) func TestSurrealDBSelect(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("surrealdb/surrealdb:v1.1.1")) + container, err := Run(ctx, "surrealdb/surrealdb:v1.1.1") if err != nil { t.Fatal(err) } @@ -73,7 +71,7 @@ func TestSurrealDBSelect(t *testing.T) { func TestSurrealDBWithAuth(t *testing.T) { ctx := context.Background() - container, err := RunContainer(ctx, testcontainers.WithImage("surrealdb/surrealdb:v1.1.1"), WithAuthentication()) + container, err := Run(ctx, "surrealdb/surrealdb:v1.1.1", WithAuthentication()) if err != nil { t.Fatal(err) } diff --git a/modules/vault/examples_test.go b/modules/vault/examples_test.go index 364b07347b..75dc908f6b 100644 --- a/modules/vault/examples_test.go +++ b/modules/vault/examples_test.go @@ -9,11 +9,11 @@ import ( "github.com/testcontainers/testcontainers-go/modules/vault" ) -func ExampleRunContainer() { +func ExampleRun() { // runVaultContainer { ctx := context.Background() - vaultContainer, err := vault.RunContainer(ctx) + vaultContainer, err := vault.Run(ctx, "hashicorp/vault:1.13.0") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -37,11 +37,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_withToken() { +func ExampleRun_withToken() { // runVaultContainerWithToken { ctx := context.Background() - vaultContainer, err := vault.RunContainer(ctx, vault.WithToken("MyToKeN")) + vaultContainer, err := vault.Run(ctx, "hashicorp/vault:1.13.0", vault.WithToken("MyToKeN")) if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -76,11 +76,11 @@ func ExampleRunContainer_withToken() { // 0 } -func ExampleRunContainer_withInitCommand() { +func ExampleRun_withInitCommand() { // runVaultContainerWithInitCommand { ctx := context.Background() - vaultContainer, err := vault.RunContainer(ctx, vault.WithToken("MyToKeN"), vault.WithInitCommand( + vaultContainer, err := vault.Run(ctx, "hashicorp/vault:1.13.0", vault.WithToken("MyToKeN"), vault.WithInitCommand( "auth enable approle", // Enable the approle auth method "secrets disable secret", // Disable the default secret engine "secrets enable -version=1 -path=secret kv", // Enable the kv secret engine at version 1 diff --git a/modules/vault/vault.go b/modules/vault/vault.go index 5c6f47aa6e..37237748ed 100644 --- a/modules/vault/vault.go +++ b/modules/vault/vault.go @@ -12,8 +12,7 @@ import ( ) const ( - defaultPort = "8200" - defaultImageName = "hashicorp/vault:1.13.0" + defaultPort = "8200" ) // VaultContainer represents the vault container type used in the module @@ -21,10 +20,16 @@ type VaultContainer struct { testcontainers.Container } -// RunContainer creates an instance of the vault container type +// Deprecated: use Run instead +// RunContainer creates an instance of the Vault container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error) { + return Run(ctx, "hashicorp/vault:1.13.0", opts...) +} + +// Run creates an instance of the Vault container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VaultContainer, error) { req := testcontainers.ContainerRequest{ - Image: defaultImageName, + Image: img, ExposedPorts: []string{defaultPort + "/tcp"}, HostConfigModifier: func(hc *container.HostConfig) { hc.CapAdd = []string{"IPC_LOCK"} diff --git a/modules/vault/vault_test.go b/modules/vault/vault_test.go index d068827fdc..23a52cee57 100644 --- a/modules/vault/vault_test.go +++ b/modules/vault/vault_test.go @@ -25,9 +25,6 @@ const ( func TestVault(t *testing.T) { ctx := context.Background() opts := []testcontainers.ContainerCustomizer{ - // WithImageName { - testcontainers.WithImage("hashicorp/vault:1.13.0"), - // } // WithToken { testcontainervault.WithToken(token), // } @@ -37,7 +34,7 @@ func TestVault(t *testing.T) { // } } - vaultContainer, err := testcontainervault.RunContainer(ctx, opts...) + vaultContainer, err := testcontainervault.Run(ctx, "hashicorp/vault:1.13.0", opts...) require.NoError(t, err) // httpHostAddress { diff --git a/modules/vearch/examples_test.go b/modules/vearch/examples_test.go index aaccb5d2de..116484c583 100644 --- a/modules/vearch/examples_test.go +++ b/modules/vearch/examples_test.go @@ -5,14 +5,13 @@ import ( "fmt" "log" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/vearch" ) -func ExampleRunContainer() { +func ExampleRun() { ctx := context.Background() - vearchContainer, err := vearch.RunContainer(ctx, testcontainers.WithImage("vearch/vearch:3.5.1")) + vearchContainer, err := vearch.Run(ctx, "vearch/vearch:3.5.1") if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/vearch/vearch.go b/modules/vearch/vearch.go index bcb6370e23..dccedacad1 100644 --- a/modules/vearch/vearch.go +++ b/modules/vearch/vearch.go @@ -14,10 +14,16 @@ type VearchContainer struct { testcontainers.Container } +// Deprecated: use Run instead // RunContainer creates an instance of the Vearch container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) { + return Run(ctx, "vearch/vearch:3.5.1", opts...) +} + +// Run creates an instance of the Vearch container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*VearchContainer, error) { req := testcontainers.ContainerRequest{ - Image: "vearch/vearch:3.5.1", + Image: img, ExposedPorts: []string{"8817/tcp", "9001/tcp"}, Cmd: []string{"-conf=/vearch/config.toml", "all"}, Privileged: true, diff --git a/modules/vearch/vearch_test.go b/modules/vearch/vearch_test.go index 4d074da828..f73abda7de 100644 --- a/modules/vearch/vearch_test.go +++ b/modules/vearch/vearch_test.go @@ -5,14 +5,13 @@ import ( "net/http" "testing" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/vearch" ) func TestVearch(t *testing.T) { ctx := context.Background() - container, err := vearch.RunContainer(ctx, testcontainers.WithImage("vearch/vearch:3.5.1")) + container, err := vearch.Run(ctx, "vearch/vearch:3.5.1") if err != nil { t.Fatal(err) } diff --git a/modules/weaviate/examples_test.go b/modules/weaviate/examples_test.go index 483b922e0a..d6c8f50988 100644 --- a/modules/weaviate/examples_test.go +++ b/modules/weaviate/examples_test.go @@ -15,11 +15,11 @@ import ( tcweaviate "github.com/testcontainers/testcontainers-go/modules/weaviate" ) -func ExampleRunContainer() { +func ExampleRun() { // runWeaviateContainer { ctx := context.Background() - weaviateContainer, err := tcweaviate.RunContainer(ctx, testcontainers.WithImage("semitechnologies/weaviate:1.24.5")) + weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.24.5") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -43,11 +43,11 @@ func ExampleRunContainer() { // true } -func ExampleRunContainer_connectWithClient() { +func ExampleRun_connectWithClient() { // createClientNoModules { ctx := context.Background() - weaviateContainer, err := tcweaviate.RunContainer(ctx, testcontainers.WithImage("semitechnologies/weaviate:1.23.9")) + weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.23.9") if err != nil { log.Fatalf("failed to start container: %s", err) } @@ -94,7 +94,7 @@ func ExampleRunContainer_connectWithClient() { // } -func ExampleRunContainer_connectWithClientWithModules() { +func ExampleRun_connectWithClientWithModules() { // createClientAndModules { ctx := context.Background() @@ -111,11 +111,10 @@ func ExampleRunContainer_connectWithClientWithModules() { } opts := []testcontainers.ContainerCustomizer{ - testcontainers.WithImage("semitechnologies/weaviate:1.25.5"), testcontainers.WithEnv(envs), } - weaviateContainer, err := tcweaviate.RunContainer(ctx, opts...) + weaviateContainer, err := tcweaviate.Run(ctx, "semitechnologies/weaviate:1.25.5", opts...) if err != nil { log.Fatalf("failed to start container: %s", err) } diff --git a/modules/weaviate/weaviate.go b/modules/weaviate/weaviate.go index 1d51036572..93665efc66 100644 --- a/modules/weaviate/weaviate.go +++ b/modules/weaviate/weaviate.go @@ -10,7 +10,6 @@ import ( ) const ( - image = "semitechnologies/weaviate:1.25.5" httpPort = "8080/tcp" grpcPort = "50051/tcp" ) @@ -20,10 +19,16 @@ type WeaviateContainer struct { testcontainers.Container } +// Deprecated: use Run instead // RunContainer creates an instance of the Weaviate container type func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) { + return Run(ctx, "semitechnologies/weaviate:1.25.5", opts...) +} + +// Run creates an instance of the Weaviate container type +func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*WeaviateContainer, error) { req := testcontainers.ContainerRequest{ - Image: image, + Image: img, Cmd: []string{"--host", "0.0.0.0", "--scheme", "http", "--port", "8080"}, ExposedPorts: []string{httpPort, grpcPort}, Env: map[string]string{ diff --git a/modules/weaviate/weaviate_test.go b/modules/weaviate/weaviate_test.go index 8d4f630906..63aa04d04b 100644 --- a/modules/weaviate/weaviate_test.go +++ b/modules/weaviate/weaviate_test.go @@ -12,14 +12,13 @@ import ( "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/health/grpc_health_v1" - "github.com/testcontainers/testcontainers-go" "github.com/testcontainers/testcontainers-go/modules/weaviate" ) func TestWeaviate(t *testing.T) { ctx := context.Background() - container, err := weaviate.RunContainer(ctx, testcontainers.WithImage("semitechnologies/weaviate:1.25.5")) + container, err := weaviate.Run(ctx, "semitechnologies/weaviate:1.25.5") if err != nil { t.Fatal(err) } diff --git a/options.go b/options.go index 95b6d9394f..4999a82362 100644 --- a/options.go +++ b/options.go @@ -95,6 +95,7 @@ func WithHostPortAccess(ports ...int) CustomizeRequestOption { } } +// Deprecated: the modules API forces passing the image as part of the signature of the Run function. // WithImage sets the image for a container func WithImage(image string) CustomizeRequestOption { return func(req *GenericContainerRequest) error {