@@ -94,6 +94,115 @@ final class RegistryClientTests: XCTestCase {
94
94
SourceControlURL ( " git@github.com:mona/LinkedList.git " ) ,
95
95
SourceControlURL ( " https://gitlab.com/mona/LinkedList " ) ,
96
96
] )
97
+
98
+ let metadataSync = try await withCheckedThrowingContinuation { continuation in
99
+ return registryClient. getPackageMetadata (
100
+ package : identity,
101
+ timeout: nil ,
102
+ observabilityScope: ObservabilitySystem . NOOP,
103
+ callbackQueue: . sharedConcurrent,
104
+ completion: { continuation. resume ( with: $0) }
105
+ )
106
+ }
107
+ XCTAssertEqual ( metadataSync. versions, [ " 1.1.1 " , " 1.0.0 " ] )
108
+ XCTAssertEqual ( metadataSync. alternateLocations, [
109
+ SourceControlURL ( " https://github.com/mona/LinkedList " ) ,
110
+ SourceControlURL ( " ssh://git@github.com:mona/LinkedList.git " ) ,
111
+ SourceControlURL ( " git@github.com:mona/LinkedList.git " ) ,
112
+ SourceControlURL ( " https://gitlab.com/mona/LinkedList " ) ,
113
+ ] )
114
+ }
115
+
116
+ func testGetPackageMetadataPaginated( ) async throws {
117
+ let registryURL = URL ( " https://packages.example.com " )
118
+ let identity = PackageIdentity . plain ( " mona.LinkedList " )
119
+ let releasesURL = URL ( " \( registryURL) / \( identity. registry!. scope) / \( identity. registry!. name) " )
120
+ let releasesURLPage2 = URL ( " \( registryURL) / \( identity. registry!. scope) / \( identity. registry!. name) ?page=2 " )
121
+
122
+ let handler : LegacyHTTPClient . Handler = { request, _, completion in
123
+ guard case . get = request. method else {
124
+ return completion ( . failure( StringError ( " method should be `get` " ) ) )
125
+ }
126
+
127
+ XCTAssertEqual ( request. headers. get ( " Accept " ) . first, " application/vnd.swift.registry.v1+json " )
128
+ let links : String
129
+ let data : Data
130
+ switch request. url {
131
+ case releasesURL:
132
+ data = #"""
133
+ {
134
+ "releases": {
135
+ "1.1.1": {
136
+ "url": "https://packages.example.com/mona/LinkedList/1.1.1"
137
+ },
138
+ "1.1.0": {
139
+ "url": "https://packages.example.com/mona/LinkedList/1.1.0",
140
+ "problem": {
141
+ "status": 410,
142
+ "title": "Gone",
143
+ "detail": "this release was removed from the registry"
144
+ }
145
+ }
146
+ }
147
+ }
148
+ """# . data ( using: . utf8) !
149
+
150
+ links = """
151
+ <https://github.com/mona/LinkedList>; rel= " canonical " ,
152
+ <ssh://git@github.com:mona/LinkedList.git>; rel= " alternate " ,
153
+ <git@github.com:mona/LinkedList.git>; rel= " alternate " ,
154
+ <https://gitlab.com/mona/LinkedList>; rel= " alternate " ,
155
+ < \( releasesURLPage2) >; rel= " next "
156
+ """
157
+ case releasesURLPage2:
158
+ data = #"""
159
+ {
160
+ "releases": {
161
+ "1.0.0": {
162
+ "url": "https://packages.example.com/mona/LinkedList/1.0.0"
163
+ }
164
+ }
165
+ }
166
+ """# . data ( using: . utf8) !
167
+
168
+ links = """
169
+ <https://github.com/mona/LinkedList>; rel= " canonical " ,
170
+ <ssh://git@github.com:mona/LinkedList.git>; rel= " alternate " ,
171
+ <git@github.com:mona/LinkedList.git>; rel= " alternate " ,
172
+ <https://gitlab.com/mona/LinkedList>; rel= " alternate "
173
+ """
174
+ default :
175
+ return completion ( . failure( StringError ( " method and url should match " ) ) )
176
+ }
177
+
178
+ completion ( . success( . init(
179
+ statusCode: 200 ,
180
+ headers: . init( [
181
+ . init( name: " Content-Length " , value: " \( data. count) " ) ,
182
+ . init( name: " Content-Type " , value: " application/json " ) ,
183
+ . init( name: " Content-Version " , value: " 1 " ) ,
184
+ . init( name: " Link " , value: links) ,
185
+ ] ) ,
186
+ body: data
187
+ ) ) )
188
+ }
189
+
190
+ let httpClient = LegacyHTTPClient ( handler: handler)
191
+ httpClient. configuration. circuitBreakerStrategy = . none
192
+ httpClient. configuration. retryStrategy = . none
193
+
194
+ var configuration = RegistryConfiguration ( )
195
+ configuration. defaultRegistry = Registry ( url: registryURL, supportsAvailability: false )
196
+
197
+ let registryClient = makeRegistryClient ( configuration: configuration, httpClient: httpClient)
198
+ let metadata = try await registryClient. getPackageMetadata ( package : identity)
199
+ XCTAssertEqual ( metadata. versions, [ " 1.1.1 " , " 1.0.0 " ] )
200
+ XCTAssertEqual ( metadata. alternateLocations, [
201
+ SourceControlURL ( " https://github.com/mona/LinkedList " ) ,
202
+ SourceControlURL ( " ssh://git@github.com:mona/LinkedList.git " ) ,
203
+ SourceControlURL ( " git@github.com:mona/LinkedList.git " ) ,
204
+ SourceControlURL ( " https://gitlab.com/mona/LinkedList " ) ,
205
+ ] )
97
206
}
98
207
99
208
func testGetPackageMetadata_NotFound( ) async throws {
0 commit comments