1
1
import ConcurrencyExtras
2
2
@testable import Functions
3
3
import Helpers
4
+ import HTTPTypes
4
5
import TestHelpers
5
6
import XCTest
6
7
@@ -22,8 +23,8 @@ final class FunctionsClientTests: XCTestCase {
22
23
)
23
24
XCTAssertEqual ( client. region, " sa-east-1 " )
24
25
25
- XCTAssertEqual ( client. headers [ " Apikey " ] , apiKey)
26
- XCTAssertNotNil ( client. headers [ " X-Client-Info " ] )
26
+ XCTAssertEqual ( client. headers [ . init ( " Apikey " ) ! ] , apiKey)
27
+ XCTAssertNotNil ( client. headers [ . init ( " X-Client-Info " ) ! ] )
27
28
}
28
29
29
30
func testInvoke( ) async throws {
@@ -53,9 +54,9 @@ final class FunctionsClientTests: XCTestCase {
53
54
54
55
XCTAssertEqual ( request? . url, url)
55
56
XCTAssertEqual ( request? . method, . post)
56
- XCTAssertEqual ( request? . headers [ " Apikey " ] , apiKey)
57
- XCTAssertEqual ( request? . headers [ " X-Custom-Key " ] , " value " )
58
- XCTAssertEqual ( request? . headers [ " X-Client-Info " ] , " functions-swift/ \( Functions . version) " )
57
+ XCTAssertEqual ( request? . headers [ . init ( " Apikey " ) ! ] , apiKey)
58
+ XCTAssertEqual ( request? . headers [ . init ( " X-Custom-Key " ) ! ] , " value " )
59
+ XCTAssertEqual ( request? . headers [ . init ( " X-Client-Info " ) ! ] , " functions-swift/ \( Functions . version) " )
59
60
}
60
61
61
62
func testInvokeWithCustomMethod( ) async throws {
@@ -109,7 +110,7 @@ final class FunctionsClientTests: XCTestCase {
109
110
try await sut. invoke ( " hello-world " )
110
111
111
112
let request = await http. receivedRequests. last
112
- XCTAssertEqual ( request? . headers [ " x-region " ] , " ca-central-1 " )
113
+ XCTAssertEqual ( request? . headers [ . xRegion ] , " ca-central-1 " )
113
114
}
114
115
115
116
func testInvokeWithRegion( ) async throws {
@@ -126,7 +127,7 @@ final class FunctionsClientTests: XCTestCase {
126
127
try await sut. invoke ( " hello-world " , options: . init( region: . caCentral1) )
127
128
128
129
let request = await http. receivedRequests. last
129
- XCTAssertEqual ( request? . headers [ " x-region " ] , " ca-central-1 " )
130
+ XCTAssertEqual ( request? . headers [ . xRegion ] , " ca-central-1 " )
130
131
}
131
132
132
133
func testInvokeWithoutRegion( ) async throws {
@@ -143,7 +144,7 @@ final class FunctionsClientTests: XCTestCase {
143
144
try await sut. invoke ( " hello-world " )
144
145
145
146
let request = await http. receivedRequests. last
146
- XCTAssertNil ( request? . headers [ " x-region " ] )
147
+ XCTAssertNil ( request? . headers [ . xRegion ] )
147
148
}
148
149
149
150
func testInvoke_shouldThrow_URLError_badServerResponse( ) async {
@@ -190,7 +191,7 @@ final class FunctionsClientTests: XCTestCase {
190
191
http: HTTPClientMock ( ) . any { _ in
191
192
try . stub(
192
193
body: Empty ( ) ,
193
- headers: [ " x-relay-error " : " true " ]
194
+ headers: [ . xRelayError : " true " ]
194
195
)
195
196
}
196
197
)
@@ -206,16 +207,16 @@ final class FunctionsClientTests: XCTestCase {
206
207
207
208
func test_setAuth( ) {
208
209
sut. setAuth ( token: " access.token " )
209
- XCTAssertEqual ( sut. headers [ " Authorization " ] , " Bearer access.token " )
210
+ XCTAssertEqual ( sut. headers [ . authorization ] , " Bearer access.token " )
210
211
}
211
212
}
212
213
213
- extension HTTPResponse {
214
+ extension Helpers . HTTPResponse {
214
215
static func stub(
215
216
body: any Encodable ,
216
217
statusCode: Int = 200 ,
217
- headers: HTTPHeaders = . init( )
218
- ) throws -> HTTPResponse {
218
+ headers: HTTPFields = . init( )
219
+ ) throws -> Helpers . HTTPResponse {
219
220
let data = try JSONEncoder ( ) . encode ( body)
220
221
let response = HTTPURLResponse (
221
222
url: URL ( string: " http://127.0.0.1 " ) !,
0 commit comments