Skip to content

Commit 87a8177

Browse files
committed
tests: Convert smoke tests
1 parent 7ff552f commit 87a8177

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

Tests/ContainerRegistryTests/SmokeTests.swift

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,23 @@
1414

1515
import Foundation
1616
import ContainerRegistry
17-
import XCTest
17+
import Testing
1818

19-
class SmokeTests: XCTestCase, @unchecked Sendable {
19+
struct SmokeTests {
2020
// These are basic tests to exercise the main registry operations.
2121
// The tests assume that a fresh, empty registry instance is available at
2222
// http://$REGISTRY_HOST:$REGISTRY_PORT
2323

24-
var client: RegistryClient!
24+
var client: RegistryClient
2525
let registryHost = ProcessInfo.processInfo.environment["REGISTRY_HOST"] ?? "localhost"
2626
let registryPort = ProcessInfo.processInfo.environment["REGISTRY_PORT"] ?? "5000"
2727

2828
/// Registry client fixture created for each test
29-
override func setUp() async throws {
30-
try await super.setUp()
29+
init() async throws {
3130
client = try await RegistryClient(registry: "\(registryHost):\(registryPort)", insecure: true)
3231
}
3332

34-
func testGetTags() async throws {
33+
@Test func testGetTags() async throws {
3534
let repository = "testgettags"
3635

3736
// registry:2 does not validate the contents of the config or image blobs
@@ -45,7 +44,7 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
4544
// Initially there will be no tags
4645
do {
4746
_ = try await client.getTags(repository: repository)
48-
XCTFail("Getting tags for an untagged blob should have thrown an error")
47+
Issue.record("Getting tags for an untagged blob should have thrown an error")
4948
} catch {
5049
// Expect to receive an error
5150
}
@@ -61,7 +60,7 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
6160
// After setting a tag, we should be able to retrieve it
6261
let _ = try await client.putManifest(repository: repository, reference: "latest", manifest: test_manifest)
6362
let firstTag = try await client.getTags(repository: repository).tags.sorted()
64-
XCTAssertEqual(firstTag, ["latest"])
63+
#expect(firstTag == ["latest"])
6564

6665
// After setting another tag, the original tag should still exist
6766
let _ = try await client.putManifest(
@@ -70,47 +69,47 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
7069
manifest: test_manifest
7170
)
7271
let secondTag = try await client.getTags(repository: repository)
73-
XCTAssertEqual(secondTag.tags.sorted(), ["additional_tag", "latest"].sorted())
72+
#expect(secondTag.tags.sorted() == ["additional_tag", "latest"].sorted())
7473
}
7574

76-
func testGetNonexistentBlob() async throws {
75+
@Test func testGetNonexistentBlob() async throws {
7776
let repository = "testgetnonexistentblob"
7877

7978
do {
8079
let _ = try await client.getBlob(
8180
repository: repository,
8281
digest: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
8382
)
84-
XCTFail("should have thrown")
83+
Issue.record("should have thrown")
8584
} catch {}
8685
}
8786

88-
func testCheckNonexistentBlob() async throws {
87+
@Test func testCheckNonexistentBlob() async throws {
8988
let repository = "testchecknonexistentblob"
9089

9190
let exists = try await client.blobExists(
9291
repository: repository,
9392
digest: "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
9493
)
95-
XCTAssertFalse(exists)
94+
#expect(!exists)
9695
}
9796

98-
func testPutAndGetBlob() async throws {
97+
@Test func testPutAndGetBlob() async throws {
9998
let repository = "testputandgetblob" // repository name must be lowercase
10099

101100
let blob_data = "test".data(using: .utf8)!
102101

103102
let descriptor = try await client.putBlob(repository: repository, data: blob_data)
104-
XCTAssertEqual(descriptor.digest, "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")
103+
#expect(descriptor.digest == "sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")
105104

106105
let exists = try await client.blobExists(repository: repository, digest: descriptor.digest)
107-
XCTAssertTrue(exists)
106+
#expect(exists)
108107

109108
let blob = try await client.getBlob(repository: repository, digest: descriptor.digest)
110-
XCTAssertEqual(blob, blob_data)
109+
#expect(blob == blob_data)
111110
}
112111

113-
func testPutAndGetTaggedManifest() async throws {
112+
@Test func testPutAndGetTaggedManifest() async throws {
114113
let repository = "testputandgettaggedmanifest" // repository name must be lowercase
115114

116115
// registry:2 does not validate the contents of the config or image blobs
@@ -139,13 +138,13 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
139138
let _ = try await client.putManifest(repository: repository, reference: "latest", manifest: test_manifest)
140139

141140
let manifest = try await client.getManifest(repository: repository, reference: "latest")
142-
XCTAssertEqual(manifest.schemaVersion, 2)
143-
XCTAssertEqual(manifest.config.mediaType, "application/vnd.docker.container.image.v1+json")
144-
XCTAssertEqual(manifest.layers.count, 1)
145-
XCTAssertEqual(manifest.layers[0].mediaType, "application/vnd.docker.image.rootfs.diff.tar.gzip")
141+
#expect(manifest.schemaVersion == 2)
142+
#expect(manifest.config.mediaType == "application/vnd.docker.container.image.v1+json")
143+
#expect(manifest.layers.count == 1)
144+
#expect(manifest.layers[0].mediaType == "application/vnd.docker.image.rootfs.diff.tar.gzip")
146145
}
147146

148-
func testPutAndGetAnonymousManifest() async throws {
147+
@Test func testPutAndGetAnonymousManifest() async throws {
149148
let repository = "testputandgetanonymousmanifest" // repository name must be lowercase
150149

151150
// registry:2 does not validate the contents of the config or image blobs
@@ -178,13 +177,13 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
178177
)
179178

180179
let manifest = try await client.getManifest(repository: repository, reference: test_manifest.digest)
181-
XCTAssertEqual(manifest.schemaVersion, 2)
182-
XCTAssertEqual(manifest.config.mediaType, "application/vnd.docker.container.image.v1+json")
183-
XCTAssertEqual(manifest.layers.count, 1)
184-
XCTAssertEqual(manifest.layers[0].mediaType, "application/vnd.docker.image.rootfs.diff.tar.gzip")
180+
#expect(manifest.schemaVersion == 2)
181+
#expect(manifest.config.mediaType == "application/vnd.docker.container.image.v1+json")
182+
#expect(manifest.layers.count == 1)
183+
#expect(manifest.layers[0].mediaType == "application/vnd.docker.image.rootfs.diff.tar.gzip")
185184
}
186185

187-
func testPutAndGetImageConfiguration() async throws {
186+
@Test func testPutAndGetImageConfiguration() async throws {
188187
let repository = "testputandgetimageconfiguration" // repository name must be lowercase
189188

190189
let configuration = ImageConfiguration(
@@ -205,6 +204,6 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
205204
digest: config_descriptor.digest
206205
)
207206

208-
XCTAssertEqual(configuration, downloaded)
207+
#expect(configuration == downloaded)
209208
}
210209
}

0 commit comments

Comments
 (0)