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
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ describe("get auth config", () => {
});

afterEach(() => {
delete process.env.DOCKER_AUTH_CONFIG;
vi.resetModules();
});

it("should use DOCKER_AUTH_CONFIG environment variable as Docker config", async () => {
process.env.DOCKER_AUTH_CONFIG = JSON.stringify({
auths: {
"https://registry.example.com": {
email: "[email protected]",
username: "user",
password: "pass",
vi.stubEnv(
"DOCKER_AUTH_CONFIG",
JSON.stringify({
auths: {
"https://registry.example.com": {
email: "[email protected]",
username: "user",
password: "pass",
},
},
},
});
})
);
const { getAuthConfig } = await import("./get-auth-config");
expect(await getAuthConfig("https://registry.example.com")).toEqual({
username: "user",
Expand Down
33 changes: 7 additions & 26 deletions packages/testcontainers/src/container-runtime/image-name.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,12 @@ describe("ContainerImage", () => {
it.each(["custom.com/registry", "custom.com/registry/"])(
"should substitute no registry with the one provided via TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX when provided registry is %s",
(customRegistry: string) => {
const oldEnvValue = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX;
try {
process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = customRegistry;
const imageName = new ImageName(undefined, "image", "tag");
expect(imageName.registry).toBe("custom.com");
expect(imageName.image).toBe("registry/image");
expect(imageName.tag).toBe("tag");
expect(imageName.string).toBe("custom.com/registry/image:tag");
} finally {
if (oldEnvValue === undefined) {
delete process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX;
} else {
process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = oldEnvValue;
}
}
vi.stubEnv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", customRegistry);
const imageName = new ImageName(undefined, "image", "tag");
expect(imageName.registry).toBe("custom.com");
expect(imageName.image).toBe("registry/image");
expect(imageName.tag).toBe("tag");
expect(imageName.string).toBe("custom.com/registry/image:tag");
}
);
});
Expand Down Expand Up @@ -176,18 +167,8 @@ describe("ContainerImage", () => {
])(
"fromString with TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX set to $customRegistry",
({ customRegistry, expectedRegistry, expectedImagePrefix }) => {
let oldEnvValue: string | undefined;
beforeEach(() => {
oldEnvValue = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX;
process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = customRegistry;
});

afterEach(() => {
if (oldEnvValue === undefined) {
delete process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX;
} else {
process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = oldEnvValue;
}
vi.stubEnv("TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", customRegistry);
});

it("should work", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import { checkContainerIsHealthy } from "../utils/test-helper";
import { GenericContainer } from "./generic-container";

describe("GenericContainer reuse", { timeout: 180_000 }, () => {
afterEach(() => {
process.env.TESTCONTAINERS_REUSE_ENABLE = undefined;
});

it("should not reuse the container by default", async () => {
const name = `there_can_only_be_one_${randomUuid()}`;
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
Expand Down Expand Up @@ -64,7 +60,7 @@ describe("GenericContainer reuse", { timeout: 180_000 }, () => {
});

it("should not reuse the container when TESTCONTAINERS_REUSE_ENABLE is set to false", async () => {
process.env.TESTCONTAINERS_REUSE_ENABLE = "false";
vi.stubEnv("TESTCONTAINERS_REUSE_ENABLE", "false");

const name = `there_can_only_be_one_${randomUuid()}`;
const container = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
Expand All @@ -90,7 +86,7 @@ describe("GenericContainer reuse", { timeout: 180_000 }, () => {
it.each(["true", undefined])(
"should reuse the container when TESTCONTAINERS_REUSE_ENABLE is set to %s",
async (reuseEnable: string | undefined) => {
process.env.TESTCONTAINERS_REUSE_ENABLE = reuseEnable;
vi.stubEnv("TESTCONTAINERS_REUSE_ENABLE", reuseEnable);

const name = `there_can_only_be_one_${randomUuid()}`;
const container1 = await new GenericContainer("cristianrgreco/testcontainer:1.1.14")
Expand Down
4 changes: 1 addition & 3 deletions packages/testcontainers/src/reaper/reaper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ describe("Reaper", { timeout: 120_000 }, () => {

beforeEach(async () => {
vi.resetModules();
vitest.unstubAllEnvs();

client = await getContainerRuntimeClient();
});

Expand All @@ -23,7 +21,7 @@ describe("Reaper", { timeout: 120_000 }, () => {
});

it("should propagate TESTCONTAINERS_RYUK_VERBOSE into Reaper container", async () => {
vitest.stubEnv("TESTCONTAINERS_RYUK_VERBOSE", "true");
vi.stubEnv("TESTCONTAINERS_RYUK_VERBOSE", "true");

vi.spyOn(client.container, "list").mockResolvedValue([]);
const reaper = await getReaper();
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default defineConfig({
silent: "passed-only",
mockReset: true,
restoreMocks: true,
unstubEnvs: true,
alias: {
testcontainers: path.resolve(__dirname, "packages/testcontainers/src"),
},
Expand Down