Skip to content

Commit

Permalink
Fixed parsing registry from env variable to work with trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
ilia-beliaev-miro committed Apr 3, 2024
1 parent e08b0a8 commit 6472201
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {

Check failure on line 57 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'custom.com/registry',·'custom.com/registry/'])("should·substitute·no·registry·with·the·one·provided·via·TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX",` with `"custom.com/registry",·"custom.com/registry/"])(⏎······"should·substitute·no·registry·with·the·one·provided·via·TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX",⏎·····`
const oldEnvValue = process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX;

Check failure on line 58 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
try {

Check failure on line 59 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = "custom.com/registry";
process.env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = customRegistry;

Check failure on line 60 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `··········`
const imageName = new ImageName(undefined, "image", "tag");

Check failure on line 61 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
expect(imageName.string).toBe("custom.com/registry/image:tag");

Check failure on line 62 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `········` with `··········`
} finally {

Check failure on line 63 in packages/testcontainers/src/container-runtime/image-name.test.ts

View workflow job for this annotation

GitHub Actions / lint

Insert `··`
Expand Down
8 changes: 3 additions & 5 deletions packages/testcontainers/src/container-runtime/image-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:")) {
Expand Down

0 comments on commit 6472201

Please sign in to comment.