Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions docs/modules/etcd.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Etcd Module

[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.

## Install

```bash
npm install @testcontainers/etcd --save-dev
```

## Examples

<!--codeinclude-->
[Read and write key-value pairs:](../../packages/modules/etcd/src/etcd-container.test.ts) inside_block:readWrite
<!--/codeinclude-->

<!--codeinclude-->
[Subscribe to key changes:](../../packages/modules/etcd/src/etcd-container.test.ts) inside_block:subscribe
<!--/codeinclude-->
17 changes: 9 additions & 8 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
site_name: Testcontainers for NodeJS
site_url: https://node.testcontainers.org
repo_name: 'testcontainers-node'
repo_url: 'https://github.com/testcontainers/testcontainers-node'
repo_name: "testcontainers-node"
repo_url: "https://github.com/testcontainers/testcontainers-node"
edit_uri: edit/main/docs/

theme:
name: 'material'
custom_dir: 'docs/site/theme'
name: "material"
custom_dir: "docs/site/theme"
palette:
scheme: testcontainers
font:
text: Roboto
code: Roboto Mono
logo: 'site/logo.svg'
favicon: 'site/favicon.ico'
logo: "site/logo.svg"
favicon: "site/favicon.ico"

extra_css:
- 'site/css/extra.css'
- 'site/css/tc-header.css'
- "site/css/extra.css"
- "site/css/tc-header.css"

plugins:
- search
Expand Down Expand Up @@ -56,6 +56,7 @@ nav:
- Couchbase: modules/couchbase.md
- CockroachDB: modules/cockroachdb.md
- Elasticsearch: modules/elasticsearch.md
- Etcd: modules/etcd.md
- EventStoreDB: modules/eventstoredb.md
- GCloud: modules/gcloud.md
- HiveMQ: modules/hivemq.md
Expand Down
41 changes: 41 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions packages/modules/etcd/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "@testcontainers/etcd",
"version": "10.21.0",
"license": "MIT",
"keywords": [
"etcd",
"etcd3",
"testing",
"docker",
"testcontainers"
],
"description": "Etcd module for Testcontainers",
"homepage": "https://github.com/testcontainers/testcontainers-node#readme",
"repository": {
"type": "git",
"url": "https://github.com/testcontainers/testcontainers-node"
},
"bugs": {
"url": "https://github.com/testcontainers/testcontainers-node/issues"
},
"main": "build/index.js",
"files": [
"build"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"prepack": "shx cp ../../../README.md . && shx cp ../../../LICENSE .",
"build": "tsc --project tsconfig.build.json"
},
"devDependencies": {
"etcd3": "^1.1.2"
},
"dependencies": {
"testcontainers": "^10.26.0"
}
}
47 changes: 47 additions & 0 deletions packages/modules/etcd/src/etcd-container.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Etcd3 } from "etcd3";
import { setTimeout } from "node:timers/promises";
import { EtcdContainer, StartedEtcdContainer } from "./etcd-container";

describe("etcd", () => {
it("should construct a container", { timeout: 30_000 }, async () => {
const container = await new EtcdContainer().start();
expect(container).toBeInstanceOf(StartedEtcdContainer);
container.stop();
});

// readWrite {
it("should connect and perform read/write operations", async () => {
const container = await new EtcdContainer().start();
const client = new Etcd3({
hosts: container.getClientEndpoint(),
});
const key = "foo";
const value = "bar";

await client.put(key).value(value);
const result = await client.get(key).string();
expect(result).toEqual(value);

await container.stop();
});
// }

// subscribe {
it("should subscribe to key changes", async () => {
const subscriber = vi.fn();
const container = await new EtcdContainer().start();
const client = new Etcd3({
hosts: container.getClientEndpoint(),
});
const key = "foo";
const value = "bar";
const watcher = await client.watch().key(key).create();
watcher.on("put", subscriber);
await client.put(key).value(value);
await setTimeout(1_000);
expect(subscriber).toHaveBeenCalled();
await watcher.cancel();
await container.stop();
});
// }
});
47 changes: 47 additions & 0 deletions packages/modules/etcd/src/etcd-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { AbstractStartedContainer, GenericContainer, Wait } from "testcontainers";

const ETCD_CLIENT_PORT = 2379;
const ETCD_PEER_PORT = 2380;

export class EtcdContainer extends GenericContainer {
constructor(image = "quay.io/coreos/etcd:v3.6.0", nodeName = "etcd-test") {
super(image);
this.withExposedPorts(ETCD_CLIENT_PORT, ETCD_PEER_PORT)
.withCommand([
"etcd",
"--name",
nodeName,
"--initial-advertise-peer-urls",
`http://0.0.0.0:${ETCD_PEER_PORT}`,
"--advertise-client-urls",
`http://0.0.0.0:${ETCD_CLIENT_PORT}`,
"--listen-peer-urls",
`http://0.0.0.0:${ETCD_PEER_PORT}`,
"--listen-client-urls",
`http://0.0.0.0:${ETCD_CLIENT_PORT}`,
])
.withWaitStrategy(Wait.forLogMessage(/"status":"SERVING"/));
}

public override async start(): Promise<StartedEtcdContainer> {
return new StartedEtcdContainer(await super.start());
}
}

export class StartedEtcdContainer extends AbstractStartedContainer {
public getClientPort(): number {
return this.startedTestContainer.getMappedPort(ETCD_CLIENT_PORT);
}

public getPeerPort(): number {
return this.startedTestContainer.getMappedPort(ETCD_PEER_PORT);
}

public getClientEndpoint(): string {
return `http://${this.getHost()}:${this.getClientPort()}`;
}

public getPeerEndpoint(): string {
return `http://${this.getHost()}:${this.getPeerPort()}`;
}
}
Empty file.
12 changes: 12 additions & 0 deletions packages/modules/etcd/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"exclude": [
"build",
"src/**/*.test.ts"
],
"references": [
{
"path": "../../testcontainers"
}
]
}
20 changes: 20 additions & 0 deletions packages/modules/etcd/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"paths": {
"testcontainers": [
"../../testcontainers/src"
]
}
},
"exclude": [
"build"
],
"references": [
{
"path": "../../testcontainers"
}
]
}