Add ability to transform values on migrate#228
Conversation
| } | ||
| } | ||
|
|
||
| func test_migrateObjectsMatching_withAccountNameAsData_doesNotRaiseException() throws |
There was a problem hiding this comment.
This test name was incorrect.
Codecov Report
@@ Coverage Diff @@
## master #228 +/- ##
==========================================
+ Coverage 85.68% 86.74% +1.06%
==========================================
Files 15 16 +1
Lines 992 1049 +57
==========================================
+ Hits 850 910 +60
+ Misses 142 139 -3
|
| var keysToMigrate = Set<String>() | ||
| var keyValuePairsToMigrate = [String: Data]() | ||
| for keychainEntry in retrievedItemsToMigrateWithData { | ||
| guard let key = keychainEntry[kSecAttrAccount as String] as? String, key != Keychain.canaryKey else { |
There was a problem hiding this comment.
We'll force the key to be a String later on as part of the compactMap. For now, we just want to make sure we have a key.
fddf1ce to
9ed7cd6
Compare
| XCTAssertNil(valet); | ||
| } | ||
|
|
||
| - (void)test_containsObjectForKey_returnsTrueWhenObjectExistsInKeychain; |
There was a problem hiding this comment.
I realized while I was here that I didn’t have an explicit objective-c test for this wrapper method, so I wrote a couple
|
|
||
| - (BOOL)testEnvironmentIsSigned; | ||
| { | ||
| return NSBundle.mainBundle.bundleIdentifier != nil && ![NSBundle.mainBundle.bundleIdentifier isEqualToString:@"com.apple.dt.xctest.tool"]; |
There was a problem hiding this comment.
This logic is the same logic used in the swift tests
| } | ||
|
|
||
|
|
||
| func test_migrateObjectsMatchingCompactMap_successfullyMigratesTransformedValue() throws { |
There was a problem hiding this comment.
Should we also add a test that transforms the key? (Same for the Valet -> Valet equivalent below)
fdiaz
left a comment
There was a problem hiding this comment.
I mostly looked at the public API 😉
| import Foundation | ||
|
|
||
| /// A struct that represented a key:value pair that can be migrated. | ||
| public struct MigratableKeyValuePair<KeyType: Hashable>: Hashable { |
There was a problem hiding this comment.
Maybe?
| public struct MigratableKeyValuePair<KeyType: Hashable>: Hashable { | |
| public struct MigratableKeyValuePair<Key: Hashable>: Hashable { |
https://swift.org/documentation/api-design-guidelines#name-according-to-roles
|
|
||
| /// A sentinal `ObjectiveCCompatibilityMigratableKeyValuePairOutput` that conveys that the migration should be prevented. | ||
| @objc | ||
| public static func preventMigration() -> ObjectiveCCompatibilityMigratableKeyValuePairOutput { |
There was a problem hiding this comment.
This method sounds to me more than its actually doing the action to prevent migration on an instance rather than creating an instance that prevents the migration.
Maybe migrationDisabled / migrationPrevented?
There was a problem hiding this comment.
Yeah the tough thing here is it isn't super clear that we're doing this work before the migration has started. This is why I wanted to use a future tense. A past-tense phrase here might make it read as if returning it prevented/disabled the migration of just this pair (or future pairs).
In the context where it's used, I hope this method reads well:
Valet/Tests/ValetObjectiveCBridgeTests/VALValetTests.m
Lines 475 to 484 in c7cec75
The documentation on the migrateObjectsMatching Objective-C method also makes it clear how to use this method:
Valet/Sources/Valet/Valet.swift
Lines 661 to 668 in c7cec75
While I agree that reading this method by itself is a bit confusing, I think within the context it's supposed to be used it makes sense? Let me know if not @fdiaz.
There was a problem hiding this comment.
That said, I should make this method available only to Objective-C
Co-authored-by: Nick Entin <entin@squareup.com>
093d029 to
abb6d42
Compare
|
Force push had no functional changes. Only change was branch history after merging |
This PR resolves #226 by adding the ability to
compactMapover key:value pairs as they are being migrated.I do not intend to merge this PR prior to the release of Valet 4.0.