Skip to content

Commit cc9964f

Browse files
authored
Fix tests to include content-length header, now included by runtime library (apple#510)
### Motivation The runtime library now always includes content-length with bodies, and our tests verified the exact set of header fields present. ### Modifications Update the expectations to include the content-length header. ### Result Passing tests again. ### Test Plan Tests are passing again.
1 parent b18bece commit cc9964f

File tree

4 files changed

+39
-26
lines changed

4 files changed

+39
-26
lines changed

Package.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ let package = Package(
6060
// Tests-only: Runtime library linked by generated code, and also
6161
// helps keep the runtime library new enough to work with the generated
6262
// code.
63-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.2.0"),
63+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.3.2"),
6464
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
6565

6666
// Build and preview docs

Tests/PetstoreConsumerTests/Test_Client.swift

+15-9
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ final class Test_Client: XCTestCase {
124124
XCTAssertEqual(
125125
request.headerFields,
126126
[
127-
.accept: "application/json", .contentType: "application/json; charset=utf-8",
127+
.accept: "application/json", .contentType: "application/json; charset=utf-8", .contentLength: "23",
128128
.init("X-Extra-Arguments")!: #"{"code":1}"#,
129129
]
130130
)
@@ -198,7 +198,10 @@ final class Test_Client: XCTestCase {
198198
XCTAssertEqual(request.path, "/pets/create")
199199
XCTAssertEqual(baseURL.absoluteString, "/api")
200200
XCTAssertEqual(request.method, .post)
201-
XCTAssertEqual(request.headerFields, [.contentType: "application/x-www-form-urlencoded"])
201+
XCTAssertEqual(
202+
request.headerFields,
203+
[.contentType: "application/x-www-form-urlencoded", .contentLength: "11"]
204+
)
202205
let bodyString: String
203206
if let body { bodyString = try await String(collecting: body, upTo: .max) } else { bodyString = "" }
204207
XCTAssertEqual(bodyString, "name=Fluffz")
@@ -220,7 +223,7 @@ final class Test_Client: XCTestCase {
220223
XCTAssertEqual(request.method, .patch)
221224
XCTAssertEqual(
222225
request.headerFields,
223-
[.accept: "application/json", .contentType: "application/json; charset=utf-8"]
226+
[.accept: "application/json", .contentType: "application/json; charset=utf-8", .contentLength: "23"]
224227
)
225228
try await XCTAssertEqualStringifiedData(
226229
requestBody,
@@ -265,7 +268,7 @@ final class Test_Client: XCTestCase {
265268
XCTAssertEqual(
266269
request.headerFields,
267270
[
268-
.accept: "application/json", .contentType: "application/json; charset=utf-8",
271+
.accept: "application/json", .contentType: "application/json; charset=utf-8", .contentLength: "112",
269272
.init("X-Extra-Arguments")!: #"{"code":1}"#,
270273
]
271274
)
@@ -533,7 +536,10 @@ final class Test_Client: XCTestCase {
533536
XCTAssertEqual(request.path, "/pets/stats")
534537
XCTAssertEqual(baseURL.absoluteString, "/api")
535538
XCTAssertEqual(request.method, .post)
536-
XCTAssertEqual(request.headerFields, [.contentType: "application/json; charset=utf-8"])
539+
XCTAssertEqual(
540+
request.headerFields,
541+
[.contentType: "application/json; charset=utf-8", .contentLength: "17"]
542+
)
537543
try await XCTAssertEqualStringifiedData(
538544
requestBody,
539545
#"""
@@ -557,7 +563,7 @@ final class Test_Client: XCTestCase {
557563
XCTAssertEqual(request.path, "/pets/stats")
558564
XCTAssertEqual(baseURL.absoluteString, "/api")
559565
XCTAssertEqual(request.method, .post)
560-
XCTAssertEqual(request.headerFields, [.contentType: "text/plain"])
566+
XCTAssertEqual(request.headerFields, [.contentType: "text/plain", .contentLength: "10"])
561567
try await XCTAssertEqualStringifiedData(
562568
requestBody,
563569
#"""
@@ -579,7 +585,7 @@ final class Test_Client: XCTestCase {
579585
XCTAssertEqual(request.path, "/pets/stats")
580586
XCTAssertEqual(baseURL.absoluteString, "/api")
581587
XCTAssertEqual(request.method, .post)
582-
XCTAssertEqual(request.headerFields, [.contentType: "application/octet-stream"])
588+
XCTAssertEqual(request.headerFields, [.contentType: "application/octet-stream", .contentLength: "10"])
583589
try await XCTAssertEqualStringifiedData(
584590
requestBody,
585591
#"""
@@ -635,7 +641,7 @@ final class Test_Client: XCTestCase {
635641
request.headerFields,
636642
[
637643
.accept: "application/octet-stream, application/json, text/plain",
638-
.contentType: "application/octet-stream",
644+
.contentType: "application/octet-stream", .contentLength: "4",
639645
]
640646
)
641647
try await XCTAssertEqualStringifiedData(requestBody, Data.abcdString)
@@ -662,7 +668,7 @@ final class Test_Client: XCTestCase {
662668
request.headerFields,
663669
[
664670
.accept: "application/octet-stream, application/json, text/plain",
665-
.contentType: "application/octet-stream",
671+
.contentType: "application/octet-stream", .contentLength: "4",
666672
]
667673
)
668674
try await XCTAssertEqualStringifiedData(requestBody, Data.abcdString)

Tests/PetstoreConsumerTests/Test_Server.swift

+21-15
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ final class Test_Server: XCTestCase {
5555
response.headerFields,
5656
[
5757
.init("My-Response-UUID")!: "abcd", .init("My-Tracing-Header")!: "1234",
58-
.contentType: "application/json; charset=utf-8",
58+
.contentType: "application/json; charset=utf-8", .contentLength: "47",
5959
]
6060
)
6161
let bodyString: String
@@ -87,7 +87,7 @@ final class Test_Server: XCTestCase {
8787
.init()
8888
)
8989
XCTAssertEqual(response.status.code, 400)
90-
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8"])
90+
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8", .contentLength: "40"])
9191
try await XCTAssertEqualStringifiedData(
9292
responseBody,
9393
#"""
@@ -131,7 +131,10 @@ final class Test_Server: XCTestCase {
131131
XCTAssertEqual(response.status.code, 201)
132132
XCTAssertEqual(
133133
response.headerFields,
134-
[.init("X-Extra-Arguments")!: #"{"code":1}"#, .contentType: "application/json; charset=utf-8"]
134+
[
135+
.init("X-Extra-Arguments")!: #"{"code":1}"#, .contentType: "application/json; charset=utf-8",
136+
.contentLength: "35",
137+
]
135138
)
136139
try await XCTAssertEqualStringifiedData(
137140
responseBody,
@@ -169,7 +172,7 @@ final class Test_Server: XCTestCase {
169172
XCTAssertEqual(response.status.code, 400)
170173
XCTAssertEqual(
171174
response.headerFields,
172-
[.init("X-Reason")!: "bad%20luck", .contentType: "application/json; charset=utf-8"]
175+
[.init("X-Reason")!: "bad%20luck", .contentType: "application/json; charset=utf-8", .contentLength: "16"]
173176
)
174177
try await XCTAssertEqualStringifiedData(
175178
responseBody,
@@ -270,7 +273,10 @@ final class Test_Server: XCTestCase {
270273
XCTAssertEqual(response.status.code, 201)
271274
XCTAssertEqual(
272275
response.headerFields,
273-
[.init("X-Extra-Arguments")!: #"{"code":1}"#, .contentType: "application/json; charset=utf-8"]
276+
[
277+
.init("X-Extra-Arguments")!: #"{"code":1}"#, .contentType: "application/json; charset=utf-8",
278+
.contentLength: "35",
279+
]
274280
)
275281
try await XCTAssertEqualStringifiedData(
276282
responseBody,
@@ -363,7 +369,7 @@ final class Test_Server: XCTestCase {
363369
.init(pathParameters: ["petId": "1"])
364370
)
365371
XCTAssertEqual(response.status.code, 400)
366-
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8"])
372+
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8", .contentLength: "26"])
367373
try await XCTAssertEqualStringifiedData(
368374
responseBody,
369375
#"""
@@ -386,7 +392,7 @@ final class Test_Server: XCTestCase {
386392
.init()
387393
)
388394
XCTAssertEqual(response.status.code, 200)
389-
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8"])
395+
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8", .contentLength: "17"])
390396
try await XCTAssertEqualStringifiedData(
391397
responseBody,
392398
#"""
@@ -421,7 +427,7 @@ final class Test_Server: XCTestCase {
421427
.init()
422428
)
423429
XCTAssertEqual(response.status.code, 200)
424-
XCTAssertEqual(response.headerFields, [.contentType: "text/plain"])
430+
XCTAssertEqual(response.headerFields, [.contentType: "text/plain", .contentLength: "10"])
425431
try await XCTAssertEqualStringifiedData(
426432
responseBody,
427433
#"""
@@ -482,7 +488,7 @@ final class Test_Server: XCTestCase {
482488
.init()
483489
)
484490
XCTAssertEqual(response.status.code, 200)
485-
XCTAssertEqual(response.headerFields, [.contentType: "text/plain"])
491+
XCTAssertEqual(response.headerFields, [.contentType: "text/plain", .contentLength: "10"])
486492
try await XCTAssertEqualStringifiedData(
487493
responseBody,
488494
#"""
@@ -509,7 +515,7 @@ final class Test_Server: XCTestCase {
509515
.init()
510516
)
511517
XCTAssertEqual(response.status.code, 200)
512-
XCTAssertEqual(response.headerFields, [.contentType: "text/plain"])
518+
XCTAssertEqual(response.headerFields, [.contentType: "text/plain", .contentLength: "10"])
513519
try await XCTAssertEqualStringifiedData(
514520
responseBody,
515521
#"""
@@ -530,7 +536,7 @@ final class Test_Server: XCTestCase {
530536
.init()
531537
)
532538
XCTAssertEqual(response.status.code, 200)
533-
XCTAssertEqual(response.headerFields, [.contentType: "application/octet-stream"])
539+
XCTAssertEqual(response.headerFields, [.contentType: "application/octet-stream", .contentLength: "10"])
534540
try await XCTAssertEqualStringifiedData(
535541
responseBody,
536542
#"""
@@ -674,7 +680,7 @@ final class Test_Server: XCTestCase {
674680
.init(pathParameters: ["petId": "1"])
675681
)
676682
XCTAssertEqual(response.status.code, 200)
677-
XCTAssertEqual(response.headerFields, [.contentType: "application/octet-stream"])
683+
XCTAssertEqual(response.headerFields, [.contentType: "application/octet-stream", .contentLength: "4"])
678684
try await XCTAssertEqualStringifiedData(responseBody, Data.efghString)
679685
}
680686

@@ -711,7 +717,7 @@ final class Test_Server: XCTestCase {
711717
.init(pathParameters: ["petId": "1"])
712718
)
713719
XCTAssertEqual(response.status.code, 200)
714-
XCTAssertEqual(response.headerFields, [.contentType: "application/octet-stream"])
720+
XCTAssertEqual(response.headerFields, [.contentType: "application/octet-stream", .contentLength: "4"])
715721
try await XCTAssertEqualStringifiedData(responseBody, Data.abcdString)
716722
let sizes = await chunkSizeCollector.sizes
717723
XCTAssertEqual(sizes, [4])
@@ -736,7 +742,7 @@ final class Test_Server: XCTestCase {
736742
.init(pathParameters: ["petId": "1"])
737743
)
738744
XCTAssertEqual(response.status.code, 412)
739-
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8"])
745+
XCTAssertEqual(response.headerFields, [.contentType: "application/json; charset=utf-8", .contentLength: "6"])
740746
try await XCTAssertEqualStringifiedData(responseBody, Data.quotedEfghString)
741747
}
742748

@@ -759,7 +765,7 @@ final class Test_Server: XCTestCase {
759765
.init(pathParameters: ["petId": "1"])
760766
)
761767
XCTAssertEqual(response.status.code, 500)
762-
XCTAssertEqual(response.headerFields, [.contentType: "text/plain"])
768+
XCTAssertEqual(response.headerFields, [.contentType: "text/plain", .contentLength: "4"])
763769
try await XCTAssertEqualStringifiedData(responseBody, Data.efghString)
764770
}
765771

docker/docker-compose.2204.510.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ services:
1010
test:
1111
image: *image
1212
environment:
13-
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
13+
# Disable warnings as errors on nightlies as they are still in-development.
14+
# - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
1415
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
1516
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
1617
shell:

0 commit comments

Comments
 (0)