Skip to content

Commit 5874de7

Browse files
committed
Review
1 parent 881f605 commit 5874de7

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

FirebaseDatabase/Tests/Unit/FLevelDBStorageEngineTests.m

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -692,31 +692,45 @@ - (void)testEnsureDirSetsCorrectFileProtection {
692692
NSString *testDirName =
693693
[NSString stringWithFormat:@"fdb_persistence_test_%lu", (unsigned long)arc4random()];
694694
NSString *testPath = [NSTemporaryDirectory() stringByAppendingPathComponent:testDirName];
695+
NSFileManager *fileManager = [NSFileManager defaultManager];
695696

696-
// Ensure the directory doesn't exist before the test
697-
[[NSFileManager defaultManager] removeItemAtPath:testPath error:nil];
698-
699-
// Call the method to create the directory
697+
// --- Test creation ---
698+
[fileManager removeItemAtPath:testPath error:nil];
700699
[FLevelDBStorageEngine ensureDir:testPath markAsDoNotBackup:NO];
701700

702-
// Get the attributes of the created directory
703701
NSError *error = nil;
704-
NSDictionary<NSFileAttributeKey, id> *attributes =
705-
[[NSFileManager defaultManager] attributesOfItemAtPath:testPath error:&error];
706-
707-
// Assert that the file protection attribute is correct
702+
NSDictionary<NSFileAttributeKey, id> *attributes = [fileManager attributesOfItemAtPath:testPath
703+
error:&error];
708704
XCTAssertNil(error, @"Failed to get attributes of directory: %@", error);
709705

710706
#if !TARGET_OS_SIMULATOR
711707
// On a physical device, file protection should be set.
712708
XCTAssertEqualObjects(attributes[NSFileProtectionKey],
713709
NSFileProtectionCompleteUntilFirstUserAuthentication);
714710
#else
715-
// In the simulator, file protection is not supported, so the key should be nil.
716711
XCTAssertNil(attributes[NSFileProtectionKey]);
717712
#endif
718713

714+
// --- Test update on existing directory ---
715+
#if !TARGET_OS_SIMULATOR
716+
// This part of the test is only relevant on devices where file protection is supported.
717+
[fileManager removeItemAtPath:testPath error:nil];
718+
NSDictionary *initialAttributes = @{NSFileProtectionKey : NSFileProtectionNone};
719+
XCTAssertTrue([fileManager createDirectoryAtPath:testPath
720+
withIntermediateDirectories:YES
721+
attributes:initialAttributes
722+
error:&error],
723+
@"Failed to create directory for update test: %@", error);
724+
725+
[FLevelDBStorageEngine ensureDir:testPath markAsDoNotBackup:NO];
726+
727+
attributes = [fileManager attributesOfItemAtPath:testPath error:&error];
728+
XCTAssertNil(error, @"Failed to get attributes after update: %@", error);
729+
XCTAssertEqualObjects(attributes[NSFileProtectionKey],
730+
NSFileProtectionCompleteUntilFirstUserAuthentication);
731+
#endif // !TARGET_OS_SIMULATOR
732+
719733
// Clean up
720-
[[NSFileManager defaultManager] removeItemAtPath:testPath error:nil];
734+
[fileManager removeItemAtPath:testPath error:nil];
721735
}
722736
@end

0 commit comments

Comments
 (0)