Skip to content

Commit 7433b55

Browse files
committed
add FileDownloadDelegate.Response head to existing tests
1 parent 82e74b9 commit 7433b55

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

Tests/AsyncHTTPClientTests/HTTPClientTests.swift

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -729,51 +729,57 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
729729
var request = try Request(url: self.defaultHTTPBinURLPrefix + "events/10/content-length")
730730
request.headers.add(name: "Accept", value: "text/event-stream")
731731

732-
let progress =
733-
try TemporaryFileHelpers.withTemporaryFilePath { path -> FileDownloadDelegate.Progress in
732+
let response =
733+
try TemporaryFileHelpers.withTemporaryFilePath { path -> FileDownloadDelegate.Response in
734734
let delegate = try FileDownloadDelegate(path: path)
735735

736-
let progress = try self.defaultClient.execute(
736+
let response = try self.defaultClient.execute(
737737
request: request,
738738
delegate: delegate
739739
)
740740
.wait()
741741

742742
try XCTAssertEqual(50, TemporaryFileHelpers.fileSize(path: path))
743743

744-
return progress
744+
return response
745745
}
746746

747-
XCTAssertEqual(50, progress.totalBytes)
748-
XCTAssertEqual(50, progress.receivedBytes)
747+
XCTAssertEqual(response.head.status, .ok)
748+
XCTAssertEqual("50", response.head.headers.first(name: "content-length"))
749+
750+
XCTAssertEqual(50, response.totalBytes)
751+
XCTAssertEqual(50, response.receivedBytes)
749752
}
750753

751754
func testFileDownloadError() throws {
752755
var request = try Request(url: self.defaultHTTPBinURLPrefix + "not-found")
753756
request.headers.add(name: "Accept", value: "text/event-stream")
754757

755-
let progress =
756-
try TemporaryFileHelpers.withTemporaryFilePath { path -> FileDownloadDelegate.Progress in
758+
let response =
759+
try TemporaryFileHelpers.withTemporaryFilePath { path -> FileDownloadDelegate.Response in
757760
let delegate = try FileDownloadDelegate(
758761
path: path,
759762
reportHead: {
760763
XCTAssertEqual($0.status, .notFound)
761764
}
762765
)
763766

764-
let progress = try self.defaultClient.execute(
767+
let response = try self.defaultClient.execute(
765768
request: request,
766769
delegate: delegate
767770
)
768771
.wait()
769772

770773
XCTAssertFalse(TemporaryFileHelpers.fileExists(path: path))
771774

772-
return progress
775+
return response
773776
}
774777

775-
XCTAssertEqual(nil, progress.totalBytes)
776-
XCTAssertEqual(0, progress.receivedBytes)
778+
XCTAssertEqual(response.head.status, .notFound)
779+
XCTAssertFalse(response.head.headers.contains(name: "content-length"))
780+
781+
XCTAssertEqual(nil, response.totalBytes)
782+
XCTAssertEqual(0, response.receivedBytes)
777783
}
778784

779785
func testFileDownloadCustomError() throws {
@@ -3910,23 +3916,27 @@ final class HTTPClientTests: XCTestCaseHTTPClientTestsBaseClass {
39103916
var request = try Request(url: self.defaultHTTPBinURLPrefix + "chunked")
39113917
request.headers.add(name: "Accept", value: "text/event-stream")
39123918

3913-
let progress =
3919+
let response =
39143920
try TemporaryFileHelpers.withTemporaryFilePath { path -> FileDownloadDelegate.Progress in
39153921
let delegate = try FileDownloadDelegate(path: path)
39163922

3917-
let progress = try self.defaultClient.execute(
3923+
let response = try self.defaultClient.execute(
39183924
request: request,
39193925
delegate: delegate
39203926
)
39213927
.wait()
39223928

39233929
try XCTAssertEqual(50, TemporaryFileHelpers.fileSize(path: path))
39243930

3925-
return progress
3931+
return response
39263932
}
39273933

3928-
XCTAssertEqual(nil, progress.totalBytes)
3929-
XCTAssertEqual(50, progress.receivedBytes)
3934+
XCTAssertEqual(.ok, response.head.status)
3935+
XCTAssertEqual("chunked", response.head.headers.first(name: "transfer-encoding"))
3936+
XCTAssertFalse(response.head.headers.contains(name: "content-length"))
3937+
3938+
XCTAssertEqual(nil, response.totalBytes)
3939+
XCTAssertEqual(50, response.receivedBytes)
39303940
}
39313941

39323942
func testCloseWhileBackpressureIsExertedIsFine() throws {

0 commit comments

Comments
 (0)