PasswordStore: allow to pass in a specific PGPAgent implementation (for testing)

This commit is contained in:
Lysann Tranvouez 2026-03-11 23:25:46 +01:00
parent 77f85ccdd1
commit e3de11f71c
3 changed files with 15 additions and 10 deletions

View file

@ -15,15 +15,18 @@ import XCTest
final class PasswordStoreTest: XCTestCase {
private let localRepoURL: URL = Globals.sharedContainerURL.appendingPathComponent("Library/password-store-test/")
private var pgpAgent: PGPAgent! = nil
private var passwordStore: PasswordStore! = nil
override func setUp() {
passwordStore = PasswordStore(url: localRepoURL)
pgpAgent = PGPAgent()
passwordStore = PasswordStore(url: localRepoURL, pgpAgent: pgpAgent)
}
override func tearDown() {
passwordStore.erase()
passwordStore = nil
pgpAgent = nil
Defaults.removeAll()
}
@ -78,7 +81,7 @@ final class PasswordStoreTest: XCTestCase {
XCTAssertTrue(AppKeychain.shared.contains(key: PGPKey.PUBLIC.getKeychainKey()))
XCTAssertEqual(Defaults.gitSignatureName, "Test User")
XCTAssertTrue(PasscodeLock.shared.hasPasscode)
XCTAssertTrue(PGPAgent.shared.isInitialized())
XCTAssertTrue(pgpAgent.isInitialized())
expectation(forNotification: .passwordStoreUpdated, object: nil)
expectation(forNotification: .passwordStoreErased, object: nil)
@ -88,7 +91,7 @@ final class PasswordStoreTest: XCTestCase {
XCTAssertFalse(AppKeychain.shared.contains(key: PGPKey.PUBLIC.getKeychainKey()))
XCTAssertFalse(Defaults.hasKey(\.gitSignatureName))
XCTAssertFalse(PasscodeLock.shared.hasPasscode)
XCTAssertFalse(PGPAgent.shared.isInitialized())
XCTAssertFalse(pgpAgent.isInitialized())
waitForExpectations(timeout: 1, handler: nil)
}