Summary: - Tests: update tests for AnyStorageKeyTests.swift, AuditTests.swift, LocalDataTests.swift (+13 more) Stats: - 16 files changed, 329 insertions(+), 386 deletions(-)
39 lines
1.3 KiB
Swift
39 lines
1.3 KiB
Swift
import Foundation
|
|
@testable import LocalData
|
|
|
|
struct MockMigration<Value: Codable & Sendable>: StorageMigration {
|
|
let destinationKey: StorageKey<Value>
|
|
let shouldSucceed: Bool
|
|
let shouldMigrateResult: Bool
|
|
let migrationDelay: TimeInterval
|
|
|
|
func shouldMigrate(using router: StorageRouter, context: MigrationContext) async throws -> Bool {
|
|
try await Task.sleep(for: .seconds(0.1))
|
|
return shouldMigrateResult
|
|
}
|
|
|
|
func migrate(using router: StorageRouter, context: MigrationContext) async throws -> MigrationResult {
|
|
try await Task.sleep(for: .seconds(migrationDelay))
|
|
|
|
if shouldSucceed {
|
|
return MigrationResult(success: true, migratedCount: 1)
|
|
}
|
|
|
|
return MigrationResult(
|
|
success: false,
|
|
errors: [.transformationFailed("Mock failure")]
|
|
)
|
|
}
|
|
}
|
|
|
|
struct FailingMigration<Value: Codable & Sendable>: StorageMigration {
|
|
let destinationKey: StorageKey<Value>
|
|
let error: MigrationError
|
|
|
|
func shouldMigrate(using router: StorageRouter, context: MigrationContext) async throws -> Bool { true }
|
|
|
|
func migrate(using router: StorageRouter, context: MigrationContext) async throws -> MigrationResult {
|
|
MigrationResult(success: false, errors: [error])
|
|
}
|
|
}
|