Skip to content

Commit 5991999

Browse files
committed
Correctly asserting up/down
1 parent b2bc1bc commit 5991999

File tree

2 files changed

+224
-218
lines changed

2 files changed

+224
-218
lines changed

Tests/Container-Compose-DynamicTests/ComposeDownTests.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,38 @@ struct ComposeDownTests {
2626

2727
@Test("What goes up must come down - container_name")
2828
func testUpAndDownContainerName() async throws {
29-
let yaml = DockerComposeYamlFiles.dockerComposeYaml1
29+
// Create a new temporary UUID to use as a container name, otherwise we might conflict with
30+
// existing containers on the system
31+
let containerName = UUID().uuidString
32+
33+
let yaml = DockerComposeYamlFiles.dockerComposeYaml9(containerName: containerName)
3034

3135
let tempLocation = URL.temporaryDirectory.appending(path: "Container-Compose_Tests_\(UUID().uuidString)/docker-compose.yaml")
3236
let tempBase = tempLocation.deletingLastPathComponent()
3337
try? FileManager.default.createDirectory(at: tempLocation.deletingLastPathComponent(), withIntermediateDirectories: true)
3438
try yaml.write(to: tempLocation, atomically: false, encoding: .utf8)
35-
let folderName = tempBase.lastPathComponent
3639

3740
var composeUp = try ComposeUp.parse(["-d", "--cwd", tempBase.path(percentEncoded: false)])
3841
try await composeUp.run()
39-
42+
4043
var containers = try await ClientContainer.list()
4144
.filter({
42-
$0.configuration.id.contains(folderName)
45+
$0.configuration.id.contains(containerName)
4346
})
4447

45-
#expect(containers.count == 1, "Expected 1 containers to be running, found \(containers.count)")
46-
//#expect(containers[0].configuration.names.contains("/custom_nginx"), "Expected container to have name /custom_nginx, found \(containers[0].configuration.names)")
48+
#expect(containers.count == 1, "Expected 1 container with the name \(containerName), found \(containers.count)")
49+
#expect(containers[0].status == .running, "Expected container \(containerName) to be running, found status: \(containers[0].status.rawValue)")
4750

4851
var composeDown = try ComposeDown.parse(["--cwd", tempBase.path(percentEncoded: false)])
4952
try await composeDown.run()
5053

5154
containers = try await ClientContainer.list()
5255
.filter({
53-
$0.configuration.id.contains(folderName)
56+
$0.configuration.id.contains(containerName)
5457
})
5558

56-
#expect(containers.count == 0, "Expected no containers to be running, found \(containers.count)")
59+
#expect(containers.count == 1, "Expected 1 container with the name \(containerName), found \(containers.count)")
60+
#expect(containers[0].status == .stopped, "Expected container \(containerName) to be stopped, found status: \(containers[0].status.rawValue)")
5761
}
5862

5963
}

0 commit comments

Comments
 (0)