Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Tests/CLITests/Subcommands/Containers/TestCLICreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ import Foundation
import Testing

class TestCLICreateCommand: CLITest {
private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

@Test func testCreateArgsPassthrough() throws {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
#expect(throws: Never.self, "expected container create to succeed") {
try doCreate(name: name, args: ["echo", "-n", "hello", "world"])
try doRemove(name: name)
Expand Down
6 changes: 5 additions & 1 deletion Tests/CLITests/Subcommands/Containers/TestCLIExec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ import Foundation
import Testing

class TestCLIExecCommand: CLITest {
private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

@Test func testCreateExecCommand() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doCreate(name: name)
defer {
try? doStop(name: name)
Expand Down
6 changes: 5 additions & 1 deletion Tests/CLITests/Subcommands/Containers/TestCLIRmRace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ class TestCLIRmRaceCondition: CLITest {
try doRemove(name: name, force: force)
}

private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

@Test func testStopRmRace() async throws {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()

do {
// Create and start a container in detached mode that runs indefinitely
Expand Down
14 changes: 11 additions & 3 deletions Tests/CLITests/Subcommands/Networks/TestCLINetwork.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ class TestCLINetwork: CLITest {
private static let retries = 10
private static let retryDelaySeconds = Int64(3)

private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

private func getLowercasedTestName() -> String {
getTestName().lowercased()
}

@available(macOS 26, *)
@Test func testNetworkCreateAndUse() async throws {
do {
let name = Test.current!.name.trimmingCharacters(in: ["(", ")"])
let name = getLowercasedTestName()
let networkDeleteArgs = ["network", "delete", name]
_ = try? run(arguments: networkDeleteArgs)

Expand Down Expand Up @@ -86,7 +94,7 @@ class TestCLINetwork: CLITest {
@Test func testNetworkDeleteWithContainer() async throws {
do {
// prep: delete container and network, ignoring if it doesn't exist
let name = Test.current!.name.trimmingCharacters(in: ["(", ")"])
let name = getLowercasedTestName()
try? doRemove(name: name)
let networkDeleteArgs = ["network", "delete", name]
_ = try? run(arguments: networkDeleteArgs)
Expand Down Expand Up @@ -133,7 +141,7 @@ class TestCLINetwork: CLITest {
@Test func testNetworkLabels() async throws {
do {
// prep: delete container and network, ignoring if it doesn't exist
let name = Test.current!.name.trimmingCharacters(in: ["(", ")"])
let name = getLowercasedTestName()
try? doRemove(name: name)
let networkDeleteArgs = ["network", "delete", name]
_ = try? run(arguments: networkDeleteArgs)
Expand Down
8 changes: 6 additions & 2 deletions Tests/CLITests/Subcommands/Run/TestCLIRunLifecycle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
import Testing

class TestCLIRunLifecycle: CLITest {
private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

@Test func testRunFailureCleanup() throws {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()

// try to create a container we know will fail
let badArgs: [String] = [
Expand All @@ -36,7 +40,7 @@ class TestCLIRunLifecycle: CLITest {
defer {
try? self.doStop(name: name)
}
let _ = try self.doExec(name: name!, cmd: ["date"])
let _ = try self.doExec(name: name, cmd: ["date"])
try self.doStop(name: name)
}
}
Expand Down
50 changes: 29 additions & 21 deletions Tests/CLITests/Subcommands/Run/TestCLIRunOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@ import Foundation
import Testing

class TestCLIRunCommand: CLITest {
private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

private func getLowercasedTestName() -> String {
getTestName().lowercased()
}

@Test func testRunCommand() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doLongRun(name: name, args: [])
defer {
try? doStop(name: name)
Expand All @@ -41,7 +49,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandCWD() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let expectedCWD = "/tmp"
try doLongRun(name: name, args: ["--cwd", expectedCWD])
defer {
Expand All @@ -59,7 +67,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandEnv() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let envData = "FOO=bar"
try doLongRun(name: name, args: ["--env", envData])
defer {
Expand All @@ -78,7 +86,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandEnvFile() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let envData = "FOO=bar"
let tempFile = FileManager.default.temporaryDirectory.appendingPathComponent("test.env")
guard FileManager.default.createFile(atPath: tempFile.path(), contents: Data(envData.utf8)) else {
Expand All @@ -105,7 +113,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandUserIDGroupID() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let uid = "10"
let gid = "100"
try doLongRun(name: name, args: ["--uid", uid, "--gid", gid])
Expand All @@ -125,7 +133,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandUser() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let user = "nobody"
try doLongRun(name: name, args: ["--user", user])
defer {
Expand All @@ -143,7 +151,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandCPUs() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let cpus = "2"
try doLongRun(name: name, args: ["--cpus", cpus])
defer {
Expand All @@ -161,7 +169,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandMemory() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let expectedMBs = 1024
try doLongRun(name: name, args: ["--memory", "\(expectedMBs)M"])
defer {
Expand All @@ -179,7 +187,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandMount() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let targetContainerPath = "/tmp/testmount"
let testData = "hello world"
let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
Expand Down Expand Up @@ -208,7 +216,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandUnixSocketMount() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let socketPath = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)

let socketType = try UnixType(path: socketPath.path, unlinkExisting: true)
Expand Down Expand Up @@ -242,7 +250,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandTmpfs() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let targetContainerPath = "/tmp/testtmpfs"
let expectedFilesystem = "tmpfs"
try doLongRun(name: name, args: ["--tmpfs", targetContainerPath])
Expand All @@ -264,7 +272,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandOSArch() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getLowercasedTestName()
let os = "linux"
let arch = "amd64"
let expectedArch = "x86_64"
Expand All @@ -284,7 +292,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandPlatform() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let os = "linux"
let platform = "linux/amd64"
let expectedArch = "x86_64"
Expand All @@ -304,7 +312,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandVolume() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let targetContainerPath = "/tmp/testvolume"
let testData = "one small step"
let volume = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
Expand Down Expand Up @@ -333,7 +341,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandCidfile() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
let filePath = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
defer {
try? FileManager.default.removeItem(at: filePath)
Expand All @@ -343,7 +351,7 @@ class TestCLIRunCommand: CLITest {
try? doStop(name: name)
}
let actualID = try String(contentsOf: filePath, encoding: .utf8)
#expect(actualID == name, "expected container ID '\(name!)', instead got '\(actualID)'")
#expect(actualID == name, "expected container ID '\(name)', instead got '\(actualID)'")
try doStop(name: name)
} catch {
Issue.record("failed to run container \(error)")
Expand All @@ -353,7 +361,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandNoDNS() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doLongRun(name: name, args: ["--no-dns"])
defer {
try? doStop(name: name)
Expand All @@ -369,7 +377,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunCommandDefaultResolvConf() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doLongRun(name: name, args: [])
defer {
try? doStop(name: name)
Expand Down Expand Up @@ -404,7 +412,7 @@ class TestCLIRunCommand: CLITest {
let expectedDomain = "example.com"
let expectedSearch = "test.com"
let expectedOption = "debug"
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doLongRun(
name: name,
args: [
Expand Down Expand Up @@ -438,7 +446,7 @@ class TestCLIRunCommand: CLITest {

@Test func testRunDefaultHostsEntries() throws {
do {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doLongRun(name: name)
defer {
try? doStop(name: name)
Expand Down Expand Up @@ -469,7 +477,7 @@ class TestCLIRunCommand: CLITest {
let retries = 10
let retryDelaySeconds = Int64(3)
do {
let name = Test.current!.name.trimmingCharacters(in: ["(", ")"])
let name = getLowercasedTestName()
let proxyIp = "127.0.0.1"
let proxyPort = UInt16.random(in: 50000..<55000)
let serverPort = UInt16.random(in: 55000..<60000)
Expand Down
6 changes: 5 additions & 1 deletion Tests/CLITests/Subcommands/System/TestKernelSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ class TestCLIKernelSet: CLITest {
}

func validateContainerRun() throws {
let name: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let name = getTestName()
try doLongRun(name: name, args: [])
defer { try? doStop(name: name) }

_ = try doExec(name: name, cmd: ["date"])
try doStop(name: name)
}

private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

@Test func fromLocalTar() async throws {
let symlinkBinaryPath: String = URL(filePath: defaultBinaryPath).deletingLastPathComponent().appending(path: "vmlinux.container").relativePath

Expand Down
36 changes: 20 additions & 16 deletions Tests/CLITests/Subcommands/Volumes/TestCLIVolumes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ class TestCLIVolumes: CLITest {
return status != 0
}

private func getTestName() -> String {
Test.current!.name.trimmingCharacters(in: ["(", ")"]).lowercased()
}

@Test func testVolumeDataPersistenceAcrossContainers() throws {
let testName: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let volumeName = "\(testName!)_vol"
let container1Name = "\(testName!)_c1"
let container2Name = "\(testName!)_c2"
let testName = getTestName()
let volumeName = "\(testName)_vol"
let container1Name = "\(testName)_c1"
let container2Name = "\(testName)_c2"
let testData = "persistent-data-test"
let testFile = "/data/test.txt"

Expand Down Expand Up @@ -102,10 +106,10 @@ class TestCLIVolumes: CLITest {
}

@Test func testVolumeSharedAccessConflict() throws {
let testName: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let volumeName = "\(testName!)_vol"
let container1Name = "\(testName!)_c1"
let container2Name = "\(testName!)_c2"
let testName = getTestName()
let volumeName = "\(testName)_vol"
let container1Name = "\(testName)_c1"
let container2Name = "\(testName)_c2"

// Clean up any existing resources from previous runs
doVolumeDeleteIfExists(name: volumeName)
Expand Down Expand Up @@ -140,9 +144,9 @@ class TestCLIVolumes: CLITest {
}

@Test func testVolumeDeleteProtectionWhileInUse() throws {
let testName: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let volumeName = "\(testName!)_vol"
let containerName = "\(testName!)_c1"
let testName = getTestName()
let volumeName = "\(testName)_vol"
let containerName = "\(testName)_c1"

// Clean up any existing resources from previous runs
doVolumeDeleteIfExists(name: volumeName)
Expand Down Expand Up @@ -175,9 +179,9 @@ class TestCLIVolumes: CLITest {
}

@Test func testVolumeDeleteProtectionWithCreatedContainer() async throws {
let testName: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let volumeName = "\(testName!)_vol"
let containerName = "\(testName!)_c1"
let testName = getTestName()
let volumeName = "\(testName)_vol"
let containerName = "\(testName)_c1"

// Clean up any existing resources from previous runs
doVolumeDeleteIfExists(name: volumeName)
Expand Down Expand Up @@ -211,8 +215,8 @@ class TestCLIVolumes: CLITest {
}

@Test func testVolumeBasicOperations() throws {
let testName: String! = Test.current?.name.trimmingCharacters(in: ["(", ")"])
let volumeName = "\(testName!)_vol"
let testName = getTestName()
let volumeName = "\(testName)_vol"

// Clean up any existing resources from previous runs
doVolumeDeleteIfExists(name: volumeName)
Expand Down