Skip to content

Commit a3318f5

Browse files
authored
Add test for cloudchamber buildAndMaybePush (cloudflare#9638)
Tests the code path where push flag is set but the image exists already in the remote so we do not want to push and instead want to untag the image.
1 parent 2be0d39 commit a3318f5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

packages/wrangler/src/__tests__/cloudchamber/build.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,50 @@ describe("buildAndMaybePush", () => {
119119
expect(dockerLoginManagedRegistry).toHaveBeenCalledOnce();
120120
});
121121

122+
it("should be able to build image and not push if it already exists in remote", async () => {
123+
vi.mocked(getDockerImageDigest).mockResolvedValue("three");
124+
vi.mocked(runDockerCmd).mockResolvedValueOnce();
125+
await runWrangler(
126+
"containers build ./container-context -t test-app:tag -p"
127+
);
128+
expect(dockerBuild).toHaveBeenCalledWith("docker", {
129+
buildCmd: [
130+
"build",
131+
"-t",
132+
`${getCloudflareContainerRegistry()}/test_account_id/test-app:tag`,
133+
"--platform",
134+
"linux/amd64",
135+
"--provenance=false",
136+
"-f",
137+
"-",
138+
"./container-context",
139+
],
140+
dockerfile,
141+
});
142+
expect(runDockerCmd).toHaveBeenCalledTimes(2);
143+
expect(runDockerCmd).toHaveBeenNthCalledWith(
144+
1,
145+
"docker",
146+
[
147+
"manifest",
148+
"inspect",
149+
`${getCloudflareContainerRegistry()}/test_account_id/test-app@three`,
150+
],
151+
"ignore"
152+
);
153+
expect(runDockerCmd).toHaveBeenNthCalledWith(2, "docker", [
154+
"image",
155+
"rm",
156+
`${getCloudflareContainerRegistry()}/test_account_id/test-app:tag`,
157+
]);
158+
expect(dockerImageInspect).toHaveBeenCalledOnce();
159+
expect(dockerImageInspect).toHaveBeenCalledWith("docker", {
160+
imageTag: `${getCloudflareContainerRegistry()}/test_account_id/test-app:tag`,
161+
formatString: "{{ .Size }} {{ len .RootFS.Layers }}",
162+
});
163+
expect(dockerLoginManagedRegistry).toHaveBeenCalledOnce();
164+
});
165+
122166
it("should be able to build image and not push", async () => {
123167
await runWrangler("containers build ./container-context -t test-app");
124168
expect(dockerBuild).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)