|
1 | | -import { mkdirSync, rmSync, writeFileSync } from "fs"; |
2 | | -import { isDockerfile } from "./../src/utils"; |
| 1 | +import { mkdirSync, writeFileSync } from "fs"; |
| 2 | +import { checkExposedPorts, isDockerfile } from "./../src/utils"; |
3 | 3 | import { runInTempDir } from "./helpers/run-in-tmp-dir"; |
4 | 4 |
|
5 | 5 | describe("isDockerfile", () => { |
@@ -60,3 +60,45 @@ describe("isDockerfile", () => { |
60 | 60 | `); |
61 | 61 | }); |
62 | 62 | }); |
| 63 | + |
| 64 | +let docketImageInspectResult = "0"; |
| 65 | + |
| 66 | +vi.mock("../src/inspect", async (importOriginal) => { |
| 67 | + const mod: object = await importOriginal(); |
| 68 | + return { |
| 69 | + ...mod, |
| 70 | + dockerImageInspect: () => docketImageInspectResult, |
| 71 | + }; |
| 72 | +}); |
| 73 | + |
| 74 | +describe("checkExposedPorts", () => { |
| 75 | + beforeEach(() => { |
| 76 | + docketImageInspectResult = "1"; |
| 77 | + }); |
| 78 | + |
| 79 | + it("should not error when some ports are exported", async () => { |
| 80 | + docketImageInspectResult = "1"; |
| 81 | + await expect( |
| 82 | + checkExposedPorts("./container-context/Dockerfile", { |
| 83 | + image: "", |
| 84 | + imageTag: "", |
| 85 | + class_name: "MyContainer", |
| 86 | + }) |
| 87 | + ).resolves.toBeUndefined(); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should error, with an appropriate message when no ports are exported", async () => { |
| 91 | + docketImageInspectResult = "0"; |
| 92 | + expect( |
| 93 | + checkExposedPorts("./container-context/Dockerfile", { |
| 94 | + image: "", |
| 95 | + imageTag: "", |
| 96 | + class_name: "MyContainer", |
| 97 | + }) |
| 98 | + ).rejects.toThrowErrorMatchingInlineSnapshot(` |
| 99 | + [Error: The container "MyContainer" does not expose any ports. In your Dockerfile, please expose any ports you intend to connect to. |
| 100 | + For additional information please see: https://developers.cloudflare.com/containers/local-dev/#exposing-ports. |
| 101 | + ] |
| 102 | + `); |
| 103 | + }); |
| 104 | +}); |
0 commit comments