Skip to content

Commit 586fa07

Browse files
authored
Migrate registry tests to new test support types. (#1845)
- Part of #1833.
1 parent d29e6ed commit 586fa07

10 files changed

Lines changed: 1727 additions & 129 deletions

Tests/CLITests/Subcommands/Images/TestCLIProgressAuto.swift

Lines changed: 0 additions & 70 deletions
This file was deleted.

Tests/CLITests/Subcommands/Registry/TestCLIRegistry.swift

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
//===----------------------------------------------------------------------===//
2+
// Copyright © 2026 Apple Inc. and the container project authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//===----------------------------------------------------------------------===//
16+
17+
import Foundation
18+
import Testing
19+
20+
@Suite(.serialized)
21+
struct TestCLIBuilderEnvOnlySerial {
22+
@Test func testBuildEnvironmentOnlyImageFromScratch() async throws {
23+
try await ContainerFixture.with { f in
24+
try await f.withBuilder { f in
25+
let dir = try f.createTempDir()
26+
let dockerfile =
27+
"""
28+
FROM scratch
29+
ARG BUILD_DATE
30+
ARG VERSION=1.0.0
31+
ENV TERM=xterm \\
32+
BUILD_DATE=${BUILD_DATE} \\
33+
APP_VERSION=${VERSION} \\
34+
PATH=/usr/local/bin:/usr/bin:/bin
35+
LABEL maintainer="test@example.com" version="${VERSION}"
36+
"""
37+
try f.createContext(dir: dir, dockerfile: dockerfile)
38+
let imageName = "test-env-only:\(UUID().uuidString)"
39+
try f.build(tag: imageName, contextDir: dir, buildArgs: ["BUILD_DATE=2025-01-01", "VERSION=2.0.0"])
40+
try f.assertImageBuilt(imageName)
41+
}
42+
}
43+
}
44+
45+
@Test func testBuildEnvironmentOnlyImageFromAlpine() async throws {
46+
try await ContainerFixture.with { f in
47+
try await f.withBuilder { f in
48+
let dir = try f.createTempDir()
49+
let dockerfile =
50+
"""
51+
FROM ghcr.io/linuxcontainers/alpine:3.20
52+
ENV APP_NAME=myapp APP_VERSION=1.0.0 APP_ENV=production
53+
LABEL maintainer="test@example.com" version="1.0.0"
54+
"""
55+
try f.createContext(dir: dir, dockerfile: dockerfile)
56+
let imageName = "test-alpine-env:\(UUID().uuidString)"
57+
try f.build(tag: imageName, contextDir: dir)
58+
try f.assertImageBuilt(imageName)
59+
}
60+
}
61+
}
62+
63+
@Test func testMultiStageBuildWithEnvOnlyBase() async throws {
64+
try await ContainerFixture.with { f in
65+
try await f.withBuilder { f in
66+
let baseDir = try f.createTempDir()
67+
let baseDockerfile =
68+
"""
69+
FROM scratch
70+
ARG JOBS=6
71+
ARG ARCH=amd64
72+
ENV MAKEOPTS="-j${JOBS}" ARCH="${ARCH}" PATH=/usr/local/bin:/usr/bin
73+
"""
74+
try f.createContext(dir: baseDir, dockerfile: baseDockerfile)
75+
let baseImageName = "test-env-base:\(UUID().uuidString)"
76+
try f.build(tag: baseImageName, contextDir: baseDir, buildArgs: ["JOBS=8", "ARCH=arm64"])
77+
try f.assertImageBuilt(baseImageName)
78+
79+
let downstreamDir = try f.createTempDir()
80+
let downstreamDockerfile =
81+
"""
82+
FROM \(baseImageName)
83+
LABEL test="env-inherited"
84+
"""
85+
try f.createContext(dir: downstreamDir, dockerfile: downstreamDockerfile)
86+
let downstreamImageName = "test-env-child:\(UUID().uuidString)"
87+
try f.build(tag: downstreamImageName, contextDir: downstreamDir)
88+
try f.assertImageBuilt(downstreamImageName)
89+
}
90+
}
91+
}
92+
93+
@Test func testComplexArgAndEnvCombinations() async throws {
94+
try await ContainerFixture.with { f in
95+
try await f.withBuilder { f in
96+
let dir = try f.createTempDir()
97+
let dockerfile =
98+
"""
99+
FROM scratch
100+
ARG JOBS=6
101+
ARG MAXLOAD=7.00
102+
ARG ARCH=amd64
103+
ARG PROFILE_PATH=23.0/split-usr/no-multilib
104+
ARG CHOST=x86_64-pc-linux-gnu
105+
ARG CFLAGS=-O2 -pipe
106+
ENV JOBS="${JOBS}" MAXLOAD="${MAXLOAD}" \\
107+
GENTOO_PROFILE="default/linux/${ARCH}/${PROFILE_PATH}" \\
108+
CHOST="${CHOST}" MAKEOPTS="-j${JOBS}" \\
109+
CFLAGS="${CFLAGS}" CXXFLAGS="${CFLAGS}"
110+
LABEL maintainer="test@example.com"
111+
"""
112+
try f.createContext(dir: dir, dockerfile: dockerfile)
113+
let imageName = "test-complex-env:\(UUID().uuidString)"
114+
try f.build(tag: imageName, contextDir: dir, buildArgs: ["JOBS=12", "ARCH=arm64"])
115+
try f.assertImageBuilt(imageName)
116+
}
117+
}
118+
}
119+
120+
@Test func testLabelOnlyDockerfile() async throws {
121+
try await ContainerFixture.with { f in
122+
try await f.withBuilder { f in
123+
let dir = try f.createTempDir()
124+
let dockerfile =
125+
"""
126+
FROM scratch
127+
LABEL maintainer="test@example.com" version="1.0.0" \\
128+
description="Test image with only labels" \\
129+
org.opencontainers.image.title="Test Image"
130+
"""
131+
try f.createContext(dir: dir, dockerfile: dockerfile)
132+
let imageName = "test-label-only:\(UUID().uuidString)"
133+
try f.build(tag: imageName, contextDir: dir)
134+
try f.assertImageBuilt(imageName)
135+
}
136+
}
137+
}
138+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===----------------------------------------------------------------------===//
2+
// Copyright © 2026 Apple Inc. and the container project authors.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// https://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//===----------------------------------------------------------------------===//
16+
17+
import Darwin
18+
import Foundation
19+
import Testing
20+
21+
/// Tests for `container builder start`, `stop`, and `delete` lifecycle commands.
22+
///
23+
/// These tests manage the builder manually — they do not use ``withBuilder``
24+
/// because they are specifically testing the lifecycle commands themselves.
25+
/// They acquire the shared builder lock via ``withBuilderLock`` to serialise
26+
/// correctly with tests that use ``withBuilder(_:)``.
27+
@Suite(.serialized)
28+
struct TestCLIBuilderLifecycleSerial {
29+
@Test func testBuilderStartStopCommand() async throws {
30+
try await ContainerFixture.with { f in
31+
try await f.withBuilderLock {
32+
f.addCleanup { try? f.builderDelete(force: true) }
33+
34+
try f.builderStart()
35+
try await f.waitForBuilderRunning()
36+
let status1 = try f.getContainerStatus("buildkit")
37+
#expect(status1 == "running", "buildkit container should be running")
38+
39+
try f.builderStop()
40+
let status2 = try f.getContainerStatus("buildkit")
41+
#expect(status2 == "stopped", "buildkit container should be stopped")
42+
}
43+
}
44+
}
45+
46+
@Test func testBuilderEnvironmentColors() async throws {
47+
try await ContainerFixture.with { f in
48+
try await f.withBuilderLock {
49+
let originalColors = ProcessInfo.processInfo.environment["BUILDKIT_COLORS"]
50+
let originalNoColor = ProcessInfo.processInfo.environment["NO_COLOR"]
51+
f.addCleanup {
52+
if let c = originalColors { setenv("BUILDKIT_COLORS", c, 1) } else { unsetenv("BUILDKIT_COLORS") }
53+
if let n = originalNoColor { setenv("NO_COLOR", n, 1) } else { unsetenv("NO_COLOR") }
54+
_ = try? f.builderDelete(force: true)
55+
}
56+
57+
_ = try? f.builderDelete(force: true)
58+
setenv("BUILDKIT_COLORS", "run=green:warning=yellow:error=red:cancel=cyan", 1)
59+
setenv("NO_COLOR", "true", 1)
60+
61+
try f.run(["builder", "start"]).check()
62+
try await f.waitForBuilderRunning()
63+
64+
let container = try f.inspectContainer("buildkit")
65+
let env = container.configuration.initProcess.environment
66+
#expect(
67+
env.contains("BUILDKIT_COLORS=run=green:warning=yellow:error=red:cancel=cyan"),
68+
"BUILDKIT_COLORS should be forwarded to the buildkit container")
69+
#expect(
70+
env.contains("NO_COLOR=true"),
71+
"NO_COLOR should be forwarded to the buildkit container")
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)