代码拉取完成,页面将自动刷新
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Foundation
import Shared
import SwiftyJSON
@testable import Sync
class MockBackoffStorage: BackoffStorage {
var serverBackoffUntilLocalTimestamp: Timestamp?
func clearServerBackoff() {
serverBackoffUntilLocalTimestamp = nil
}
func isInBackoff(_ now: Timestamp) -> Timestamp? {
return nil
}
}
class MockSyncCollectionClient<T: CleartextPayloadJSON>: Sync15CollectionClient<T> {
let uploader: BatchUploadFunction
let infoConfig: InfoConfiguration
init(uploader: @escaping BatchUploadFunction,
infoConfig: InfoConfiguration,
collection: String,
encrypter: RecordEncrypter<T>,
client: Sync15StorageClient = getClient(server: getServer(preStart: { _ in })),
serverURI: URL = URL(string: "http://localhost/collections")!) {
self.uploader = uploader
self.infoConfig = infoConfig
super.init(client: client, serverURI: serverURI, collection: collection, encrypter: encrypter)
}
override func newBatch(ifUnmodifiedSince: Timestamp? = nil, onCollectionUploaded: @escaping (POSTResult, Timestamp?) -> DeferredTimestamp) -> Sync15BatchClient<T> {
return Sync15BatchClient(config: self.infoConfig,
ifUnmodifiedSince: ifUnmodifiedSince,
serializeRecord: self.serializeRecord,
uploader: self.uploader,
onCollectionUploaded: onCollectionUploaded)
}
}
// MARK: Various mocks
// Non-encrypting 'encrypter'.
func getEncrypter() -> RecordEncrypter<CleartextPayloadJSON> {
let serializer: (Record<CleartextPayloadJSON>) -> JSON? = { $0.payload.json }
let factory: (String) -> CleartextPayloadJSON = { CleartextPayloadJSON($0) }
return RecordEncrypter(serializer: serializer, factory: factory)
}
func getClient(server: MockSyncServer) -> Sync15StorageClient {
let url = server.baseURL.asURL!
let authorizer: Authorizer = identity
let queue = DispatchQueue.global(qos: DispatchQoS.background.qosClass)
return Sync15StorageClient(serverURI: url, authorizer: authorizer, workQueue: queue, resultQueue: queue, backoff: MockBackoffStorage())
}
func getServer(username: String = "1234567", preStart: (MockSyncServer) -> Void) -> MockSyncServer {
let server = MockSyncServer(username: username)
preStart(server)
server.start()
return server
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。