From fd14723343af8a649312d8bef13b86844dc48d57 Mon Sep 17 00:00:00 2001 From: Leif Date: Thu, 1 Feb 2024 17:04:19 -0700 Subject: [PATCH] Make defaultFileStatePath non-computed --- .../Application/Types/Helper/FileManager+AppState.swift | 6 +++--- Tests/AppStateTests/FileStateTests.swift | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Sources/AppState/Application/Types/Helper/FileManager+AppState.swift b/Sources/AppState/Application/Types/Helper/FileManager+AppState.swift index cab9281..1a09229 100644 --- a/Sources/AppState/Application/Types/Helper/FileManager+AppState.swift +++ b/Sources/AppState/Application/Types/Helper/FileManager+AppState.swift @@ -1,8 +1,8 @@ import Foundation extension FileManager { - /// Gets the documentDirectory from FileManager and appends "/App". Otherwise if it can not get the documents directory is will return "~/App". - public static var defaultFileStatePath: String { + /// Gets the documentDirectory from FileManager and appends "/App". Otherwise if it can not get the documents directory is will return "~/App". This variable can be set to whatever path you want to be the default. + public static var defaultFileStatePath: String = { let fileManager: FileManager = Application.dependency(\.fileManager) guard let path = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first else { return "~/App" @@ -17,7 +17,7 @@ extension FileManager { #else return "\(path.path)/App" #endif - } + }() /// Creates a directory at the specified path. /// diff --git a/Tests/AppStateTests/FileStateTests.swift b/Tests/AppStateTests/FileStateTests.swift index a6e1477..80f8065 100644 --- a/Tests/AppStateTests/FileStateTests.swift +++ b/Tests/AppStateTests/FileStateTests.swift @@ -7,11 +7,11 @@ import XCTest fileprivate extension Application { var storedValue: FileState { - fileState(path: "./AppStateTests", filename: "storedValue") + fileState(filename: "storedValue") } var storedString: FileState { - fileState(path: "./AppStateTests", filename: "storedString", isBase64Encoded: false) + fileState(filename: "storedString", isBase64Encoded: false) } } @@ -44,6 +44,8 @@ extension ExampleStoringViewModel: ObservableObject { } final class FileStateTests: XCTestCase { override class func setUp() { Application.logging(isEnabled: true) + + FileManager.defaultFileStatePath = "./AppStateTests" } override class func tearDown() { @@ -52,6 +54,7 @@ final class FileStateTests: XCTestCase { } func testFileState() { + XCTAssertEqual(FileManager.defaultFileStatePath, "./AppStateTests") XCTAssertNil(Application.fileState(\.storedValue).value) XCTAssertNil(Application.fileState(\.storedString).value) @@ -76,6 +79,7 @@ final class FileStateTests: XCTestCase { } func testStoringViewModel() { + XCTAssertEqual(FileManager.defaultFileStatePath, "./AppStateTests") XCTAssertNil(Application.fileState(\.storedValue).value) XCTAssertNil(Application.fileState(\.storedString).value)