18
18
#import " GoogleUtilities/Environment/Private/GULHeartbeatDateStorage.h"
19
19
20
20
@interface GULHeartbeatDateStorageTest : XCTestCase
21
- @property (nonatomic ) NSURL *fileURL;
22
21
@property (nonatomic ) GULHeartbeatDateStorage *storage;
23
22
@end
24
23
24
+ static NSString *const kTestFileName = @" GULStorageHeartbeatTest" ;
25
+
25
26
@implementation GULHeartbeatDateStorageTest
26
27
27
28
- (void )setUp {
@@ -38,7 +39,10 @@ - (void)setUp {
38
39
error: &error],
39
40
@" Error: %@ " , error);
40
41
}
41
- self.storage = [[GULHeartbeatDateStorage alloc ] initWithFileName: @" GULStorageHeartbeatTest" ];
42
+
43
+ self.storage = [[GULHeartbeatDateStorage alloc ] initWithFileName: kTestFileName ];
44
+
45
+ [self assertInitializationDoesNotAccessFileSystem ];
42
46
}
43
47
44
48
- (void )tearDown {
@@ -53,4 +57,24 @@ - (void)testHeartbeatDateForTag {
53
57
[[self .storage heartbeatDateForTag: @" fire-iid" ] timeIntervalSinceReferenceDate ]);
54
58
}
55
59
60
+ #pragma mark - Private Helpers
61
+
62
+ - (void )assertInitializationDoesNotAccessFileSystem {
63
+ NSURL *fileURL = [self heartbeatFileURL ];
64
+ NSError *error;
65
+ BOOL fileIsReachable = [fileURL checkResourceIsReachableAndReturnError: &error];
66
+ XCTAssertFalse (fileIsReachable,
67
+ @" GULHeartbeatDateStorage initialization should not access the file system." );
68
+ XCTAssertNotNil (error, @" Error: %@ " , error);
69
+ }
70
+
71
+ - (NSURL *)heartbeatFileURL {
72
+ NSString *documentsPath = [NSSearchPathForDirectoriesInDomains (
73
+ NSApplicationSupportDirectory, NSUserDomainMask, YES ) firstObject ];
74
+ NSArray <NSString *> *components = @[ documentsPath, @" Google/FIRApp" , kTestFileName ];
75
+ NSString *fileString = [NSString pathWithComponents: components];
76
+ NSURL *fileURL = [NSURL fileURLWithPath: fileString];
77
+ return fileURL;
78
+ }
79
+
56
80
@end
0 commit comments