Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: use Go testable examples in modules #1603

Merged
merged 39 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ba14798
fix: rename vault container in tests
mdelapenya Sep 6, 2023
b192a81
chore: adjust comment in template
mdelapenya Sep 6, 2023
64bd746
docs(vault): use RunContainer example in usage section
mdelapenya Sep 6, 2023
14a6022
docs: update vault docs
mdelapenya Sep 6, 2023
d5b68da
docs: add RunContainer example for redpanda
mdelapenya Sep 7, 2023
4cb9f60
docs: add RunContainer example for redis
mdelapenya Sep 7, 2023
93f2a5c
docs: document creating networks
mdelapenya Sep 7, 2023
61b37ec
docs: add RunContainer example for pulsar
mdelapenya Sep 7, 2023
e547200
docs: add RunContainer example for postgres
mdelapenya Sep 7, 2023
2273da3
docs: add RunContainer example for neo4j
mdelapenya Sep 7, 2023
a2b03fd
docs: add RunContainer example for nats
mdelapenya Sep 7, 2023
8325e51
docs: update quickstart to not use testing libraries
mdelapenya Sep 7, 2023
2886ebd
docs: add RunContainer example for mysql
mdelapenya Sep 7, 2023
72cabe1
docs: add RunContainer example for mongo
mdelapenya Sep 7, 2023
86015c5
docs: add RunContainer example for mariadb
mdelapenya Sep 7, 2023
fc9b9ce
chore: use logger to print out hostname external reason
mdelapenya Sep 7, 2023
7ad9043
docs: document new Go examples file
mdelapenya Sep 7, 2023
fc9bea3
docs: add RunContainer example for localstack
mdelapenya Sep 7, 2023
9bd0377
chore: convert k3s test into a testable example
mdelapenya Sep 7, 2023
9911613
chore: convert mongodb test into testable example
mdelapenya Sep 7, 2023
8f90e0a
fix: handle errors in example tests for elasticsearch
mdelapenya Sep 7, 2023
af18064
fix: do not deprecate used fields
mdelapenya Sep 8, 2023
286c86f
chore: convert couchbase test into testable example
mdelapenya Sep 8, 2023
7a48310
chore: convert clickhouse test into testable example
mdelapenya Sep 8, 2023
ac4c5f0
docs: adjust artemis docs
mdelapenya Sep 8, 2023
a6c4780
chore: simplify postgres example
mdelapenya Sep 8, 2023
b01f6af
fix: lint
mdelapenya Sep 8, 2023
94386b9
Merge branch 'main' into migrate-examples
mdelapenya Sep 10, 2023
d411e3a
chore(deps): bump github.com/hashicorp/vault-client-go in /modules/va…
mmorel-35 Sep 11, 2023
7c5f468
ci(lint): enable gocritic linter (#1605)
mmorel-35 Sep 11, 2023
a85ac93
ci(lint): enable errorlint linter (#1604)
mmorel-35 Sep 11, 2023
d6c4221
fix: handle errors
mdelapenya Sep 11, 2023
9235361
chore(pulsar): create/remove the network properly
mdelapenya Sep 11, 2023
b5d3749
Merge branch 'main' into migrate-examples
mdelapenya Sep 11, 2023
0e28881
chore: better container logs on errors during startup
mdelapenya Sep 11, 2023
25adc7a
Revert "chore: better container logs on errors during startup"
mdelapenya Sep 11, 2023
2d91912
chore: better container logs on errors during startup
mdelapenya Sep 11, 2023
c8a8a7b
fix: do not wrap error but print it
mdelapenya Sep 11, 2023
1f64536
fix: avoid polluting default wait strategies in pulsar
mdelapenya Sep 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/features/creating_networks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# How to create a network

Apart from creating containers, `Testcontainers for Go` also allows you to create networks. This is useful when you need to connect multiple containers to the same network.

## Usage example

<!--codeinclude-->
[Creating a network](../../network_test.go) inside_block:createNetwork
<!--/codeinclude-->

<!--codeinclude-->
[Creating a network with IPAM](../../network_test.go) inside_block:withIPAM
<!--/codeinclude-->
16 changes: 11 additions & 5 deletions docs/modules/artemis.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ go get github.com/testcontainers/testcontainers-go/modules/artemis
## Usage example

<!--codeinclude-->
[Creating and connecting to an Artemis container](../../modules/artemis/example_test.go) inside_block:ExampleRunContainer
[Creating to an Artemis container](../../modules/artemis/examples_test.go) inside_block:runArtemisContainer
<!--/codeinclude-->

<!--codeinclude-->
[Connecting to an Artemis container](../../modules/artemis/examples_test.go) inside_block:connectToArtemisContainer
<!--/codeinclude-->

## Module reference
Expand Down Expand Up @@ -58,7 +62,7 @@ If you need to change the default admin credentials (i.e. `artemis:artemis`) use
[With credentials](../../modules/artemis/artemis_test.go) inside_block:withCredentials
<!--/codeinclude-->

#### Anonymous Login
#### Enable Anonymous login

If you need to enable anonymous logins (which are disabled by default) use `WithAnonymousLogin`.

Expand All @@ -71,7 +75,9 @@ If you need to enable anonymous logins (which are disabled by default) use `With
If you need to pass custom arguments to the `artemis create` command, use `WithExtraArgs`.
The default is `--http-host 0.0.0.0 --relax-jolokia`.
Setting this value will override the default.
See the documentation on `artemis create` for available options.

!!!info
Please see the documentation on `artemis create` for the available options here: [https://activemq.apache.org/components/artemis/documentation/latest/using-server.html#options](https://activemq.apache.org/components/artemis/documentation/latest/using-server.html#options)

<!--codeinclude-->
[With Extra Arguments](../../modules/artemis/artemis_test.go) inside_block:withExtraArgs
Expand All @@ -96,15 +102,15 @@ The Artemis container exposes the following methods:
User returns the administrator username.

<!--codeinclude-->
[Retrieving the Administrator User](../../modules/artemis/example_test.go) inside_block:containerUser
[Retrieving the Administrator User](../../modules/artemis/examples_test.go) inside_block:containerUser
<!--/codeinclude-->

#### Password

Password returns the administrator password.

<!--codeinclude-->
[Retrieving the Administrator Password](../../modules/artemis/example_test.go) inside_block:containerPassword
[Retrieving the Administrator Password](../../modules/artemis/examples_test.go) inside_block:containerPassword
<!--/codeinclude-->

#### BrokerEndpoint
Expand Down
56 changes: 30 additions & 26 deletions docs/modules/clickhouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ go get github.com/testcontainers/testcontainers-go/modules/clickhouse
## Usage example

<!--codeinclude-->

[Test for a ClickHouse container](../../modules/clickhouse/clickhouse_test.go)inside_block:customInitialization

[Test for a ClickHouse container](../../modules/clickhouse/examples_test.go) inside_block:runClickHouseContainer
<!--/codeinclude-->

## Module reference
Expand All @@ -33,6 +31,14 @@ func RunContainer(ctx context.Context, opts ...testcontainers.ContainerCustomize
- `context.Context`, the Go context.
- `testcontainers.ContainerCustomizer`, a variadic argument for passing options.

### Container Ports

Here you can find the list with the default ports used by the ClickHouse container.

<!--codeinclude-->
[Container Ports](../../modules/clickhouse/clickhouse.go) inside_block:containerPorts
<!--/codeinclude-->

### Container Options

When starting the ClickHouse container, you can pass options in a variadic way to configure it.
Expand Down Expand Up @@ -65,13 +71,7 @@ Please read the [Create containers: Advanced Settings](../features/creating_cont
#### Set username, password and database name

If you need to set a different database, and its credentials, you can use `WithUsername`, `WithPassword`, `WithDatabase`
options.

<!--codeinclude-->

[Custom Database initialization](../../modules/clickhouse/clickhouse_test.go) inside_block:customInitialization

<!--/codeinclude-->
options. E.g. `WithUsername("user")`, `WithPassword("password")`, `WithDatabase("db")`.

!!!info
The default values for the username is `default`, for password is `clickhouse` and for the default database name is `clickhouse`.
Expand All @@ -84,42 +84,46 @@ it will run any `*.sql` files, run any executable `*.sh` scripts, and source any
initialization before starting the service.

<!--codeinclude-->

[Include init scripts](../../modules/clickhouse/clickhouse_test.go) inside_block:withInitScripts
<!--/codeinclude-->

<!--codeinclude-->
[Init script content](../../modules/clickhouse/testdata/init-db.sh)
<!--/codeinclude-->

#### Custom configuration

If you need to set a custom configuration, the module provides the `WithConfigFile` option to pass the path to a custom configuration file in XML format.

<!--codeinclude-->
[XML config file](../../modules/clickhouse/testdata/config.xml)
<!--/codeinclude-->

[Init script content](../../modules/clickhouse/testdata/init-db.sh)
In the case you want to pass a YAML configuration file, you can use the `WithYamlConfigFile` option.

<!--codeinclude-->
[YAML config file](../../modules/clickhouse/testdata/config.yaml)
<!--/codeinclude-->

### Container Methods

The ClickHouse container exposes the following methods:

#### ConnectionString

This method returns the dsn connection string to connect to the ClickHouse container, using the default configs.
It's possible to pass extra parameters to the connection string, e.g. `dial_timeout=300ms` or `skip_verify=false`, in a variadic way.
#### ConnectionHost

e.g. `clickhouse://default:pass@localhost:9000?dial_timeout=300ms&skip_verify=false`
This method returns the host and port of the ClickHouse container, using the default, native `9000/tcp` port. E.g. `localhost:9000`

<!--codeinclude-->

[Get connection string](../../modules/clickhouse/clickhouse_test.go) inside_block:connectionString

[Get connection host](../../modules/clickhouse/clickhouse_test.go) inside_block:connectionHost
<!--/codeinclude-->

#### ConnectionHost
#### ConnectionString

This method returns the host & port of the ClickHouse container.
This method returns the dsn connection string to connect to the ClickHouse container, using the default, native `9000/tcp` port obtained from the `ConnectionHost` method.
It's possible to pass extra parameters to the connection string, e.g. `dial_timeout=300ms` or `skip_verify=false`, in a variadic way.

e.g. `localhost:9000`
e.g. `clickhouse://default:pass@localhost:9000?dial_timeout=300ms&skip_verify=false`

<!--codeinclude-->

[Get connection host](../../modules/clickhouse/clickhouse_test.go) inside_block:connectionHost

[Get connection string](../../modules/clickhouse/clickhouse_test.go) inside_block:connectionString
<!--/codeinclude-->
35 changes: 15 additions & 20 deletions docs/modules/couchbase.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ go get github.com/testcontainers/testcontainers-go/modules/couchbase
## Usage example

<!--codeinclude-->
[Start Couchbase](../../modules/couchbase/couchbase_test.go) inside_block:withBucket
[Creating a Couchbase container](../../modules/couchbase/examples_test.go) inside_block:runCouchbaseContainer
<!--/codeinclude-->

## Module Reference
Expand Down Expand Up @@ -49,6 +49,11 @@ Once the container is started, it will perform the following operations, **in th

### Container Ports

Here you can find the list with the default ports used by the Couchbase container. The Management ports (`MGMT_PORT` and `MGMT_SSL_PORT`) and the Service ports for `kv`, `query` and `search` are exposed by default.

!!!tip
You can export the service ports for Analytics and Eventing by using the `WithServiceAnalytics` and `WithServiceEventing` optional functions.

<!--codeinclude-->
[Container Ports](../../modules/couchbase/couchbase.go) inside_block:containerPorts
<!--/codeinclude-->
Expand All @@ -68,6 +73,12 @@ By default, the container will use the following Docker image:
[Default Docker image](../../modules/couchbase/couchbase.go) inside_block:defaultImage
<!--/codeinclude-->

You can find the Docker images that are currently tested in this module, for the Enterprise and Community editions, in the following list:

<!--codeinclude-->
[Docker images](../../modules/couchbase/couchbase_test.go) inside_block:dockerImages
<!--/codeinclude-->

#### Wait Strategies

If you need to set a different wait strategy for Couchbase, you can use `testcontainers.WithWaitStrategy` with a valid wait strategy
Expand All @@ -94,12 +105,12 @@ If you need to change the default credentials for the admin user, you can use `W
When the password has less than 6 characters, the container won't be created and the `RunContainer` function will throw an error.

!!!info
The default username is `Administrator` and the default password is `password`.
In the case this optional function is not called, the default username is `Administrator` and the default password is `password`.

#### Buckets

When creating a new Couchbase container, you can create one or more buckets. The module provides with a `WithBuckets` function that accepts an array of buckets to be created.
To create a new bucket, the module exposes a `NewBucket` function, where you can pass the bucket name.
When creating a new Couchbase container, you can create one or more buckets. The module exposes a `WithBuckets` optional function that accepts an slice of buckets to be created.
To create a new bucket, the module also exposes a `NewBucket` function, where you can pass the bucket name.

It's possible to customize a newly created bucket, using the following options:

Expand Down Expand Up @@ -131,33 +142,17 @@ By default, the container will start with the following services: `kv`, `n1ql`,
When running the Enterprise Edition of Couchbase Server, the module provides two functions to enable or disable services:
`WithServiceAnalytics` and `WithServiceEventing`. Else, it will throw an error and the container won't be created.

<!--codeinclude-->
[Docker images](../../modules/couchbase/couchbase_test.go) inside_block:dockerImages
<!--/codeinclude-->

### Container Methods

#### ConnectionString

The `ConnectionString` method returns the connection string to connect to the Couchbase container instance.
It returns a string with the format `couchbase://<host>:<port>`.

<!--codeinclude-->
[Connect to Couchbase](../../modules/couchbase/couchbase_test.go) inside_block:connectToCluster
<!--/codeinclude-->

#### Username

The `Username` method returns the username of the Couchbase administrator.

<!--codeinclude-->
[Connect to Couchbase using Credentials](../../modules/couchbase/couchbase_test.go) inside_block:getCredentials
<!--/codeinclude-->

#### Password

The `Password` method returns the password of the Couchbase administrator.

<!--codeinclude-->
[Connect to Couchbase using Credentials](../../modules/couchbase/couchbase_test.go) inside_block:getCredentials
<!--/codeinclude-->
4 changes: 3 additions & 1 deletion docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ We have provided a command line tool to generate the scaffolding for the code of
- 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 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:
- the version of _Testcontainers for Go_ in which the module was added.
- a short introduction to the module.
- a section for adding the module to the project dependencies.
- a section for a usage example.
- a section for a usage example, including:
- a snippet for creating the container, from the `examples_test.go` file in the Go module.
- a section for the module reference, including:
- the entrypoint function for creating the container.
- the options for creating the container.
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/k3s.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ go get github.com/testcontainers/testcontainers-go/modules/k3s
## Usage example

<!--codeinclude-->
[Test for a K3s container](../../modules/k3s/k3s_test.go) inside_block: k3sRunContainer
[Test for a K3s container](../../modules/k3s/k3s_test.go) inside_block:runK3sContainer
<!--/codeinclude-->

## Module reference
Expand Down
Loading