14
14
15
15
import Foundation
16
16
import ContainerRegistry
17
- import XCTest
17
+ import Testing
18
18
19
- class SmokeTests : XCTestCase , @ unchecked Sendable {
19
+ struct SmokeTests {
20
20
// These are basic tests to exercise the main registry operations.
21
21
// The tests assume that a fresh, empty registry instance is available at
22
22
// http://$REGISTRY_HOST:$REGISTRY_PORT
23
23
24
- var client : RegistryClient !
24
+ var client : RegistryClient
25
25
let registryHost = ProcessInfo . processInfo. environment [ " REGISTRY_HOST " ] ?? " localhost "
26
26
let registryPort = ProcessInfo . processInfo. environment [ " REGISTRY_PORT " ] ?? " 5000 "
27
27
28
28
/// Registry client fixture created for each test
29
- override func setUp( ) async throws {
30
- try await super. setUp ( )
29
+ init ( ) async throws {
31
30
client = try await RegistryClient ( registry: " \( registryHost) : \( registryPort) " , insecure: true )
32
31
}
33
32
34
- func testGetTags( ) async throws {
33
+ @ Test func testGetTags( ) async throws {
35
34
let repository = " testgettags "
36
35
37
36
// registry:2 does not validate the contents of the config or image blobs
@@ -45,7 +44,7 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
45
44
// Initially there will be no tags
46
45
do {
47
46
_ = 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 " )
49
48
} catch {
50
49
// Expect to receive an error
51
50
}
@@ -61,7 +60,7 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
61
60
// After setting a tag, we should be able to retrieve it
62
61
let _ = try await client. putManifest ( repository: repository, reference: " latest " , manifest: test_manifest)
63
62
let firstTag = try await client. getTags ( repository: repository) . tags. sorted ( )
64
- XCTAssertEqual ( firstTag, [ " latest " ] )
63
+ #expect ( firstTag == [ " latest " ] )
65
64
66
65
// After setting another tag, the original tag should still exist
67
66
let _ = try await client. putManifest (
@@ -70,47 +69,47 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
70
69
manifest: test_manifest
71
70
)
72
71
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 ( ) )
74
73
}
75
74
76
- func testGetNonexistentBlob( ) async throws {
75
+ @ Test func testGetNonexistentBlob( ) async throws {
77
76
let repository = " testgetnonexistentblob "
78
77
79
78
do {
80
79
let _ = try await client. getBlob (
81
80
repository: repository,
82
81
digest: " sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
83
82
)
84
- XCTFail ( " should have thrown " )
83
+ Issue . record ( " should have thrown " )
85
84
} catch { }
86
85
}
87
86
88
- func testCheckNonexistentBlob( ) async throws {
87
+ @ Test func testCheckNonexistentBlob( ) async throws {
89
88
let repository = " testchecknonexistentblob "
90
89
91
90
let exists = try await client. blobExists (
92
91
repository: repository,
93
92
digest: " sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa "
94
93
)
95
- XCTAssertFalse ( exists)
94
+ #expect ( ! exists)
96
95
}
97
96
98
- func testPutAndGetBlob( ) async throws {
97
+ @ Test func testPutAndGetBlob( ) async throws {
99
98
let repository = " testputandgetblob " // repository name must be lowercase
100
99
101
100
let blob_data = " test " . data ( using: . utf8) !
102
101
103
102
let descriptor = try await client. putBlob ( repository: repository, data: blob_data)
104
- XCTAssertEqual ( descriptor. digest, " sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 " )
103
+ #expect ( descriptor. digest == " sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08 " )
105
104
106
105
let exists = try await client. blobExists ( repository: repository, digest: descriptor. digest)
107
- XCTAssertTrue ( exists)
106
+ #expect ( exists)
108
107
109
108
let blob = try await client. getBlob ( repository: repository, digest: descriptor. digest)
110
- XCTAssertEqual ( blob, blob_data)
109
+ #expect ( blob == blob_data)
111
110
}
112
111
113
- func testPutAndGetTaggedManifest( ) async throws {
112
+ @ Test func testPutAndGetTaggedManifest( ) async throws {
114
113
let repository = " testputandgettaggedmanifest " // repository name must be lowercase
115
114
116
115
// registry:2 does not validate the contents of the config or image blobs
@@ -139,13 +138,13 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
139
138
let _ = try await client. putManifest ( repository: repository, reference: " latest " , manifest: test_manifest)
140
139
141
140
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 " )
146
145
}
147
146
148
- func testPutAndGetAnonymousManifest( ) async throws {
147
+ @ Test func testPutAndGetAnonymousManifest( ) async throws {
149
148
let repository = " testputandgetanonymousmanifest " // repository name must be lowercase
150
149
151
150
// registry:2 does not validate the contents of the config or image blobs
@@ -178,13 +177,13 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
178
177
)
179
178
180
179
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 " )
185
184
}
186
185
187
- func testPutAndGetImageConfiguration( ) async throws {
186
+ @ Test func testPutAndGetImageConfiguration( ) async throws {
188
187
let repository = " testputandgetimageconfiguration " // repository name must be lowercase
189
188
190
189
let configuration = ImageConfiguration (
@@ -205,6 +204,6 @@ class SmokeTests: XCTestCase, @unchecked Sendable {
205
204
digest: config_descriptor. digest
206
205
)
207
206
208
- XCTAssertEqual ( configuration, downloaded)
207
+ #expect ( configuration == downloaded)
209
208
}
210
209
}
0 commit comments