Skip to content

Commit d461e81

Browse files
authored
feat: Add support for Testcontainers. (#197)
1 parent baf7587 commit d461e81

16 files changed

+1640
-372
lines changed

.github/dependabot.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,6 @@ updates:
1616
prefix: chore
1717
prefix-development: chore
1818

19-
- package-ecosystem: docker
20-
directory: "/test/docker"
21-
schedule:
22-
interval: weekly
23-
open-pull-requests-limit: 10
24-
assignees:
25-
- thenativeweb/internal_dev
26-
labels:
27-
- Dependencies
28-
commit-message:
29-
prefix: chore
30-
3119
- package-ecosystem: "github-actions"
3220
directory: "/"
3321
schedule:

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ EventSourcingDB enables you to build and operate event-driven applications with
66

77
For more information on EventSourcingDB, see its [official documentation](https://docs.eventsourcingdb.io/).
88

9+
This client SDK includes support for [Testcontainers](https://testcontainers.com/) to spin up EventSourcingDB instances in integration tests. For details, see [Using Testcontainers](#using-testcontainers).
10+
911
## Getting Started
1012

1113
Import the `Client` class and create an instance by providing the URL of your EventSourcingDB instance and the API token to use:
@@ -356,3 +358,52 @@ for await (const eventType of client.readEventTypes()) {
356358
// reading to end.
357359
controller.abort();
358360
```
361+
362+
### Using Testcontainers
363+
364+
Import the `EventSourcingDbContainer` class, create an instance, call the `start` function to run a test container, get a client, run your test code, and finally call the `stop` function to stop the test container:
365+
366+
```typescript
367+
import { EventSourcingDbContainer } from 'eventsourcingdb';
368+
369+
const container = new EventSourcingDbContainer();
370+
await container.start();
371+
372+
const client = container.getClient();
373+
374+
// ...
375+
376+
await container.stop();
377+
```
378+
379+
To check if the test container is running, call the `isRunning` function:
380+
381+
```typescript
382+
const isRunning = container.isRunning();
383+
```
384+
385+
#### Configuring the Container Instance
386+
387+
By default, `EventSourcingDbContainer` uses the `latest` tag of the official EventSourcingDB Docker image. To change that, call the `withImageTag` function:
388+
389+
```typescript
390+
const container = new EventSourcingDbContainer()
391+
.withImageTag('1.0.0');
392+
```
393+
394+
Similarly, you can configure the port to use and the API token. Call the `withPort` or the `withApiToken` function respectively:
395+
396+
```typescript
397+
const container = new EventSourcingDbContainer()
398+
.withPort(4000)
399+
.withApiToken('secret');
400+
```
401+
402+
#### Configuring the Client Manually
403+
404+
In case you need to set up the client yourself, use the following functions to get details on the container:
405+
406+
- `getHost()` returns the host name.
407+
- `getMappedPort()` returns the port.
408+
- `getBaseUrl()` returns the full URL of the container.
409+
- `getApiToken()` returns the API token.

0 commit comments

Comments
 (0)