60 lines
2.6 KiB
Swift
60 lines
2.6 KiB
Swift
//
|
|
// PreferencePersistenceTests.swift
|
|
//
|
|
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
|
|
import Foundation
|
|
import Testing
|
|
|
|
@testable import LuminateCore
|
|
@testable import LuminateStore
|
|
@testable import LuminateUI
|
|
|
|
/// Verifies preference persistence across the UI and SQLite layers.
|
|
@MainActor @Suite struct PreferencePersistenceTests {
|
|
@Test("A preference written through a slot survives flush and reopen without a main-loop turn")
|
|
func survivesFlushAndReopen() async throws {
|
|
let directory = FileManager.default.temporaryDirectory
|
|
.appending(path: "luminate-e2e-\(UUID().uuidString)", directoryHint: .isDirectory)
|
|
defer { try? FileManager.default.removeItem(at: directory) }
|
|
let url = directory.appending(path: "preferences.sqlite")
|
|
|
|
let preferences = Preferences(store: try SQLitePreferenceStore(url: url))
|
|
preferences.slot(for: .serverURL).value = URL(string: "http://jellyfin.test:8096")
|
|
try await preferences.flush()
|
|
|
|
let reopened = try SQLitePreferenceStore(url: url)
|
|
#expect(reopened.initialSnapshot["server.url"] == .text("http://jellyfin.test:8096"))
|
|
}
|
|
|
|
@Test("Bootstrap points the shared coordinator at the on-disk store")
|
|
func bootstrapInstallsSharedCoordinator() async throws {
|
|
let directory = FileManager.default.temporaryDirectory
|
|
.appending(path: "luminate-bootstrap-\(UUID().uuidString)", directoryHint: .isDirectory)
|
|
defer { try? FileManager.default.removeItem(at: directory) }
|
|
let url = directory.appending(path: "preferences.sqlite")
|
|
|
|
Preferences.bootstrap(PreferenceBackend.open(url: url))
|
|
Preferences.shared[.serverURL] = URL(string: "http://jellyfin.test:8096")
|
|
try await Preferences.shared.flush()
|
|
|
|
let reopened = try SQLitePreferenceStore(url: url)
|
|
#expect(reopened.initialSnapshot["server.url"] == .text("http://jellyfin.test:8096"))
|
|
}
|
|
}
|