Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 0c874f7

Browse files
Merge pull request #6 from jackgene/chore/fix-test-on-arm-image
Updated testStartingContainerAndRetrievingLogs() to work on Apple Silicon
2 parents e1393d0 + b5b1258 commit 0c874f7

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed

Tests/DockerClientTests/ContainerTests.swift

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ final class ContainerTests: XCTestCase {
1717
func testCreateContainers() throws {
1818
let image = try client.images.pullImage(byName: "hello-world", tag: "latest").wait()
1919
let container = try client.containers.createContainer(image: image).wait()
20-
20+
2121
XCTAssertEqual(container.command, "/hello")
2222
}
2323

@@ -26,7 +26,7 @@ final class ContainerTests: XCTestCase {
2626
let _ = try client.containers.createContainer(image: image).wait()
2727

2828
let containers = try client.containers.list(all: true).wait()
29-
29+
3030
XCTAssert(containers.count >= 1)
3131
}
3232

@@ -45,32 +45,54 @@ final class ContainerTests: XCTestCase {
4545
let container = try client.containers.createContainer(image: image).wait()
4646
try container.start(on: client).wait()
4747
let output = try container.logs(on: client).wait()
48-
49-
XCTAssertEqual(
50-
output,
51-
"""
52-
48+
// Depending on CPU architecture, step 2 of the log output may by:
49+
// 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
50+
// (amd64)
51+
// or
52+
// 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
53+
// (arm64v8)
54+
//
55+
// Just check the lines before and after this line
56+
let expectedOutputPrefix = """
57+
5358
Hello from Docker!
5459
This message shows that your installation appears to be working correctly.
55-
60+
5661
To generate this message, Docker took the following steps:
5762
1. The Docker client contacted the Docker daemon.
5863
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
59-
(amd64)
64+
"""
65+
let expectedOutputSuffix = """
6066
3. The Docker daemon created a new container from that image which runs the
6167
executable that produces the output you are currently reading.
6268
4. The Docker daemon streamed that output to the Docker client, which sent it
6369
to your terminal.
64-
70+
6571
To try something more ambitious, you can run an Ubuntu container with:
6672
$ docker run -it ubuntu bash
67-
73+
6874
Share images, automate workflows, and more with a free Docker ID:
6975
https://hub.docker.com/
70-
76+
7177
For more examples and ideas, visit:
7278
https://docs.docker.com/get-started/
73-
79+
80+
"""
81+
82+
XCTAssertTrue(
83+
output.hasPrefix(expectedOutputPrefix),
84+
"""
85+
"\(output)"
86+
did not start with
87+
"\(expectedOutputPrefix)"
88+
"""
89+
)
90+
XCTAssertTrue(
91+
output.hasSuffix(expectedOutputSuffix),
92+
"""
93+
"\(output)"
94+
did not end with
95+
"\(expectedOutputSuffix)"
7496
"""
7597
)
7698
}

0 commit comments

Comments
 (0)