-
-
Notifications
You must be signed in to change notification settings - Fork 116
Improve test coverage #711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lysanntranvouez
wants to merge
21
commits into
mssun:master
Choose a base branch
from
lysanntranvouez:feature/more-tests-pr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
17b6bb8
fix test cleanup
85972a0
include repo as text fixture, no need to clone from actual github
ef188fc
basic core data tests upon clone
60999c7
more tests: entity fetching + erase
e5650ec
add encrypt-save-decrypt roundtrip test
98ad323
check notification center notifications
12c8c04
test add, edit, delete
9864624
fix deleting directory
c3bfa86
check file system and commits upon changes to store
e195280
test resetting local changes
e1da198
add save and decrypt round trip
c6a4f80
add initPasswordEntityCoreData tests
4c21ab9
add tests for AppKeychain
cde82d9
rename file to match contained class
b8b7e1f
PersistenceController tests
55b682b
improve directory deletion/editing handling
fe283c9
fixup! improve directory deletion/editing handling
48ae610
fixup! PersistenceController tests
778d649
PersistenceController.init default URL is explicit
5dfd3ef
fixup! more tests: entity fetching + erase
348b86f
fixup! PersistenceController tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // | ||
| // PersistenceControllerTest.swift | ||
| // passKitTests | ||
| // | ||
| // Created by Lysann Tranvouez on 9/3/26. | ||
| // Copyright © 2026 Bob Sun. All rights reserved. | ||
| // | ||
|
|
||
| import CoreData | ||
| import XCTest | ||
|
|
||
| @testable import passKit | ||
|
|
||
| final class PersistenceControllerTest: XCTestCase { | ||
| func testModelLoads() { | ||
| let controller = PersistenceController.forUnitTests() | ||
| let context = controller.viewContext() | ||
|
|
||
| let entityNames = context.persistentStoreCoordinator!.managedObjectModel.entities.map(\.name) | ||
| XCTAssertEqual(entityNames, ["PasswordEntity"]) | ||
| } | ||
|
|
||
| func testInsertAndFetch() { | ||
| let controller = PersistenceController.forUnitTests() | ||
| let context = controller.viewContext() | ||
| XCTAssertEqual(PasswordEntity.fetchAll(in: context).count, 0) | ||
|
|
||
| PasswordEntity.insert(name: "test", path: "test.gpg", isDir: false, into: context) | ||
| try? context.save() | ||
|
|
||
| XCTAssertEqual(PasswordEntity.fetchAll(in: context).count, 1) | ||
| } | ||
|
|
||
| func testReinitializePersistentStoreClearsData() { | ||
| let controller = PersistenceController.forUnitTests() | ||
| let context = controller.viewContext() | ||
|
|
||
| PasswordEntity.insert(name: "test1", path: "test1.gpg", isDir: false, into: context) | ||
| PasswordEntity.insert(name: "test2", path: "test2.gpg", isDir: false, into: context) | ||
| try? context.save() | ||
| XCTAssertEqual(PasswordEntity.fetchAll(in: context).count, 2) | ||
|
|
||
| controller.reinitializePersistentStore() | ||
|
|
||
| // After reinitialize, old data should be gone | ||
| // (reinitializePersistentStore calls initPasswordEntityCoreData with the default repo URL, | ||
| // which won't exist in tests, so the result should be an empty store) | ||
| let remaining = PasswordEntity.fetchAll(in: context) | ||
| XCTAssertEqual(remaining.count, 0) | ||
| } | ||
|
|
||
| func testMultipleControllersAreIndependent() { | ||
| let controller1 = PersistenceController.forUnitTests() | ||
| let controller2 = PersistenceController.forUnitTests() | ||
|
|
||
| let context1 = controller1.viewContext() | ||
| let context2 = controller2.viewContext() | ||
|
|
||
| PasswordEntity.insert(name: "only-in-1", path: "only-in-1.gpg", isDir: false, into: context1) | ||
| try? context1.save() | ||
|
|
||
| XCTAssertEqual(PasswordEntity.fetchAll(in: context1).count, 1) | ||
| XCTAssertEqual(PasswordEntity.fetchAll(in: context2).count, 0) | ||
| } | ||
|
|
||
| func testSaveAndLoadFromFile() throws { | ||
| let tempDir = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString) | ||
| try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) | ||
| defer { try? FileManager.default.removeItem(at: tempDir) } | ||
| let storeURL = tempDir.appendingPathComponent("test.sqlite") | ||
|
|
||
| // Write | ||
| let controller1 = PersistenceController(storeURL: storeURL) | ||
| let context1 = controller1.viewContext() | ||
| PasswordEntity.insert(name: "saved", path: "saved.gpg", isDir: false, into: context1) | ||
| PasswordEntity.insert(name: "dir", path: "dir", isDir: true, into: context1) | ||
| controller1.save() | ||
|
|
||
| // Load in a fresh controller from the same file | ||
| let controller2 = PersistenceController(storeURL: storeURL) | ||
| let context2 = controller2.viewContext() | ||
| let allEntities = PasswordEntity.fetchAll(in: context2) | ||
|
|
||
| XCTAssertEqual(allEntities.count, 2) | ||
| XCTAssertNotNil(allEntities.first { $0.name == "saved" && !$0.isDir }) | ||
| XCTAssertNotNil(allEntities.first { $0.name == "dir" && $0.isDir }) | ||
| } | ||
|
|
||
| func testSaveError() throws { | ||
|
Check failure on line 89 in passKitTests/Controllers/PersistenceControllerTest.swift
|
||
| // NOTE: save() calls fatalError on Core Data save failures, so error propagation | ||
| // cannot be tested without refactoring save() to throw... | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.