LocalData/Tests/LocalDataTests/Mocks/MockMigration.swift
Matt Bruce c2b17a4b7f Update Migrations, Models, Protocols (+2 more) + tests + docs
Summary:
- Sources: Migrations, Models, Protocols, Services, Utilities
- Tests: AnyStorageKeyTests.swift, MigrationAdditionalTests.swift, MigrationIntegrationTests.swift, MigrationProtocolTests.swift, MigrationTests.swift (+1 more)
- Docs: Migration, Migration_Refactor_Plan_Clean, Proposal, README
- Added symbols: struct MyMigration, typealias DestinationKey, func shouldMigrate, func migrate, extension MyNewKey, protocol StorageMigration (+74 more)
- Removed symbols: enum StorageDomain, func migrate, func validatePlatformAvailability, func deserialize, func applySecurity, func retrieve (+1 more)

Stats:
- 31 files changed, 2820 insertions(+), 80 deletions(-)
2026-01-18 14:53:30 -06:00

43 lines
1.3 KiB
Swift

import Foundation
@testable import LocalData
struct MockMigration<Destination: StorageKey>: StorageMigration {
typealias DestinationKey = Destination
let destinationKey: Destination
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<Destination: StorageKey>: StorageMigration {
typealias DestinationKey = Destination
let destinationKey: Destination
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])
}
}