Skip to content

Commit

Permalink
Merge pull request #11 from MFB-Technologies-Inc/feature/improve-Mock…
Browse files Browse the repository at this point in the history
…NetworkService-subclassing

Changes methods in MockNetworkService to `open`
  • Loading branch information
roanutil authored Jun 22, 2023
2 parents daf000a + 138ef06 commit 1949153
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Sources/NetworkService/URLRequest+HTTPHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ extension URLRequest.ContentType: HTTPHeader {
public var value: String { rawValue }
}

extension Array where Element: HTTPHeader {
public var asDictionary: [String: String] {
var dict = [String: String]()
dict.reserveCapacity(count)
return reduce(into: dict) { acc, next in
acc[next.key] = next.value
}
}
}

/// Model for HTTP headers
public protocol HTTPHeader {
var key: String { get }
Expand Down
4 changes: 2 additions & 2 deletions Sources/NetworkServiceTestHelper/MockNetworkService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

/// Manages the output queue and returns the new value for reach iteration.
private func queue() throws -> MockOutput {
open func queue() throws -> MockOutput {
guard outputs.count > 0 else {
throw Errors.noOutputQueued
}
Expand All @@ -50,7 +50,7 @@
/// this
/// version of `start`.
/// Delay and repeat are handled here.
public func start(_: URLRequest) async -> Result<Data, Failure> {
open func start(_: URLRequest) async -> Result<Data, Failure> {
let next: MockOutput
do {
next = try queue()
Expand Down

0 comments on commit 1949153

Please sign in to comment.