Skip to content

Commit ad8cd4a

Browse files
Merge branch 'main' into refactor-timeouts
2 parents 0164516 + 1ccbc6d commit ad8cd4a

File tree

88 files changed

+2007
-519
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2007
-519
lines changed

docs/features/compose.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ const environment = await new DockerComposeEnvironment(composeFilePath, composeF
4141
.up();
4242
```
4343

44+
### With a default wait strategy
45+
46+
By default Testcontainers uses the "listening ports" wait strategy for all containers. If you'd like to override
47+
the default wait strategy for all services, you can do so:
48+
49+
```javascript
50+
const environment = await new DockerComposeEnvironment(composeFilePath, composeFile)
51+
.withDefaultWaitStrategy(Wait.forHealthCheck())
52+
.up();
53+
```
54+
4455
### With a pull policy
4556

4657
Testcontainers will automatically pull an image if it doesn't exist. This is configurable:

docs/features/containers.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,35 @@ const container = await new GenericContainer("alpine")
583583
.start();
584584
```
585585

586+
## SocatContainer as a TCP proxy
587+
588+
`SocatContainer` enables any TCP port of another container to be exposed publicly.
589+
590+
```javascript
591+
const network = await new Network().start();
592+
593+
const container = await new GenericContainer("testcontainers/helloworld:1.2.0")
594+
.withExposedPorts(8080)
595+
.withNetwork(network)
596+
.withNetworkAliases("helloworld")
597+
.start();
598+
599+
const socat = await new SocatContainer()
600+
.withNetwork(network)
601+
.withTarget(8081, "helloworld", 8080)
602+
.start();
603+
604+
const socatUrl = `http://${socat.getHost()}:${socat.getMappedPort(8081)}`;
605+
606+
const response = await fetch(`${socatUrl}/ping`);
607+
608+
expect(response.status).toBe(200);
609+
expect(await response.text()).toBe("PONG");
610+
```
611+
612+
The example above starts a `testcontainers/helloworld` container and a `socat` container.
613+
The `socat` container is configured to forward traffic from port `8081` to the `testcontainers/helloworld` container on port `8080`.
614+
586615
## Running commands
587616

588617
To run a command inside an already started container, use the exec method.
@@ -605,7 +634,6 @@ The following options can be provided to modify the command execution:
605634

606635
3. **`env`:** A map of environment variables to set inside the container.
607636

608-
609637
```javascript
610638
const container = await new GenericContainer("alpine")
611639
.withCommand(["sleep", "infinity"])
@@ -621,8 +649,6 @@ const { output, stdout, stderr, exitCode } = await container.exec(["echo", "hell
621649
});
622650
```
623651

624-
625-
626652
## Streaming logs
627653

628654
Logs can be consumed either from a started container:

docs/features/wait-strategies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ const container = await new GenericContainer("redis")
155155

156156
```javascript
157157
.withWaitStrategy(Wait.forHttp("/health", 8443)
158-
.useTls())
158+
.usingTls())
159159
```
160160

161161
#### Insecure TLS
162162

163163
```javascript
164164
.withWaitStrategy(Wait.forHttp("/health", 8443)
165-
.useTls()
165+
.usingTls()
166166
.insecureTls())
167167
```
168168

docs/modules/clickhouse.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# ClickHouse Module
2+
3+
[ClickHouse](https://clickhouse.com/) is a column-oriented database management system for online analytical processing (OLAP) that allows users to generate analytical reports using SQL queries in real-time.
4+
5+
## Install
6+
7+
```bash
8+
npm install @testcontainers/clickhouse --save-dev
9+
```
10+
11+
## Examples
12+
13+
<!--codeinclude-->
14+
[Connect and execute query:](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:connectWithOptions
15+
<!--/codeinclude-->
16+
17+
<!--codeinclude-->
18+
[Connect using URL and execute query:](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:connectWithUrl
19+
<!--/codeinclude-->
20+
21+
<!--codeinclude-->
22+
[Connect with username and password and execute query:](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:connectWithUsernameAndPassword
23+
<!--/codeinclude-->
24+
25+
<!--codeinclude-->
26+
[Set database:](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:setDatabase
27+
<!--/codeinclude-->
28+
29+
<!--codeinclude-->
30+
[Set username:](../../packages/modules/clickhouse/src/clickhouse-container.test.ts) inside_block:setUsername
31+
<!--/codeinclude-->
32+
33+
### Connection Methods
34+
35+
The module provides several methods to connect to the ClickHouse container:
36+
37+
1. `getClientOptions()` - Returns a configuration object suitable for `@clickhouse/client`:
38+
```typescript
39+
{
40+
url: string; // HTTP URL with host and port
41+
username: string; // Container username
42+
password: string; // Container password
43+
database: string; // Container database
44+
}
45+
```
46+
2. `getConnectionUrl()` - Returns a complete HTTP URL including credentials and database:
47+
```
48+
http://[username[:password]@][host[:port]]/database
49+
```
50+
3. `getHttpUrl()` - Returns the base HTTP URL without credentials:
51+
```
52+
http://[host[:port]]
53+
```
54+
55+
These methods can be used with the `@clickhouse/client` package or any other ClickHouse client.

docs/modules/etcd.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Etcd Module
2+
3+
[Etcd](https://etcd.io/) is a strongly consistent, distributed key-value store that provides a reliable way to store data that needs to be accessed by a distributed system or cluster of machines.
4+
5+
## Install
6+
7+
```bash
8+
npm install @testcontainers/etcd --save-dev
9+
```
10+
11+
## Examples
12+
13+
<!--codeinclude-->
14+
[Read and write key-value pairs:](../../packages/modules/etcd/src/etcd-container.test.ts) inside_block:readWrite
15+
<!--/codeinclude-->
16+
17+
<!--codeinclude-->
18+
[Subscribe to key changes:](../../packages/modules/etcd/src/etcd-container.test.ts) inside_block:subscribe
19+
<!--/codeinclude-->

docs/modules/neo4j.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ npm install @testcontainers/neo4j --save-dev
2121
<!--codeinclude-->
2222
[Configure APOC:](../../packages/modules/neo4j/src/neo4j-container.test.ts) inside_block:apoc
2323
<!--/codeinclude-->
24+
25+
<!--codeinclude-->
26+
[Configure other supported plugins:](../../packages/modules/neo4j/src/neo4j-container.test.ts) inside_block:pluginsList
27+
<!--/codeinclude-->

docs/modules/postgresql.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,18 @@ npm install @testcontainers/postgresql --save-dev
2525
<!--codeinclude-->
2626
[Set username:](../../packages/modules/postgresql/src/postgresql-container.test.ts) inside_block:setUsername
2727
<!--/codeinclude-->
28+
29+
### Using Snapshots
30+
31+
This example shows the usage of the postgres module's Snapshot feature to give each test a clean database without having
32+
to recreate the database container on every test or run heavy scripts to clean your database. This makes the individual
33+
tests very modular, since they always run on a brand-new database.
34+
35+
!!!tip
36+
You should never pass the `"postgres"` system database as the container database name if you want to use snapshots.
37+
The Snapshot logic requires dropping the connected database and using the system database to run commands, which will
38+
not work if the database for the container is set to `"postgres"`.
39+
40+
<!--codeinclude-->
41+
[Test with a reusable Postgres container](../../packages/modules/postgresql/src/postgresql-container-snapshot.test.ts) inside_block:createAndRestoreFromSnapshot
42+
<!--/codeinclude-->

docs/modules/redis.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,37 @@ npm install @testcontainers/redis --save-dev
1111
## Examples
1212

1313
<!--codeinclude-->
14+
1415
[Start container:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:startContainer
16+
1517
<!--/codeinclude-->
1618

1719
<!--codeinclude-->
20+
1821
[Connect redis client to container:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:simpleConnect
22+
1923
<!--/codeinclude-->
2024

2125
<!--codeinclude-->
26+
2227
[Start container with password authentication:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:startWithCredentials
28+
2329
<!--/codeinclude-->
2430

2531
<!--codeinclude-->
32+
2633
[Define volume for persistent/predefined data:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:persistentData
34+
2735
<!--/codeinclude-->
2836

2937
<!--codeinclude-->
38+
39+
[Start container with redis/redis-stack-server image:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:startWithRedisStack
40+
41+
<!--/codeinclude-->
42+
43+
<!--codeinclude-->
44+
3045
[Execute a command inside the container:](../../packages/modules/redis/src/redis-container.test.ts) inside_block:executeCommand
46+
3147
<!--/codeinclude-->

docs/quickstart/global-setup.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function setup() {
1919
url: `redis://${redisContainer.getHost()}:${redisContainer.getMappedPort(6379)}`
2020
});
2121

22-
await redisClient.connect();
22+
await globalThis.redisClient.connect();
2323
}
2424

2525
export async function teardown() {

docs/quickstart/logging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,4 @@ If we run the test again, we'll see a lot of debug output:
132132
[INFO] [936d82e9964e] Stopped container
133133
```
134134

135-
These logs are very useful for debugging when a container isn't working as expected. You can see there are logs from the Testcontainers library, as well as logs emitted from all Testcontainers-managed containers.
135+
These logs are useful for debugging when a container isn't working as expected. You can see there are logs from the Testcontainers library, as well as logs emitted from all Testcontainers-managed containers.

0 commit comments

Comments
 (0)