@@ -33,10 +33,87 @@ final class RegistryManagerTests: XCTestCase {
33
33
return MockArchiver ( )
34
34
}
35
35
36
- RegistryManager . clientFactory = { _ in
37
- let configuration = URLSessionConfiguration . default
38
- configuration. protocolClasses = [ MockPackageRegistryURLProtocol . self] + ( configuration. protocolClasses ?? [ ] )
39
- return URLSessionHTTPClient ( configuration: configuration)
36
+ RegistryManager . clientFactory = { diagnosticsEngine in
37
+ let configuration = HTTPClientConfiguration ( )
38
+ let handler : HTTPClient . Handler = { request, completion in
39
+ var headers : HTTPClientHeaders = [
40
+ " Content-Version " : " 1 " ,
41
+ ]
42
+
43
+ let result : Result < HTTPClientResponse , Error >
44
+ switch ( request. method, request. url. absoluteString. lowercased ( ) ) {
45
+ case ( . head, " https://github.com/mona/linkedlist " ) :
46
+ headers. add ( name: " Location " , value: " https://pkg.swift.github.com/github.com/mona/LinkedList " )
47
+
48
+ result = . success( HTTPClientResponse ( statusCode: 303 , headers: headers, body: nil ) )
49
+ case ( . get, " https://pkg.swift.github.com/github.com/mona/linkedlist " ) :
50
+ let data = #"""
51
+ {
52
+ "releases": {
53
+ "1.1.1": {
54
+ "url": "https://packages.example.com/mona/LinkedList/1.1.1"
55
+ },
56
+ "1.1.0": {
57
+ "url": "https://packages.example.com/mona/LinkedList/1.1.0",
58
+ "problem": {
59
+ "status": 410,
60
+ "title": "Gone",
61
+ "detail": "this release was removed from the registry"
62
+ }
63
+ },
64
+ "1.0.0": {
65
+ "url": "https://packages.example.com/mona/LinkedList/1.0.0"
66
+ }
67
+ }
68
+ }
69
+
70
+ """# . data ( using: . utf8) !
71
+
72
+ headers. add ( name: " Content-Type " , value: " application/json " )
73
+ headers. add ( name: " Content-Length " , value: " \( data. count) " )
74
+
75
+ result = . success( HTTPClientResponse ( statusCode: 200 , headers: headers, body: data) )
76
+ case ( . get, " https://pkg.swift.github.com/github.com/mona/linkedlist/1.1.1/package.swift " ) :
77
+ let data = #"""
78
+ // swift-tools-version:5.0
79
+ import PackageDescription
80
+
81
+ let package = Package(
82
+ name: "LinkedList",
83
+ products: [
84
+ .library(name: "LinkedList", targets: ["LinkedList"])
85
+ ],
86
+ targets: [
87
+ .target(name: "LinkedList"),
88
+ .testTarget(name: "LinkedListTests", dependencies: ["LinkedList"]),
89
+ ],
90
+ swiftLanguageVersions: [.v4, .v5]
91
+ )
92
+
93
+ """# . data ( using: . utf8) !
94
+
95
+ headers. add ( name: " Content-Type " , value: " text/x-swift " )
96
+ headers. add ( name: " Content-Disposition " , value: #"attachment; filename="Package.swift""# )
97
+ headers. add ( name: " Content-Length " , value: " \( data. count) " )
98
+
99
+ result = . success( HTTPClientResponse ( statusCode: 200 , headers: headers, body: data) )
100
+ case ( . get, " https://pkg.swift.github.com/github.com/mona/linkedlist/1.1.1.zip " ) :
101
+ let archive = emptyZipFile
102
+
103
+ headers. add ( name: " Content-Type " , value: " application/zip " )
104
+ headers. add ( name: " Content-Disposition " , value: #"attachment; filename="LinkedList-1.1.1.zip""# )
105
+ headers. add ( name: " Content-Length " , value: " 22 " )
106
+ headers. add ( name: " Digest " , value: " sha-256=bc6c9a5d2f2226cfa1ef4fad8344b10e1cc2e82960f468f70d9ed696d26b3283 " )
107
+
108
+ result = . success( HTTPClientResponse ( statusCode: 200 , headers: headers, body: Data ( archive. contents) ) )
109
+ default :
110
+ result = . failure( StringError ( " Unhandled request: \( request) " ) )
111
+ }
112
+
113
+ completion ( result)
114
+ }
115
+
116
+ return HTTPClient ( configuration: configuration, handler: handler, diagnosticsEngine: diagnosticsEngine)
40
117
}
41
118
42
119
super. setUp ( )
0 commit comments