Skip to content

Commit

Permalink
Rework how mock matcher handles missing HTTP method
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Jul 7, 2023
1 parent e94e1f0 commit dbc1a47
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Sources/Pulse/RemoteLogger/RemoteLogger-Protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ struct URLSessionMock: Hashable, Codable {
var method: String?

func isMatch(_ request: URLRequest) -> Bool {
guard request.httpMethod?.uppercased() == method ?? "GET" else {
if let lhs = request.httpMethod, let rhs = method,
lhs.uppercased() != rhs.uppercased() {
return false
}
guard let url = request.url?.absoluteString else {
Expand All @@ -237,8 +238,6 @@ struct URLSessionMock: Hashable, Codable {
}
}

private let schemeRegex = try! Regex(#"^([a-z][a-z0-9+\-.]*)://"#)

struct URLSessionMockedResponse: Codable {
let errorCode: Int?
let statusCode: Int?
Expand Down
9 changes: 9 additions & 0 deletions Tests/PulseTests/URLSessionProxyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,13 @@ final class URLSessionProxyTests: XCTestCase {
let message = try XCTUnwrap(task.message)
XCTAssertEqual(message.label, "network")
}

func testURLSessionMockMatching() {
var request = URLRequest(url: URL(string: "example.com")!)
request.httpMethod = "GET"

XCTAssertTrue(URLSessionMock(mockID: UUID(), pattern: "example.com", method: "GET").isMatch(request))
XCTAssertTrue(URLSessionMock(mockID: UUID(), pattern: "example.com", method: nil).isMatch(request))
XCTAssertFalse(URLSessionMock(mockID: UUID(), pattern: "example.com", method: "POST").isMatch(request))
}
}

0 comments on commit dbc1a47

Please sign in to comment.