Refactoring
This commit is contained in:
@@ -4,7 +4,7 @@ import DataLiteC
|
||||
import DataLiteCore
|
||||
import DataRaft
|
||||
|
||||
class DatabaseServiceTests: DatabaseServiceKeyProvider, @unchecked Sendable {
|
||||
class DatabaseServiceTests: ConnectionServiceKeyProvider, @unchecked Sendable {
|
||||
private let keyOne = Connection.Key.rawKey(Data([
|
||||
0xe8, 0xd7, 0x92, 0xa2, 0xa1, 0x35, 0x56, 0xc0,
|
||||
0xfd, 0xbb, 0x2f, 0x91, 0xe8, 0x0b, 0x4b, 0x2a,
|
||||
@@ -54,13 +54,16 @@ class DatabaseServiceTests: DatabaseServiceKeyProvider, @unchecked Sendable {
|
||||
try? FileManager.default.removeItem(at: fileURL)
|
||||
}
|
||||
|
||||
func databaseService(keyFor service: any DatabaseServiceProtocol) throws -> Connection.Key {
|
||||
func connectionService(keyFor service: any ConnectionServiceProtocol) throws -> Connection.Key {
|
||||
currentKey
|
||||
}
|
||||
|
||||
func databaseService(shouldReconnect service: any DatabaseServiceProtocol) -> Bool {
|
||||
func connectionService(shouldReconnect service: any ConnectionServiceProtocol) -> Bool {
|
||||
true
|
||||
}
|
||||
|
||||
func connectionService(_ service: any ConnectionServiceProtocol, didReceive error: any Error) {
|
||||
}
|
||||
}
|
||||
|
||||
extension DatabaseServiceTests {
|
||||
@@ -138,8 +141,8 @@ extension DatabaseServiceTests {
|
||||
path: fileURL.path,
|
||||
options: [.readwrite]
|
||||
)
|
||||
try connection.apply(currentKey)
|
||||
try connection.rekey(keyTwo)
|
||||
try connection.apply(currentKey, name: nil)
|
||||
try connection.rekey(keyTwo, name: nil)
|
||||
currentKey = keyTwo
|
||||
|
||||
try service.perform(in: .deferred) { connection in
|
||||
@@ -166,9 +169,9 @@ extension DatabaseServiceTests {
|
||||
path: fileURL.path,
|
||||
options: [.readwrite]
|
||||
)
|
||||
try connection.apply(currentKey)
|
||||
try connection.rekey(keyTwo)
|
||||
let error = Connection.Error(
|
||||
try connection.apply(currentKey, name: nil)
|
||||
try connection.rekey(keyTwo, name: nil)
|
||||
let error = SQLiteError(
|
||||
code: SQLITE_NOTADB,
|
||||
message: "file is not a database"
|
||||
)
|
||||
|
||||
@@ -3,7 +3,7 @@ import DataLiteCore
|
||||
@testable import DataRaft
|
||||
|
||||
@Suite struct MigrationServiceTests {
|
||||
private typealias MigrationService = DataRaft.MigrationService<DatabaseService, VersionStorage>
|
||||
private typealias MigrationService = DataRaft.MigrationService<VersionStorage>
|
||||
private typealias MigrationError = DataRaft.MigrationError<MigrationService.Version>
|
||||
|
||||
private var connection: Connection!
|
||||
@@ -12,7 +12,7 @@ import DataLiteCore
|
||||
init() throws {
|
||||
let connection = try Connection(location: .inMemory, options: .readwrite)
|
||||
self.connection = connection
|
||||
self.migrationService = .init(service: .init(connection: connection), storage: .init())
|
||||
self.migrationService = .init(connection: connection)
|
||||
}
|
||||
|
||||
@Test func addMigration() throws {
|
||||
@@ -68,7 +68,7 @@ import DataLiteCore
|
||||
@Test func migrateEmpty() async throws {
|
||||
let migration1 = Migration<Int32>(version: 1, byResource: "migration_1", extension: "sql", in: .module)!
|
||||
let migration2 = Migration<Int32>(version: 2, byResource: "migration_2", extension: "sql", in: .module)!
|
||||
let migration4 = Migration<Int32>(version: 4, byResource: "migration_4", extension: "sql", in: .module)!
|
||||
let migration4 = Migration<Int32>(version: 4, byResource: "empty", extension: "sql", in: .module)!
|
||||
|
||||
try migrationService.add(migration1)
|
||||
try migrationService.add(migration2)
|
||||
@@ -91,11 +91,11 @@ private extension MigrationServiceTests {
|
||||
struct VersionStorage: DataRaft.VersionStorage {
|
||||
typealias Version = Int32
|
||||
|
||||
func getVersion(_ connection: Connection) throws -> Version {
|
||||
func getVersion(_ connection: ConnectionProtocol) throws -> Version {
|
||||
connection.userVersion
|
||||
}
|
||||
|
||||
func setVersion(_ connection: Connection, _ version: Version) throws {
|
||||
func setVersion(_ connection: ConnectionProtocol, _ version: Version) throws {
|
||||
connection.userVersion = version
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user