Skip to content

Commit 05211d1

Browse files
Isolate container lifecycle per test to avoid race conditions
Co-authored-by: Cristian Greco <cristianrgreco@gmail.com>
1 parent 2f40855 commit 05211d1

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

packages/modules/vault/src/vault-container.test.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
import vault from "node-vault";
22
import { getImage } from "../../../testcontainers/src/utils/test-helper";
3-
import { StartedVaultContainer, VaultContainer } from "./vault-container";
3+
import { VaultContainer } from "./vault-container";
44

55
const VAULT_TOKEN = "my-root-token";
66
const IMAGE = getImage(__dirname);
77

88
describe("VaultContainer", { timeout: 180_000 }, () => {
9-
let container: StartedVaultContainer;
10-
11-
afterEach(async () => {
12-
await container?.stop();
13-
});
14-
159
// inside_block:readWrite {
1610
it("should start Vault and allow reading/writing secrets", async () => {
17-
container = await new VaultContainer(IMAGE).withVaultToken(VAULT_TOKEN).start();
11+
const container = await new VaultContainer(IMAGE).withVaultToken(VAULT_TOKEN).start();
1812

1913
const client = vault({
2014
apiVersion: "v1",
@@ -34,12 +28,14 @@ describe("VaultContainer", { timeout: 180_000 }, () => {
3428

3529
expect(data.message).toBe("world");
3630
expect(data.other).toBe("vault");
31+
32+
await container.stop();
3733
});
3834
// }
3935

4036
// inside_block:initCommands {
4137
it("should execute init commands using vault CLI", async () => {
42-
container = await new VaultContainer(IMAGE)
38+
const container = await new VaultContainer(IMAGE)
4339
.withVaultToken(VAULT_TOKEN)
4440
.withInitCommands("secrets enable transit", "write -f transit/keys/my-key")
4541
.start();
@@ -48,6 +44,8 @@ describe("VaultContainer", { timeout: 180_000 }, () => {
4844

4945
expect(result.exitCode).toBe(0);
5046
expect(result.output).toContain("my-key");
47+
48+
await container.stop();
5149
});
5250
// }
5351
});

0 commit comments

Comments
 (0)