Skip to content

Commit

Permalink
Use throws in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danielctull committed Mar 22, 2024
1 parent 6333f8a commit 0d79a92
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions Tests/ResourcefulTests/ResourceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,51 @@ import FoundationNetworking
final class ResourceTests: XCTestCase {

func testInit() throws {
let resource = Resource(request: request) { _ in return "Hello" }
XCTAssertEqual(try resource.request, request)
XCTAssertEqual(try resource.value(for: response), "Hello")
let resource = try Resource(request: request) { _ in return "Hello" }
try XCTAssertEqual(resource.request, request)
try XCTAssertEqual(resource.value(for: response), "Hello")
}

func testMapRequest() {
let resource = Resource(request: request) { _ in return 20 }
func testMapRequest() throws {
let resource = try Resource(request: request) { _ in return 20 }
.mapRequest { request in
URLRequest(url: request.url!.appendingPathComponent("test"))

Check warning on line 20 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Force Unwrapping Violation: Force unwrapping should be avoided. (force_unwrapping)

Check warning on line 20 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Force Unwrapping Violation: Force unwrapping should be avoided. (force_unwrapping)
}
XCTAssertEqual(try resource.request.url, url.appendingPathComponent("test"))
try XCTAssertEqual(try resource.request.url, url.appendingPathComponent("test"))
}

func testModifyRequest() {
let resource = Resource(request: request) { _ in return 20 }
func testModifyRequest() throws {
let resource = try Resource(request: request) { _ in return 20 }
.modifyRequest { $0.url?.appendPathComponent("test") }
XCTAssertEqual(try resource.request.url, url.appendingPathComponent("test"))
try XCTAssertEqual(resource.request.url, url.appendingPathComponent("test"))
}

func testTryMap() {
let integer = Resource(request: request) { _ in return 20 }
func testTryMap() throws {
let integer = try Resource(request: request) { _ in return 20 }
let string = integer.tryMap { String($0) }
XCTAssertEqual(try integer.value(for: response), 20)
XCTAssertEqual(try string.value(for: response), "20")
}

// swiftlint:disable force_unwrapping
private var url: URL { return URL(string: "http://example.com")! }
// swiftlint:enable force_unwrapping
private var url: URL {
get throws { try XCTUnwrap(URL(string: "http://example.com")) }

Check warning on line 39 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)

Check warning on line 39 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)
}

private var request: URLRequest {
get throws { try URLRequest(url: url) }

Check warning on line 43 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)

Check warning on line 43 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)
}

private var request: URLRequest { return URLRequest(url: url) }
private var response: (Data, URLResponse) {
return (Data(), URLResponse(url: url,
mimeType: nil,
expectedContentLength: 0,
textEncodingName: nil))
private var response: Resource.Response {
get throws {

Check warning on line 47 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)

Check warning on line 47 in Tests/ResourcefulTests/ResourceTests.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Implicit Getter Violation: Computed read-only properties should avoid using the get keyword. (implicit_getter)
try (
Data(),
URLResponse(
url: url,
mimeType: nil,
expectedContentLength: 0,
textEncodingName: nil
)
)
}
}
}

0 comments on commit 0d79a92

Please sign in to comment.