Skip to content

Commit

Permalink
Adding tests for upload and download with progress
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Sep 30, 2014
1 parent bc6a58d commit da237ff
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Tests/DownloadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,26 @@ class AlamofireDownloadResponseTestCase: XCTestCase {
XCTAssertNil(error, "\(error)")
}
}

func testDownloadRequestWithProgress() {
let numberOfLines = 100
let URL = "http://httpbin.org/stream/\(numberOfLines)"

let expectation = expectationWithDescription(URL)

let destination = Alamofire.Request.suggestedDownloadDestination(directory: searchPathDirectory, domain: searchPathDomain)

Alamofire.download(.GET, URL, destination)
.progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) -> Void in
expectation.fulfill()

XCTAssertGreaterThan(bytesRead, 0, "bytesRead should be > 0")
XCTAssertGreaterThan(totalBytesRead, 0, "totalBytesRead should be > 0")
XCTAssertEqual(totalBytesExpectedToRead, -1, "totalBytesExpectedToRead should be -1")
}

waitForExpectationsWithTimeout(10) { (error) in
XCTAssertNil(error, "\(error)")
}
}
}
22 changes: 21 additions & 1 deletion Tests/UploadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Alamofire
import XCTest

class UploadResponseTestCase: XCTestCase {
func testDownloadRequest() {
func testUploadRequest() {
let URL = "http://httpbin.org/post"
let data = "Lorem ipsum dolor sit amet".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)

Expand All @@ -44,4 +44,24 @@ class UploadResponseTestCase: XCTestCase {
XCTAssertNil(error, "\(error)")
}
}

func testUploadRequestWithProgress() {
let URL = "http://httpbin.org/post"
let data = "Lorem ipsum dolor sit amet".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)

let expectation = expectationWithDescription(URL)

Alamofire.upload(.POST, URL, data!)
.progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) -> Void in
expectation.fulfill()

XCTAssertGreaterThan(bytesWritten, 0, "bytesWritten should be > 0")
XCTAssertGreaterThan(totalBytesWritten, 0, "totalBytesWritten should be > 0")
XCTAssertGreaterThan(totalBytesExpectedToWrite, 0, "totalBytesExpectedToWrite should be > 0")
}

waitForExpectationsWithTimeout(10) { (error) in
XCTAssertNil(error, "\(error)")
}
}
}

0 comments on commit da237ff

Please sign in to comment.