Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download(to:, completionHandler:) doesn't work. #75

Open
ghost opened this issue Oct 4, 2019 · 2 comments
Open

download(to:, completionHandler:) doesn't work. #75

ghost opened this issue Oct 4, 2019 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 4, 2019

Hi all,
I'm faced with the issue, that download method just creates an empty file, but actually no content downloads.

Tested on my mac, with XCode 11, SwiftyRequest v3.0.0.
The problem is that DownloadDelegate methods doesn't fire as expected. Currently, it only creates an empty file by this method:

func didSendRequestHead(task: HTTPClient.Task<Response>, _ head: HTTPRequestHead)

and this method never fires:

func didReceivePart(task: HTTPClient.Task<Response>, _ buffer: ByteBuffer) -> EventLoopFuture<Void>

Also, seems that testFileDownload test is false-positive.

Completion handler check only response status code, but not written data length or something else:

case .success(let result):
                XCTAssertEqual(result.status.code, 200)

So, what happens here on my local machine:

  1. it is trying to download file with JSON
  2. during the download it creates an empty file
  3. checks status code (200) and pass the test
  4. removes an empty file

Modified test code to reproduce the issue:

func testFileDownload() {
        let expectation = self.expectation(description: "download file SwiftyRequest test")

        let url = "https://raw.githubusercontent.com/IBM-Swift/SwiftyRequest/c7cfc669a5872831e816d9f9c6fec06bc638222b/Tests/SwiftyRequestTests/test_file.json"

        let request = RestRequest(url: url)

        // 1. change destination URL. (file should be created at root of the project dir)
        let bundleURL = URL(fileURLWithPath: "./")
        let destinationURL = bundleURL.appendingPathComponent("test_file.json")

        request.download(to: destinationURL) { response in
            switch response {
            case .success(let result):
                XCTAssertEqual(result.status.code, 200)
            case .failure(let error):
                XCTFail("Failed download with error: \(error)")
            }
            // 2. print destination URL
            print(destinationURL)
            // 3. Don't remove the file in order to check it content
            expectation.fulfill()
        }

        waitForExpectations(timeout: 10)
    }
@djones6
Copy link
Contributor

djones6 commented Oct 9, 2019

@harish1992 Could you take a look at this?

@codemeister64
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants