Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort HTTP methods to remove randomness from keys #149

Merged
merged 2 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/Mocker/Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ public struct Mock: Equatable {
}

public static func == (lhs: Mock, rhs: Mock) -> Bool {
let lhsHTTPMethods: [String] = lhs.data.keys.compactMap { $0.rawValue }
let rhsHTTPMethods: [String] = rhs.data.keys.compactMap { $0.rawValue }
let lhsHTTPMethods: [String] = lhs.data.keys.compactMap { $0.rawValue }.sorted()
let rhsHTTPMethods: [String] = rhs.data.keys.compactMap { $0.rawValue }.sorted()

if let lhsFileExtensions = lhs.fileExtensions, let rhsFileExtensions = rhs.fileExtensions, (!lhsFileExtensions.isEmpty || !rhsFileExtensions.isEmpty) {
/// The mocks are targeting file extensions specifically, check on those.
Expand Down
9 changes: 9 additions & 0 deletions Tests/MockerTests/MockTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,13 @@ final class MockTests: XCTestCase {
XCTAssertEqual(mock200, mock400)
XCTAssertNotEqual(mock200, mockJPEG)
}

func testMethodsComparing() {
let url = URL(string: "https://mocked.wetransfer.com")!

let methods = [Mock.HTTPMethod.options, .get, .head, .post, .put, .patch, .delete, .trace, .connect]
let first = Mock(url: url, statusCode: 200, data: Dictionary(uniqueKeysWithValues: methods.shuffled().map { ($0, Data()) }))
let second = Mock(url: url, statusCode: 200, data: Dictionary(uniqueKeysWithValues: methods.shuffled().map { ($0, Data()) }))
XCTAssertEqual(first, second)
}
}