Skip to content

Commit eb6be3b

Browse files
committed
test: cover container machine user mounts
1 parent 80b2847 commit eb6be3b

3 files changed

Lines changed: 63 additions & 0 deletions

File tree

Sources/ContainerTestSupport/ContainerFixture+MachineHelpers.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
// limitations under the License.
1515
//===----------------------------------------------------------------------===//
1616

17+
import ContainerPersistence
1718
import Foundation
1819
import Testing
1920

@@ -41,6 +42,7 @@ public struct MachineInspectOutput: Codable {
4142
public let cpus: Int
4243
public let memory: UInt64
4344
public let homeMount: String?
45+
public let mounts: [MachineConfig.Mount]
4446
public let diskSize: UInt64?
4547
public let ipAddress: String?
4648

Tests/IntegrationTests/Machine/TestCLIMachineCommand.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ struct TestCLIMachineCommand {
3333
}
3434
}
3535

36+
@Test func testCreateWithMounts() async throws {
37+
try await ContainerFixture.with { f in
38+
let name = "\(f.testID)-machine"
39+
f.addCleanup { f.cleanupMachine(name) }
40+
41+
let source = URL(fileURLWithPath: f.testDir.string).standardizedFileURL.path
42+
try f.doMachineCreate(
43+
name: name,
44+
image: machineImage,
45+
extraArgs: [
46+
"--mount", "\(source):/mnt/read-write:rw",
47+
"--mount", "\(source):/mnt/read-only:ro",
48+
])
49+
50+
let snapshot = try f.doMachineInspect(name: name)
51+
#expect(snapshot.mounts.count == 2)
52+
#expect(snapshot.mounts[0].source == source)
53+
#expect(snapshot.mounts[0].destination == "/mnt/read-write")
54+
#expect(snapshot.mounts[0].readOnly == false)
55+
#expect(snapshot.mounts[1].source == source)
56+
#expect(snapshot.mounts[1].destination == "/mnt/read-only")
57+
#expect(snapshot.mounts[1].readOnly == true)
58+
}
59+
}
60+
3661
@Test func testCreateRejectsDots() async throws {
3762
try await ContainerFixture.with { f in
3863
let result = try f.runMachine(["create", "--name", "my.bad.name", machineImage])

Tests/IntegrationTests/Machine/TestCLIMachineRuntimeSerial.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,42 @@ struct TestCLIMachineRuntimeSerial {
666666
}
667667
}
668668

669+
@Test func testUserMountsReadWriteAndReadOnly() async throws {
670+
try await ContainerFixture.with { f in
671+
let name = "\(f.testID)-machine"
672+
f.addCleanup { f.cleanupMachine(name) }
673+
674+
let readWriteSource = f.testDir.appending("read-write")
675+
let readOnlySource = f.testDir.appending("read-only")
676+
try FileManager.default.createDirectory(
677+
atPath: readWriteSource.string, withIntermediateDirectories: true)
678+
try FileManager.default.createDirectory(
679+
atPath: readOnlySource.string, withIntermediateDirectories: true)
680+
681+
try f.doMachineCreate(
682+
name: name,
683+
image: machineImage,
684+
extraArgs: [
685+
"--home-mount", "none",
686+
"--mount", "\(readWriteSource.string):/mnt/read-write:rw",
687+
"--mount", "\(readOnlySource.string):/mnt/read-only:ro",
688+
])
689+
try f.doMachineBoot(name: name)
690+
try await f.waitForMachineStatus(name, status: "running")
691+
692+
try f.doMachineRun(
693+
name: name, root: true,
694+
command: ["touch", "/mnt/read-write/from-guest"])
695+
#expect(FileManager.default.fileExists(atPath: readWriteSource.appending("from-guest").string))
696+
697+
let readOnlyWrite = try f.runMachine([
698+
"run", "--root", "-n", name, "touch", "/mnt/read-only/blocked",
699+
])
700+
#expect(readOnlyWrite.status != 0)
701+
#expect(!FileManager.default.fileExists(atPath: readOnlySource.appending("blocked").string))
702+
}
703+
}
704+
669705
@Test func testCreateAutoBoots() async throws {
670706
try await ContainerFixture.with { f in
671707
let name = "\(f.testID)-machine"

0 commit comments

Comments
 (0)