Skip to content

Instantly share code, notes, and snippets.

@thexande
Created December 20, 2018 05:03
Show Gist options
  • Save thexande/c50915f46a079f06ee3266eca9d2349c to your computer and use it in GitHub Desktop.
Save thexande/c50915f46a079f06ee3266eca9d2349c to your computer and use it in GitHub Desktop.
import XCTest
@testable import Apollo
protocol TestCacheProvider: AnyObject {
static func withCache(initialRecords: RecordSet?,
execute test: (NormalizedCache) throws -> ()) rethrows
}
final class InMemoryTestCacheProvider: TestCacheProvider {
/// Execute a test block rather than return a cache synchronously, since cache setup may be
/// asynchronous at some point.
static func withCache(initialRecords: RecordSet? = nil,
execute test: (NormalizedCache) throws -> ()) rethrows {
let cache = InMemoryNormalizedCache(records: initialRecords ?? [:])
try test(cache)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment