Summary: - Sources: update Configuration, Helpers, Models (+1 more) - Tests: update tests for AppGroupTests.swift, FileStorageHelperExpansionTests.swift, FileStorageHelperTests.swift (+7 more) Stats: - 18 files changed, 306 insertions(+), 58 deletions(-)
58 lines
1.9 KiB
Swift
58 lines
1.9 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import LocalData
|
|
|
|
@Suite struct SyncHelperTests {
|
|
private let helper = SyncHelper()
|
|
|
|
@Test func syncPolicyNeverDoesNothing() async throws {
|
|
// This should return early without doing anything
|
|
try await helper.syncIfNeeded(
|
|
data: Data("test".utf8),
|
|
keyName: "test.key",
|
|
availability: .all,
|
|
syncPolicy: .never
|
|
)
|
|
}
|
|
|
|
@Test func syncPolicyAutomaticSmallThrowsIfTooLarge() async throws {
|
|
let config = SyncConfiguration(maxAutoSyncSize: 10)
|
|
let localHelper = SyncHelper(configuration: config)
|
|
|
|
let largeData = Data(repeating: 0, count: 100)
|
|
|
|
await #expect(throws: StorageError.dataTooLargeForSync) {
|
|
try await localHelper.syncIfNeeded(
|
|
data: largeData,
|
|
keyName: "too.large",
|
|
availability: .all,
|
|
syncPolicy: .automaticSmall
|
|
)
|
|
}
|
|
}
|
|
|
|
@Test func syncPolicyAutomaticSmallPassesIfSmall() async throws {
|
|
let config = SyncConfiguration(maxAutoSyncSize: 1000)
|
|
await helper.updateConfiguration(config)
|
|
|
|
let smallData = Data(repeating: 0, count: 10)
|
|
|
|
// This should not throw StorageError.dataTooLargeForSync
|
|
// It might return early due to WCSession not being supported/active in tests,
|
|
// which is fine for covering the policy check logic.
|
|
try await helper.syncIfNeeded(
|
|
data: smallData,
|
|
keyName: "small.key",
|
|
availability: .all,
|
|
syncPolicy: .automaticSmall
|
|
)
|
|
}
|
|
|
|
@Test func syncAvailabilityChecksPlatform() async {
|
|
let available = await helper.isSyncAvailable()
|
|
// In a simulator environment without a paired watch, this is likely false
|
|
// But we are exercising the code path.
|
|
#expect(available == available)
|
|
}
|
|
}
|