FIRCLSRolloutsPersistenceManagerTests.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2024 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 "Crashlytics/Crashlytics/Components/FIRCLSContext.h"
  17. #import "Crashlytics/Crashlytics/Controllers/FIRCLSRolloutsPersistenceManager.h"
  18. #import "Crashlytics/Crashlytics/Models/FIRCLSInternalReport.h"
  19. #import "Crashlytics/UnitTests/Mocks/FIRCLSTempMockFileManager.h"
  20. #if SWIFT_PACKAGE
  21. @import FirebaseCrashlyticsSwift;
  22. #else // Swift Package Manager
  23. #import <FirebaseCrashlytics/FirebaseCrashlytics-Swift.h>
  24. #endif // CocoaPods
  25. NSString *reportId = @"1234567";
  26. @interface FIRCLSRolloutsPersistenceManagerTests : XCTestCase
  27. @property(nonatomic, strong) FIRCLSTempMockFileManager *fileManager;
  28. @property(nonatomic, strong) FIRCLSRolloutsPersistenceManager *rolloutsPersistenceManager;
  29. @end
  30. @implementation FIRCLSRolloutsPersistenceManagerTests
  31. - (void)setUp {
  32. [super setUp];
  33. FIRCLSContextBaseInit();
  34. self.fileManager = [[FIRCLSTempMockFileManager alloc] init];
  35. [self.fileManager createReportDirectories];
  36. [self.fileManager setupNewPathForExecutionIdentifier:reportId];
  37. self.rolloutsPersistenceManager =
  38. [[FIRCLSRolloutsPersistenceManager alloc] initWithFileManager:self.fileManager];
  39. }
  40. - (void)tearDown {
  41. [self.fileManager removeItemAtPath:_fileManager.rootPath];
  42. FIRCLSContextBaseDeinit();
  43. [super tearDown];
  44. }
  45. - (void)testUpdateRolloutsStateToPersistenceWithRollouts {
  46. NSString *encodedStateString =
  47. @"{rollouts:[{\"parameter_key\":\"6d795f66656174757265\",\"parameter_value\":"
  48. @"\"e8bf99e698af7468656d6973e79a84e6b58be8af95e695b0e68daeefbc8ce8be93e585a5e4b8ade69687\","
  49. @"\"rollout_id\":\"726f6c6c6f75745f31\",\"template_version\":1,\"variant_id\":"
  50. @"\"636f6e74726f6c\"}]}";
  51. NSData *data = [encodedStateString dataUsingEncoding:NSUTF8StringEncoding];
  52. NSString *rolloutsFilePath =
  53. [[[self.fileManager activePath] stringByAppendingPathComponent:reportId]
  54. stringByAppendingPathComponent:FIRCLSReportRolloutsFile];
  55. [self.rolloutsPersistenceManager updateRolloutsStateToPersistenceWithRollouts:data
  56. reportID:reportId];
  57. XCTAssertTrue([[NSFileManager defaultManager] fileExistsAtPath:rolloutsFilePath]);
  58. }
  59. @end