Skip to content

Commit be3b1f2

Browse files
authored
Migrate some container tests, remove concurrent demo tests. (apple#1840)
- Part of apple#1833. - Tweaks `ContainerFixture.withContainer()` to support the legacy `longRun()` pattern without boilerplate.
1 parent 649164d commit be3b1f2

11 files changed

Lines changed: 508 additions & 410 deletions

Makefile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,19 +200,32 @@ endef
200200
# the three phases. Expand the filter lists as suites are migrated from CLITests.
201201
PARALLEL_WIDTH ?= 2
202202
WARMUP_FILTER = ImageWarmup
203-
CONCURRENT_FILTER = DemoConcurrentTests
203+
204+
CONCURRENT_TEST_SUITES ?= \
205+
TestCLIStop \
206+
TestCLIRmRaceCondition \
207+
TestCLIExportCommand
208+
CONCURRENT_FILTER = $(subst $(space),|,$(strip $(CONCURRENT_TEST_SUITES)))
209+
204210
GLOBAL_FILTER = DemoGlobalTests
205211

206212
INTEGRATION_SWIFT_EXTRA ?=
207213
INTEGRATION_POST_TEST ?=
208214

215+
PRESERVE_KERNELS ?= false
216+
209217
define RUN_INTEGRATION
210218
@echo Ensuring apiserver stopped before the CLI integration tests...
211219
@bin/container system stop && sleep 3 && scripts/ensure-container-stopped.sh
212220
@if [ -n "$(APP_ROOT)" ]; then \
213-
echo "Clearing application data under $(APP_ROOT) (preserving kernels)..." ; \
214221
mkdir -p $(APP_ROOT) ; \
215-
find "$(APP_ROOT)" -mindepth 1 -maxdepth 1 ! -name kernels -exec rm -rf {} + ; \
222+
if [ "$(PRESERVE_KERNELS)" = "true" ]; then \
223+
echo "Clearing application data under $(APP_ROOT) (preserving kernels)..." ; \
224+
find "$(APP_ROOT)" -mindepth 1 -maxdepth 1 ! -name kernels -exec rm -rf {} + ; \
225+
else \
226+
echo "Clearing application data under $(APP_ROOT)..." ; \
227+
find "$(APP_ROOT)" -mindepth 1 -maxdepth 1 -exec rm -rf {} + ; \
228+
fi ; \
216229
fi
217230
@echo Running the integration tests...
218231
@bin/container --debug system start --timeout 60 --enable-kernel-install $(SYSTEM_START_OPTS) && \
@@ -263,7 +276,6 @@ INTEGRATION_TEST_SUITES ?= \
263276
TestCLIRunBase \
264277
TestCLIRunInitImage \
265278
TestCLIBuildBase \
266-
TestCLIExportCommand \
267279
TestCLIVolumes \
268280
TestCLIKernelSet \
269281
TestCLIAnonymousVolumes \

Package.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@ let package = Package(
8585
dependencies: [
8686
.product(name: "Logging", package: "swift-log"),
8787
.product(name: "SystemPackage", package: "swift-system"),
88+
.product(name: "ContainerizationArchive", package: "containerization"),
89+
.product(name: "ContainerizationExtras", package: "containerization"),
8890
"ContainerLog",
91+
"ContainerResource",
8992
"Yams",
9093
],
9194
path: "Tests/IntegrationTests"

Tests/CLITests/Subcommands/Containers/TestCLIExport.swift

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

Tests/CLITests/Subcommands/Containers/TestCLIRmRace.swift

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

Tests/CLITests/Subcommands/Containers/TestCLIStop.swift

Lines changed: 0 additions & 75 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 ContainerizationArchive
18+
import Foundation
19+
import Testing
20+
21+
@Suite
22+
struct TestCLIExportCommand {
23+
@Test func testExportCommand() async throws {
24+
try await ContainerFixture.with { f in
25+
let image = try f.copyWarmupImage(ContainerFixture.warmupImages[0])
26+
try await f.withContainer(image: image, autoRemove: false) { name in
27+
let mustBeInImage = "must-be-in-image"
28+
try f.doExec(name, cmd: ["sh", "-c", "echo \(mustBeInImage) > /foo"])
29+
try f.doExec(name, cmd: ["sh", "-c", "mkdir -p /parent/child"])
30+
let hardlinkMustRemain = "hardlink-must-remain"
31+
try f.doExec(name, cmd: ["sh", "-c", "echo \(hardlinkMustRemain) > /parent/child/bar"])
32+
try f.doExec(name, cmd: ["sh", "-c", "ln /parent/child/bar /bar"])
33+
let symlinkMustRemain = "symlink-must-remain"
34+
try f.doExec(name, cmd: ["sh", "-c", "echo \(symlinkMustRemain) > /parent/child/baz"])
35+
try f.doExec(name, cmd: ["sh", "-c", "ln /parent/child/baz /baz"])
36+
37+
try f.doStop(name)
38+
39+
let exportPath = f.testDir.appending("export.tar")
40+
try f.doExport(name, to: exportPath)
41+
42+
let exportURL = URL(filePath: exportPath.string)
43+
let attrs = try FileManager.default.attributesOfItem(atPath: exportPath.string)
44+
let fileSize = attrs[.size] as! UInt64
45+
#expect(fileSize > 0)
46+
47+
// TODO: verify foo bar baz are in tar file.
48+
let reader = try ArchiveReader(file: exportURL)
49+
let (foo, fooData) = try reader.extractFile(path: "/foo")
50+
#expect(foo.fileType == .regular)
51+
#expect(String(data: fooData, encoding: .utf8)?.starts(with: mustBeInImage) ?? false)
52+
}
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)