|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { rewriteImageRegistry } from "./imageRegistry.js"; |
| 3 | + |
| 4 | +const FROM = "123456789012.dkr.ecr.us-east-1.amazonaws.com"; |
| 5 | +const TO = "123456789012.dkr.ecr.eu-central-1.amazonaws.com"; |
| 6 | + |
| 7 | +describe("rewriteImageRegistry", () => { |
| 8 | + it("rewrites the registry host and keeps the rest of the reference", () => { |
| 9 | + expect(rewriteImageRegistry(`${FROM}/deployments/proj_abc:20260818.1`, FROM, TO)).toBe( |
| 10 | + `${TO}/deployments/proj_abc:20260818.1` |
| 11 | + ); |
| 12 | + }); |
| 13 | + |
| 14 | + it("preserves a digest", () => { |
| 15 | + expect(rewriteImageRegistry(`${FROM}/deployments/proj_abc@sha256:abc123`, FROM, TO)).toBe( |
| 16 | + `${TO}/deployments/proj_abc@sha256:abc123` |
| 17 | + ); |
| 18 | + }); |
| 19 | + |
| 20 | + it("is a no-op unless both ends are configured", () => { |
| 21 | + const ref = `${FROM}/deployments/proj_abc:tag`; |
| 22 | + |
| 23 | + expect(rewriteImageRegistry(ref, undefined, TO)).toBe(ref); |
| 24 | + expect(rewriteImageRegistry(ref, FROM, undefined)).toBe(ref); |
| 25 | + expect(rewriteImageRegistry(ref, undefined, undefined)).toBe(ref); |
| 26 | + }); |
| 27 | + |
| 28 | + it("leaves other registries alone", () => { |
| 29 | + const ref = "ghcr.io/triggerdotdev/something:tag"; |
| 30 | + expect(rewriteImageRegistry(ref, FROM, TO)).toBe(ref); |
| 31 | + }); |
| 32 | + |
| 33 | + it("only matches on a host boundary", () => { |
| 34 | + const lookalike = `${FROM}.evil.example.com/deployments/proj_abc:tag`; |
| 35 | + expect(rewriteImageRegistry(lookalike, FROM, TO)).toBe(lookalike); |
| 36 | + }); |
| 37 | + |
| 38 | + it("does not rewrite a host that merely contains the source", () => { |
| 39 | + const ref = `registry.example.com/${FROM}/proj_abc:tag`; |
| 40 | + expect(rewriteImageRegistry(ref, FROM, TO)).toBe(ref); |
| 41 | + }); |
| 42 | +}); |
0 commit comments