diff --git a/packages/testcontainers/src/container-runtime/image-name.test.ts b/packages/testcontainers/src/container-runtime/image-name.test.ts index 9710f75e..6c251959 100644 --- a/packages/testcontainers/src/container-runtime/image-name.test.ts +++ b/packages/testcontainers/src/container-runtime/image-name.test.ts @@ -54,10 +54,10 @@ describe("ContainerImage", () => { expect(imageName.string).toBe("aa285b773a2c042056883845aea893a743d358a5d40f61734fa228fde93dae6f:1"); }); - it("should substitute no registry with the one provided via TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", () => { + it.each(['custom.com/registry', 'custom.com/registry/'])("should substitute no registry with the one provided via TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX", (customRegistry: string) => { const oldEnvValue = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX; try { - process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = "custom.com/registry"; + process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = customRegistry; const imageName = new ImageName(undefined, "image", "tag"); expect(imageName.string).toBe("custom.com/registry/image:tag"); } finally { diff --git a/packages/testcontainers/src/container-runtime/image-name.ts b/packages/testcontainers/src/container-runtime/image-name.ts index 306e7b60..569a44e0 100644 --- a/packages/testcontainers/src/container-runtime/image-name.ts +++ b/packages/testcontainers/src/container-runtime/image-name.ts @@ -10,11 +10,9 @@ export class ImageName { public readonly image: string, public readonly tag: string ) { - if (!this.registry) { - this.registry = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX; - if (this.registry) { - log.info(`Applying changes to image ${image} with tag ${tag}: added registry ${this.registry}`); - } + if (!this.registry && process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX) { + this.registry = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX.replace(/\/$/, ""); + log.info(`Applying changes to image ${image} with tag ${tag}: added registry ${this.registry}`); } if (this.registry) { if (this.tag.startsWith("sha256:")) {