Supported container runtimes

Etcd

qianmoQqianmoQ· 更新于 2026-10-19· 阅读 3 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

Etcd

Install

1
npm install @testcontainers/etcd --save-dev

Examples

These examples use the following libraries:

  • etcd3

    1
    npm install etcd3

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);
 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();

评论

登录后参与评论

正在加载评论…