Skip to content

Commit

Permalink
Make defaultFileStatePath non-computed
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLeif committed Feb 2, 2024
1 parent 48c384d commit fd14723
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -17,7 +17,7 @@ extension FileManager {
#else
return "\(path.path)/App"
#endif
}
}()

/// Creates a directory at the specified path.
///
Expand Down
8 changes: 6 additions & 2 deletions Tests/AppStateTests/FileStateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import XCTest

fileprivate extension Application {
var storedValue: FileState<Int?> {
fileState(path: "./AppStateTests", filename: "storedValue")
fileState(filename: "storedValue")
}

var storedString: FileState<String?> {
fileState(path: "./AppStateTests", filename: "storedString", isBase64Encoded: false)
fileState(filename: "storedString", isBase64Encoded: false)
}
}

Expand Down Expand Up @@ -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() {
Expand All @@ -52,6 +54,7 @@ final class FileStateTests: XCTestCase {
}

func testFileState() {
XCTAssertEqual(FileManager.defaultFileStatePath, "./AppStateTests")
XCTAssertNil(Application.fileState(\.storedValue).value)
XCTAssertNil(Application.fileState(\.storedString).value)

Expand All @@ -76,6 +79,7 @@ final class FileStateTests: XCTestCase {
}

func testStoringViewModel() {
XCTAssertEqual(FileManager.defaultFileStatePath, "./AppStateTests")
XCTAssertNil(Application.fileState(\.storedValue).value)
XCTAssertNil(Application.fileState(\.storedString).value)

Expand Down

0 comments on commit fd14723

Please sign in to comment.