FIRCLSFileManagerTests.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2019 Google
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #import <Foundation/Foundation.h>
  15. #import <XCTest/XCTest.h>
  16. #import "FIRCLSMockFileManager.h"
  17. @interface FIRCLSFileManagerTests : XCTestCase {
  18. FIRCLSMockFileManager* _manager;
  19. }
  20. @property(nonatomic, retain, readonly) FIRCLSMockFileManager* manager;
  21. @end
  22. @implementation FIRCLSFileManagerTests
  23. - (void)setUp {
  24. [super setUp];
  25. _manager = [[FIRCLSMockFileManager alloc] init];
  26. [_manager setPathNamespace:@"com.crashlytics.unittests"];
  27. [self removeRootDirectory];
  28. }
  29. - (void)tearDown {
  30. [self removeRootDirectory];
  31. [super tearDown];
  32. }
  33. - (BOOL)removeRootDirectory {
  34. if ([self doesFileExist:[_manager rootPath]]) {
  35. assert([_manager removeItemAtPath:[_manager rootPath]]);
  36. }
  37. return YES;
  38. }
  39. - (void)printPathContents:(NSString*)path {
  40. NSLog(@"%@", [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]);
  41. }
  42. - (BOOL)doesFileExist:(NSString*)path {
  43. return [[NSFileManager defaultManager] fileExistsAtPath:path];
  44. }
  45. - (void)testCreateV4DirectoryStructure {
  46. NSString* path = [[self manager] rootPath];
  47. [[self manager] createReportDirectories];
  48. XCTAssertTrue([self doesFileExist:path], @"");
  49. path = [path stringByAppendingPathComponent:@"v4/reports"];
  50. XCTAssertTrue([self doesFileExist:path], @"");
  51. for (NSString* subpath in @[ @"active", @"prepared", @"processing" ]) {
  52. XCTAssertTrue([self doesFileExist:[path stringByAppendingPathComponent:subpath]], @"");
  53. }
  54. }
  55. @end