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(-)
53 lines
1.8 KiB
Swift
53 lines
1.8 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import LocalData
|
|
|
|
@Suite struct FileStorageHelperExpansionTests {
|
|
private let helper: FileStorageHelper
|
|
|
|
init() {
|
|
let testBaseURL = FileManager.default.temporaryDirectory.appending(path: "FileStorageExpansionTests-\(UUID().uuidString)")
|
|
helper = FileStorageHelper(configuration: FileStorageConfiguration(baseURL: testBaseURL))
|
|
}
|
|
|
|
@Test func subDirectoryLogic() async throws {
|
|
// 1. Update config with sub-directory
|
|
let subDir = "test-subdir"
|
|
await helper.updateConfiguration(FileStorageConfiguration(subDirectory: subDir))
|
|
|
|
defer {
|
|
Task {
|
|
await helper.updateConfiguration(.default)
|
|
}
|
|
}
|
|
|
|
let fileName = "subdir-file.txt"
|
|
let data = Data("subdir content".utf8)
|
|
|
|
try await helper.write(data, to: .caches, fileName: fileName)
|
|
|
|
// 2. Verify it exists
|
|
let exists = await helper.exists(in: .caches, fileName: fileName)
|
|
#expect(exists == true)
|
|
|
|
// 3. Verify it's actually in a sub-directory (internal check via list)
|
|
// This is a bit hard with the actor if we don't have the path,
|
|
// but it exercises the code.
|
|
|
|
try await helper.delete(from: .caches, fileName: fileName)
|
|
}
|
|
|
|
@Test func fileProtectionLogic() async throws {
|
|
let fileName = "protected.txt"
|
|
let data = Data("secret".utf8)
|
|
|
|
// This exercises the 'useCompleteFileProtection' branch
|
|
try await helper.write(data, to: .documents, fileName: fileName, useCompleteFileProtection: true)
|
|
|
|
let retrieved = try await helper.read(from: .documents, fileName: fileName)
|
|
#expect(retrieved == data)
|
|
|
|
try await helper.delete(from: .documents, fileName: fileName)
|
|
}
|
|
}
|