Files
wehub-resource-sync 70bf21e064
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
Handle Changesets / Handle Changesets (push) Has been cancelled
Semgrep OSS scan / semgrep-oss (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:11 +08:00

77 lines
2.7 KiB
TypeScript

import { mkdirSync, writeFileSync } from "node:fs";
import { beforeEach, describe, it } from "vitest";
import { isDockerfile } from "../../../src/config/validation";
import { runInTempDir } from "../../../src/test-helpers";
describe("isDockerfile", () => {
const dockerfile =
'FROM node:18\nWORKDIR /app\nCOPY . .\nRUN npm install\nCMD ["node", "index.js"]';
runInTempDir();
beforeEach(() => {
mkdirSync("./container-context");
writeFileSync("./container-context/Dockerfile", dockerfile);
});
it("should return true if given a valid dockerfile path", async ({
expect,
}) => {
expect(isDockerfile("./container-context/Dockerfile", undefined)).toBe(
true
);
});
it("should find a dockerfile relative to the wrangler config path", async ({
expect,
}) => {
expect(
isDockerfile("./Dockerfile", "./container-context/wrangler.json")
).toBe(true);
});
it("should return false if given a valid image registry path", async ({
expect,
}) => {
expect(isDockerfile("docker.io/httpd:1", undefined)).toBe(false);
});
it("should error if given a non existent dockerfile", async ({ expect }) => {
expect(() => isDockerfile("./FakeDockerfile", undefined))
.toThrowErrorMatchingInlineSnapshot(`
[Error: The image "./FakeDockerfile" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)]
`);
});
it("should error if given a directory instead of a dockerfile", async ({
expect,
}) => {
expect(() => isDockerfile("./container-context", undefined))
.toThrowErrorMatchingInlineSnapshot(`
[Error: ./container-context is a directory, you should specify a path to the Dockerfile]
`);
});
it("should error if image registry reference contains the protocol part", async ({
expect,
}) => {
expect(() =>
isDockerfile("http://registry.cloudflare.com/image:tag", undefined)
).toThrowErrorMatchingInlineSnapshot(`
[Error: The image "http://registry.cloudflare.com/image:tag" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
Image reference should not include the protocol part (e.g: docker.io/httpd:1, not https://docker.io/httpd:1)]
`);
});
it("should error if image registry reference does not contain a tag", async ({
expect,
}) => {
expect(() => isDockerfile("docker.io/httpd", undefined))
.toThrowErrorMatchingInlineSnapshot(`
[Error: The image "docker.io/httpd" does not appear to be a valid path to a Dockerfile, or a valid image registry path:
If this is an image registry path, it needs to include at least a tag ':' (e.g: docker.io/httpd:1)]
`);
});
});