-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the cURL command to the debug logs
- Loading branch information
1 parent
edfc597
commit 2c72d2c
Showing
2 changed files
with
98 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// CurlLoggingTests.swift | ||
// | ||
// | ||
// Created by Maxence Levelu on 25/01/2021. | ||
// | ||
|
||
import Foundation | ||
import XCTest | ||
|
||
final class CurlLoggingTests: XCTestCase { | ||
|
||
func testLogGet() { | ||
var urlRequest = URLRequest(url: URL(string: "https://jsonplaceholder.typicode.com")!) | ||
urlRequest.httpMethod = "GET" | ||
urlRequest.addValue("token", forHTTPHeaderField: "Authorization") | ||
let result = urlRequest.curlString | ||
XCTAssertEqual(result, "curl \"https://jsonplaceholder.typicode.com\" \\\n\t-H 'Authorization: token'") | ||
} | ||
|
||
func testLogPost() { | ||
var urlRequest = URLRequest(url: URL(string: | ||
"https://jsonplaceholder.typicode.com/posts")!) | ||
urlRequest.httpMethod = "POST" | ||
let jsonString = """ | ||
{"title": "Hello world"} | ||
""" | ||
urlRequest.httpBody = jsonString.data(using: .utf8) | ||
let result = urlRequest.curlString | ||
XCTAssertEqual(result, "curl \"https://jsonplaceholder.typicode.com/posts\" \\\n\t-X POST \\\n\t-d '{\"title\": \"Hello world\"}'") | ||
} | ||
|
||
func testLogPut() { | ||
var urlRequest = URLRequest(url: URL(string: | ||
"https://jsonplaceholder.typicode.com/posts")!) | ||
urlRequest.httpMethod = "PUT" | ||
let jsonString = """ | ||
{"title": "Hello world"} | ||
""" | ||
urlRequest.httpBody = jsonString.data(using: .utf8) | ||
let result = urlRequest.curlString | ||
XCTAssertEqual(result, "curl \"https://jsonplaceholder.typicode.com/posts\" \\\n\t-X PUT \\\n\t-d '{\"title\": \"Hello world\"}'") | ||
} | ||
|
||
func testLogPatch() { | ||
var urlRequest = URLRequest(url: URL(string: | ||
"https://jsonplaceholder.typicode.com/posts")!) | ||
urlRequest.httpMethod = "PATCH" | ||
let jsonString = """ | ||
{"title": "Hello world"} | ||
""" | ||
urlRequest.httpBody = jsonString.data(using: .utf8) | ||
let result = urlRequest.curlString | ||
XCTAssertEqual(result, "curl \"https://jsonplaceholder.typicode.com/posts\" \\\n\t-X PATCH \\\n\t-d '{\"title\": \"Hello world\"}'") | ||
} | ||
|
||
func testLogDelete() { | ||
var urlRequest = URLRequest(url: URL(string: | ||
"https://jsonplaceholder.typicode.com/posts/1")!) | ||
urlRequest.httpMethod = "DELETE" | ||
let result = urlRequest.curlString | ||
XCTAssertEqual(result, "curl \"https://jsonplaceholder.typicode.com/posts/1\" \\\n\t-X DELETE") | ||
} | ||
} |