|
| 1 | +import { beforeEach, describe, it, vi } from "vitest"; |
| 2 | +import { |
| 3 | + getEgressInterceptorPlatform, |
| 4 | + pullEgressInterceptorImage, |
| 5 | +} from "../src/images"; |
| 6 | +import { runDockerCmd } from "../src/utils"; |
| 7 | + |
| 8 | +vi.mock("../src/utils", () => ({ |
| 9 | + runDockerCmd: vi.fn(() => ({ |
| 10 | + abort: vi.fn(), |
| 11 | + ready: Promise.resolve({ aborted: false }), |
| 12 | + then: (resolve: () => void) => { |
| 13 | + resolve(); |
| 14 | + }, |
| 15 | + })), |
| 16 | +})); |
| 17 | + |
| 18 | +describe("getEgressInterceptorPlatform", () => { |
| 19 | + beforeEach(() => { |
| 20 | + vi.unstubAllEnvs(); |
| 21 | + }); |
| 22 | + |
| 23 | + it("does not force a platform by default", ({ expect }) => { |
| 24 | + expect(getEgressInterceptorPlatform()).toBeUndefined(); |
| 25 | + }); |
| 26 | + |
| 27 | + it("allows overriding the platform", ({ expect }) => { |
| 28 | + vi.stubEnv("MINIFLARE_CONTAINER_EGRESS_IMAGE_PLATFORM", "linux/s390x"); |
| 29 | + |
| 30 | + expect(getEgressInterceptorPlatform()).toBe("linux/s390x"); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe("pullEgressInterceptorImage", () => { |
| 35 | + beforeEach(() => { |
| 36 | + vi.unstubAllEnvs(); |
| 37 | + vi.mocked(runDockerCmd).mockClear(); |
| 38 | + }); |
| 39 | + |
| 40 | + it("pulls the egress interceptor image without forcing a platform by default", async ({ |
| 41 | + expect, |
| 42 | + }) => { |
| 43 | + vi.stubEnv("MINIFLARE_CONTAINER_EGRESS_IMAGE", "proxy-everything:test"); |
| 44 | + |
| 45 | + await pullEgressInterceptorImage("docker"); |
| 46 | + |
| 47 | + expect(runDockerCmd).toHaveBeenCalledWith("docker", [ |
| 48 | + "pull", |
| 49 | + "proxy-everything:test", |
| 50 | + ]); |
| 51 | + }); |
| 52 | + |
| 53 | + it("pulls the egress interceptor image for the configured platform", async ({ |
| 54 | + expect, |
| 55 | + }) => { |
| 56 | + vi.stubEnv("MINIFLARE_CONTAINER_EGRESS_IMAGE", "proxy-everything:test"); |
| 57 | + vi.stubEnv("MINIFLARE_CONTAINER_EGRESS_IMAGE_PLATFORM", "linux/arm64"); |
| 58 | + |
| 59 | + await pullEgressInterceptorImage("docker"); |
| 60 | + |
| 61 | + expect(runDockerCmd).toHaveBeenCalledWith("docker", [ |
| 62 | + "pull", |
| 63 | + "proxy-everything:test", |
| 64 | + "--platform", |
| 65 | + "linux/arm64", |
| 66 | + ]); |
| 67 | + }); |
| 68 | +}); |
0 commit comments