Skip to content

Commit

Permalink
Debug info for travis build
Browse files Browse the repository at this point in the history
  • Loading branch information
timshadel committed Aug 12, 2016
1 parent 61fd212 commit dbc2704
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
20 changes: 20 additions & 0 deletions DVR/Cassette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,31 @@ struct Cassette {
// MARK: - Functions

func interactionForRequest(request: NSURLRequest) -> Interaction? {
print("REQUEST")
print(request.HTTPMethod)
print(request.URL)
if let body = request.HTTPBody {
print(Interaction.encodeBody(body, headers: request.allHTTPHeaderFields))
} else {
print("[empty body]")
}
print("")
for interaction in interactions {
let interactionRequest = interaction.request

print("INTERACTION")
print(interactionRequest.HTTPMethod)
print(interactionRequest.URL)
if let body = interactionRequest.HTTPBody {
print(Interaction.encodeBody(body, headers: interactionRequest.allHTTPHeaderFields))
} else {
print("[empty body]")
}
print("")

// Note: We don't check headers right now
if interactionRequest.HTTPMethod == request.HTTPMethod && interactionRequest.URL == request.URL && interactionRequest.hasHTTPBodyEqualToThatOfRequest(request) {
print("MATCHED!")
return interaction
}
}
Expand Down
11 changes: 10 additions & 1 deletion DVR/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ public class Session: NSURLSession {
}

public override func uploadTaskWithRequest(request: NSURLRequest, fromFile fileURL: NSURL, completionHandler: (NSData?, NSURLResponse?, NSError?) -> Void) -> NSURLSessionUploadTask {
print(fileURL)
print("File exists: \(NSFileManager.defaultManager().fileExistsAtPath(fileURL.path!))")
let data = NSData(contentsOfURL: fileURL)
print("DATA-2")
print(data)
return addUploadTask(request, fromData: data, completionHandler: completionHandler)
}

Expand Down Expand Up @@ -162,7 +166,12 @@ public class Session: NSURLSession {

private func addUploadTask(request: NSURLRequest, fromData data: NSData?, completionHandler: SessionUploadTask.Completion? = nil) -> NSURLSessionUploadTask {
var modifiedRequest = backingSession.configuration.HTTPAdditionalHeaders.map(request.requestByAppendingHeaders) ?? request
modifiedRequest = data.map(modifiedRequest.requestWithBody) ?? modifiedRequest
print("DATA-3")
print(data)
let mapped = data.map(modifiedRequest.requestWithBody)
print("MAPPED")
print(mapped)
modifiedRequest = mapped ?? modifiedRequest
let task = SessionUploadTask(session: self, request: modifiedRequest, completion: completionHandler)
addTask(task.dataTask)
return task
Expand Down
12 changes: 11 additions & 1 deletion DVR/Tests/SessionUploadTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ class SessionUploadTests: XCTestCase {
guard let fileData = NSData(contentsOfURL: testFile) else { XCTFail("Missing body data"); return }
let data = encodeMultipartBody(fileData, parameters: [:])
let file = writeDataToFile(data, fileName: "upload-file")
print("DATA")
print(data)
print("FILE")
print(file)
print("File exists: \(NSFileManager.defaultManager().fileExistsAtPath(file.path!))")
let check = NSData(contentsOfURL: file)
print("DATA-1.2")
print(check)

session.uploadTaskWithRequest(request, fromFile: file) { data, response, error in
if let error = error {
Expand Down Expand Up @@ -99,7 +107,9 @@ class SessionUploadTests: XCTestCase {

let url = documentsURL.URLByAppendingPathComponent(fileName + ".tmp")

data.writeToURL(url, atomically: true)
if !data.writeToURL(url, atomically: true) {
XCTFail("Failed to write to \(url)")
}
return url
}

Expand Down

0 comments on commit dbc2704

Please sign in to comment.