-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from PerfectlySoft/ISS-543-New-JSON-Codable
Fixing ISS-543 by appending a new body json interface.
- Loading branch information
Showing
3 changed files
with
25 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,7 +121,22 @@ class PerfectCURLTests: XCTestCase { | |
.addHeader(custom2, ""), | ||
.removeHeader(accept), | ||
.replaceHeader(custom, customValue)) | ||
|
||
|
||
struct Headers: Codable { | ||
var connection = "" | ||
var host = "" | ||
var extra = "" | ||
var extra2 = "" | ||
private enum CodingKeys: String, CodingKey { | ||
case connection = "Connection" | ||
case host = "Host" | ||
case extra = "X-Extra" | ||
case extra2 = "X-Extra-2" | ||
} | ||
} | ||
struct HeaderJSON: Codable { | ||
var headers = Headers() | ||
} | ||
do { | ||
let response = try request.perform() | ||
let json = response.bodyJSON | ||
|
@@ -133,6 +148,8 @@ class PerfectCURLTests: XCTestCase { | |
XCTAssertNil(headers[accept.standardName]) | ||
XCTAssertEqual(customValue, resCustom) | ||
XCTAssertEqual("", resCustom2) | ||
let headerJSON = try response.bodyJSON(HeaderJSON.self) | ||
print(headerJSON) | ||
} catch { | ||
XCTAssert(false, "\(error)") | ||
} | ||
|
@@ -313,47 +330,6 @@ class PerfectCURLTests: XCTestCase { | |
} | ||
self.waitForExpectations(timeout: 10000) | ||
} | ||
|
||
// func testSMTP () { | ||
// var timestamp = time(nil) | ||
// let now = String(cString: asctime(localtime(×tamp))!) | ||
// let sender = "[email protected]" | ||
// let recipient = sender | ||
// let u = UnsafeMutablePointer<UInt8>.allocate(capacity: MemoryLayout<uuid_t>.size) | ||
// uuid_generate_random(u) | ||
// let unu = UnsafeMutablePointer<Int8>.allocate(capacity: 37) | ||
// uuid_unparse_lower(u, unu) | ||
// let uuid = String(validatingUTF8: unu)! | ||
// u.deallocate(capacity: MemoryLayout<uuid_t>.size) | ||
// unu.deallocate(capacity: 37) | ||
// | ||
// let content = "Date: \(now)To: \(recipient)\r\nFrom: \(sender)\r\nCc:\r\nBcc:\r\n" + | ||
// "Message-ID: <\(uuid)@perfect.org>\r\n" + | ||
// "Subject: Hello Perfect-CURL\r\n\r\nSMTP test \(now)\r\n\r\n" | ||
// let curl = CURL(url: "smtp://smtp.gmx.com") | ||
// let _ = curl.setOption(CURLOPT_USERNAME, s: sender) | ||
// let _ = curl.setOption(CURLOPT_PASSWORD, s: "abcd1234") | ||
// let _ = curl.setOption(CURLOPT_MAIL_FROM, s: sender) | ||
// let _ = curl.setOption(CURLOPT_MAIL_RCPT, s: recipient) | ||
// let _ = curl.setOption(CURLOPT_VERBOSE, int: 1) | ||
// let _ = curl.setOption(CURLOPT_UPLOAD, int: 1) | ||
// let _ = curl.setOption(CURLOPT_INFILESIZE, int: content.utf8.count) | ||
// var p:[Int32] = [-1, -1] | ||
// let result = pipe(&p) | ||
// XCTAssertEqual(result, 0) | ||
// let fi = fdopen(p[0], "rb") | ||
// let fo = fdopen(p[1], "wb") | ||
// let w = fwrite(content, 1, content.utf8.count, fo) | ||
// fclose(fo) | ||
// XCTAssertEqual(w, content.utf8.count) | ||
// let _ = curl.setOption(CURLOPT_READDATA, v: fi!) | ||
// let r = curl.performFully() | ||
// print(r.0) | ||
// print(String(cString:r.1)) | ||
// print(String(cString:r.2)) | ||
// fclose(fi) | ||
// XCTAssertEqual(r.0, 0) | ||
// } | ||
|
||
static var allTests : [(String, (PerfectCURLTests) -> () throws -> Void)] { | ||
return [ | ||
|