Etcd
Install
| npm install @testcontainers/etcd --save-dev
|
Examples
These examples use the following libraries:
Choose an image from the container registry and substitute IMAGE
.
Read and write key-value pairs
1
2
3
4
5
6
7
8
9
10
11
12 | await using container = await new EtcdContainer(IMAGE).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);
|
Subscribe to key changes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 | await using container = await new EtcdContainer(IMAGE).start();
const client = new Etcd3({
hosts: container.getClientEndpoint(),
});
const key = "foo";
const value = "bar";
const watcher = await client.watch().key(key).create();
const subscriber = vi.fn();
watcher.on("put", subscriber);
await client.put(key).value(value);
await vi.waitFor(() => expect(subscriber).toHaveBeenCalled(), 1_000);
await watcher.cancel();
|