From 7f3d097b323b49ed33ec46ef4013bf0dce88a9de Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 24 Feb 2022 17:58:45 -0800 Subject: [PATCH 01/32] created RollbarCocoaLumberjack package project --- RollbarCocoaLumberjack/.gitignore | 7 +++++ RollbarCocoaLumberjack/Package.swift | 28 +++++++++++++++++++ RollbarCocoaLumberjack/README.md | 9 ++++++ .../RollbarCocoaLumberjack.swift | 6 ++++ .../RollbarCocoaLumberjackTests.swift | 11 ++++++++ 5 files changed, 61 insertions(+) create mode 100644 RollbarCocoaLumberjack/.gitignore create mode 100644 RollbarCocoaLumberjack/Package.swift create mode 100644 RollbarCocoaLumberjack/README.md create mode 100644 RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift create mode 100644 RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift diff --git a/RollbarCocoaLumberjack/.gitignore b/RollbarCocoaLumberjack/.gitignore new file mode 100644 index 00000000..bb460e7b --- /dev/null +++ b/RollbarCocoaLumberjack/.gitignore @@ -0,0 +1,7 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ +DerivedData/ +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata diff --git a/RollbarCocoaLumberjack/Package.swift b/RollbarCocoaLumberjack/Package.swift new file mode 100644 index 00000000..435ccbd7 --- /dev/null +++ b/RollbarCocoaLumberjack/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.5 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "RollbarCocoaLumberjack", + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "RollbarCocoaLumberjack", + targets: ["RollbarCocoaLumberjack"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "RollbarCocoaLumberjack", + dependencies: []), + .testTarget( + name: "RollbarCocoaLumberjackTests", + dependencies: ["RollbarCocoaLumberjack"]), + ] +) diff --git a/RollbarCocoaLumberjack/README.md b/RollbarCocoaLumberjack/README.md new file mode 100644 index 00000000..b1601be9 --- /dev/null +++ b/RollbarCocoaLumberjack/README.md @@ -0,0 +1,9 @@ +# RollbarCocoaLumberjack + + +This SDK module implements integration of Rollbar into the popular CocoaLumberjack logging framework. + +So if you either already use CocoaLumberjack or you are planning to use it for your software product logging needs, +then you can easily integrate Rollbar into it via this module and have all or some of the logs performed via the +CocoaLumberjack framework redirected into a dedicated Rollbar project at www.rollbar.com and monitor the health of +your own software product/service remotely. diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift new file mode 100644 index 00000000..1967e5a1 --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift @@ -0,0 +1,6 @@ +public struct RollbarCocoaLumberjack { + public private(set) var text = "Hello, World!" + + public init() { + } +} diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift new file mode 100644 index 00000000..49535d92 --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -0,0 +1,11 @@ +import XCTest +@testable import RollbarCocoaLumberjack + +final class RollbarCocoaLumberjackTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + XCTAssertEqual(RollbarCocoaLumberjack().text, "Hello, World!") + } +} From 56a5e8306de0104c0e6dd66e92044f3395824e84 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 24 Feb 2022 18:05:40 -0800 Subject: [PATCH 02/32] added CocoaLumberjack package project to the SDK workspace --- RollbarSDK.xcworkspace/contents.xcworkspacedata | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RollbarSDK.xcworkspace/contents.xcworkspacedata b/RollbarSDK.xcworkspace/contents.xcworkspacedata index c834da3e..73e5248d 100644 --- a/RollbarSDK.xcworkspace/contents.xcworkspacedata +++ b/RollbarSDK.xcworkspace/contents.xcworkspacedata @@ -81,6 +81,9 @@ + + From 5cc81e7d0643c27d553492037ffcd0d4140e7ccc Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Sat, 26 Feb 2022 01:29:05 -0800 Subject: [PATCH 03/32] feat: basic package and manifest configuration for RollbarCocoaLumberjack --- Package.swift | 52 +++++++++++-- .../xcschemes/RollbarCocoaLumberjack.xcscheme | 77 +++++++++++++++++++ RollbarCocoaLumberjack/Package.swift | 50 +++++++++++- RollbarCocoaLumberjack/Tests/LinuxMain.swift | 7 ++ .../RollbarCocoaLumberjackTests.m | 16 ++++ .../xcshareddata/swiftpm/Package.resolved | 18 +++++ 6 files changed, 211 insertions(+), 9 deletions(-) create mode 100644 RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme create mode 100644 RollbarCocoaLumberjack/Tests/LinuxMain.swift create mode 100644 RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m diff --git a/Package.swift b/Package.swift index 6feec7ba..a1b62311 100644 --- a/Package.swift +++ b/Package.swift @@ -35,6 +35,9 @@ let package = Package( .library( name: "RollbarSwift", targets: ["RollbarSwift"]), + .library( + name: "RollbarCocoaLumberjack", + targets: ["RollbarCocoaLumberjack"]), ], dependencies: [ // Dependencies declare other packages that this package depends on. @@ -47,13 +50,18 @@ let package = Package( url: "https://github.com/microsoft/plcrashreporter.git", from: "1.10.0" //Package.Dependency.Requirement.branch("master") ), + .package(name:"CocoaLumberjack", + url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", + from: "3.7.4" //Package.Dependency.Requirement.branch("master") + ), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "RollbarCommon", - dependencies: [], + dependencies: [ + ], path: "RollbarCommon/Sources/RollbarCommon", publicHeadersPath: "include", cSettings: [ @@ -63,7 +71,9 @@ let package = Package( .target( name: "RollbarDeploys", - dependencies: ["RollbarCommon",], + dependencies: [ + "RollbarCommon", + ], path: "RollbarDeploys/Sources/RollbarDeploys", publicHeadersPath: "include", cSettings: [ @@ -73,7 +83,9 @@ let package = Package( .target( name: "RollbarNotifier", - dependencies: ["RollbarCommon",], + dependencies: [ + "RollbarCommon", + ], path: "RollbarNotifier/Sources/RollbarNotifier", publicHeadersPath: "include", cSettings: [ @@ -83,7 +95,10 @@ let package = Package( .target( name: "RollbarKSCrash", - dependencies: ["RollbarCommon", "KSCrash"], + dependencies: [ + "RollbarCommon", + "KSCrash", + ], path: "RollbarKSCrash/Sources/RollbarKSCrash", publicHeadersPath: "include", cSettings: [ @@ -93,7 +108,10 @@ let package = Package( .target( name: "RollbarPLCrashReporter", - dependencies: ["RollbarCommon", .product(name: "CrashReporter", package: "PLCrashReporter")], + dependencies: [ + "RollbarCommon", + .product(name: "CrashReporter", package: "PLCrashReporter"), + ], path: "RollbarPLCrashReporter/Sources/RollbarPLCrashReporter", publicHeadersPath: "include", cSettings: [ @@ -103,7 +121,10 @@ let package = Package( .target( name: "RollbarAUL", - dependencies: ["RollbarCommon", "RollbarNotifier"], + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + ], path: "RollbarAUL/Sources/RollbarAUL", publicHeadersPath: "include", cSettings: [ @@ -113,7 +134,10 @@ let package = Package( .target( name: "RollbarSwift", - dependencies: ["RollbarCommon", "RollbarNotifier"], + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + ], path: "RollbarSwift/Sources/RollbarSwift", publicHeadersPath: "include", cSettings: [ @@ -121,6 +145,20 @@ let package = Package( ] ), + .target( + name: "RollbarCocoaLumberjack", + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + "CocoaLumberjack", + ], + path: "RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack", + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/**"), + ] + ), + ], swiftLanguageVersions: [ SwiftVersion.v4, diff --git a/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme b/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme new file mode 100644 index 00000000..a65d72e2 --- /dev/null +++ b/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RollbarCocoaLumberjack/Package.swift b/RollbarCocoaLumberjack/Package.swift index 435ccbd7..9a29d65e 100644 --- a/RollbarCocoaLumberjack/Package.swift +++ b/RollbarCocoaLumberjack/Package.swift @@ -5,6 +5,13 @@ import PackageDescription let package = Package( name: "RollbarCocoaLumberjack", + platforms: [ + // Oldest targeted platform versions that are supported by this product. + .macOS(.v10_10), + .iOS(.v9), + .tvOS(.v11), + .watchOS(.v4), + ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( @@ -14,15 +21,54 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../RollbarCommon"), + .package(path: "../RollbarNotifier"), + .package(name: "UnitTesting", + path: "../UnitTesting" + ), + .package(name:"CocoaLumberjack", + url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", + from: "3.7.4" //Package.Dependency.Requirement.branch("master") + ), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "RollbarCocoaLumberjack", - dependencies: []), + dependencies: [ + "RollbarCommon", + "RollbarNotifier", + "CocoaLumberjack", + ], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("Sources/RollbarCocoaLumberjack/**"), + // .headerSearchPath("Sources/RollbarSwift"), + // .headerSearchPath("Sources/RollbarSwift/include"), + // .headerSearchPath("Sources/RollbarSwift/DTOs"), + + // .define("DEFINES_MODULE"), + ] + ), .testTarget( name: "RollbarCocoaLumberjackTests", - dependencies: ["RollbarCocoaLumberjack"]), + dependencies: [ + "UnitTesting", + "RollbarCocoaLumberjack", + ] + ), + .testTarget( + name: "RollbarCocoaLumberjackTests-ObjC", + dependencies: ["RollbarCocoaLumberjack"], + cSettings: [ + .headerSearchPath("Tests/RollbarCocoaLumberjackTests-ObjC/**"), + ] + ), + ], + swiftLanguageVersions: [ + SwiftVersion.v4, + SwiftVersion.v4_2, + SwiftVersion.v5, ] ) diff --git a/RollbarCocoaLumberjack/Tests/LinuxMain.swift b/RollbarCocoaLumberjack/Tests/LinuxMain.swift new file mode 100644 index 00000000..3876c733 --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import RollbarCocoaLumberjackTests + +var tests = [XCTestCaseEntry]() +tests += RollbarCocoaLumberjackTests.allTests() +XCTMain(tests) diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m new file mode 100644 index 00000000..45e81511 --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -0,0 +1,16 @@ +// Copyright (c) 2018 Rollbar, Inc. All rights reserved. + +#import + +@import RollbarCocoaLumberjack; + +@interface RollbarCocoaLumberjackTests : XCTestCase +@end + +@implementation RollbarCocoaLumberjackTests + +- (void)testBasics { +} + +@end + diff --git a/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved index 7b7b50ff..40e827fa 100644 --- a/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -1,6 +1,15 @@ { "object": { "pins": [ + { + "package": "CocoaLumberjack", + "repositoryURL": "https://github.com/CocoaLumberjack/CocoaLumberjack.git", + "state": { + "branch": null, + "revision": "80ada1f753b0d53d9b57c465936a7c4169375002", + "version": "3.7.4" + } + }, { "package": "KSCrash", "repositoryURL": "https://github.com/kstenerud/KSCrash.git", @@ -18,6 +27,15 @@ "revision": "59513acde6194d93617afcf7b2c81c88638a6af2", "version": "1.10.0" } + }, + { + "package": "swift-log", + "repositoryURL": "https://github.com/apple/swift-log.git", + "state": { + "branch": null, + "revision": "5d66f7ba25daf4f94100e7022febf3c75e37a6c7", + "version": "1.4.2" + } } ] }, From 9b14cb80116df3a6c27673be3a3d9217d90e09c5 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 28 Feb 2022 17:43:38 -0800 Subject: [PATCH 04/32] RollbarCocoaLumberjack: added module map file --- .../RollbarCocoaLumberjack/include/module.modulemap | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap new file mode 100644 index 00000000..543b66ad --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/module.modulemap @@ -0,0 +1,8 @@ +module RollbarCocoaLumberjack { + umbrella "." + + export * + module * { export * } + + requires objc +} From a8b198823719d3b24106f4c4aa1b695ca0b94078 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 28 Feb 2022 20:41:44 -0800 Subject: [PATCH 05/32] first cut: RollbarCocoaLumberjackLogger --- .../RollbarCocoaLumberjack.swift | 6 -- .../RollbarCocoaLumberjackLogger.m | 76 +++++++++++++++++++ .../include/RollbarCocoaLumberjackLogger.h | 30 ++++++++ 3 files changed, 106 insertions(+), 6 deletions(-) delete mode 100644 RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift create mode 100644 RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m create mode 100644 RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift deleted file mode 100644 index 1967e5a1..00000000 --- a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjack.swift +++ /dev/null @@ -1,6 +0,0 @@ -public struct RollbarCocoaLumberjack { - public private(set) var text = "Hello, World!" - - public init() { - } -} diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m new file mode 100644 index 00000000..9c62af75 --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m @@ -0,0 +1,76 @@ +#import "RollbarCocoaLumberjackLogger.h" + +@implementation RollbarCocoaLumberjackLogger + +#pragma mark - factory methods + ++ (NSObject *)createWithRollbarConfig:(RollbarConfig *)rollbarConfig { + + return [[RollbarCocoaLumberjackLogger alloc] initWithRollbarConfig:rollbarConfig]; +} + ++ (NSObject *)createWithRollbarLogger:(RollbarLogger *)rollbarLogger { + + return [[RollbarCocoaLumberjackLogger alloc] initWithRollbarLogger:rollbarLogger]; +} + +#pragma mark - instance initializers + +- (instancetype)initWithRollbarLogger:(RollbarLogger *)rollbarLogger { + + if ((self = [super init])) { + _rollbarLogger = rollbarLogger; + } + return self; +} + +- (instancetype)initWithRollbarConfig:(RollbarConfig *)rollbarConfig { + + RollbarLogger *rollbarLogger = [[RollbarLogger alloc] initWithConfiguration:rollbarConfig]; + return [self initWithRollbarLogger:rollbarLogger]; +} + +#pragma mark - DDLogger protocol + +- (void)logMessage:(DDLogMessage *)logMessage { + NSString *logMsg = logMessage.message; + + if (self->_logFormatter) + logMsg = [self->_logFormatter formatLogMessage:logMessage]; + + if (logMsg) { + // let's send it to Rollbar: + [self->_rollbarLogger log:[RollbarCocoaLumberjackLogger convert:logMessage] + message:logMsg + data:nil + context:@"RollbarCocoaLumberjackLogger" + ]; + } +} + +#pragma mark - utility methods + ++ (NSDictionary *)dataWithDDLogMessage:(DDLogMessage *)logMessage { + + return @{ + //TODO: complete the data mapping... + }; +} + ++ (RollbarLevel) convert:(DDLogFlag) ddLogFlag { + + switch(ddLogFlag) { + case DDLogFlagError: + return RollbarLevel_Error; + case DDLogFlagWarning: + return RollbarLevel_Warning; + case DDLogFlagInfo: + return RollbarLevel_Info; + case DDLogFlagDebug: + case DDLogFlagVerbose: + return RollbarLevel_Debug; + default: + return RollbarLevel_Critical; + } +} +@end diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h new file mode 100644 index 00000000..16289521 --- /dev/null +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h @@ -0,0 +1,30 @@ +#import +@import CocoaLumberjack; +@import RollbarNotifier; + +NS_ASSUME_NONNULL_BEGIN + +@interface RollbarCocoaLumberjackLogger : DDAbstractLogger { + @private + RollbarLogger *_rollbarLogger; +} + +#pragma mark - factory methods + ++ (NSObject *)createWithRollbarLogger:(RollbarLogger *)rollbarLogger; + ++ (NSObject *)createWithRollbarConfig:(RollbarConfig *)rollbarConfig; + +#pragma mark - instance initializers + +- (instancetype)initWithRollbarLogger:(RollbarLogger *)rollbarLogger +NS_DESIGNATED_INITIALIZER; + +- (instancetype)initWithRollbarConfig:(RollbarConfig *)rollbarConfig; + +- (instancetype)init +NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END From 4f2998c74b96d9ae07d3456cb17b052658d71382 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 1 Mar 2022 21:34:40 -0800 Subject: [PATCH 06/32] RollbarCocoaLumberjackLogger: prototype is code complete --- .../RollbarCocoaLumberjackLogger.m | 103 +++++++++++++++++- .../RollbarCocoaLumberjackTests.m | 58 +++++++++- .../RollbarTestUtil.h | 16 +++ .../RollbarTestUtil.m | 66 +++++++++++ .../RollbarCommonTests.m | 9 -- .../RollbarCrashReportUtilTest.m | 7 -- .../RollbarHostingProcessUtilTest.m | 7 -- .../RollbarPredicateBuilderTests.m | 7 -- .../Sources/RollbarNotifier/RollbarLogger.m | 2 + .../RollbarTestUtil.m | 2 + 10 files changed, 242 insertions(+), 35 deletions(-) create mode 100644 RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h create mode 100644 RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m index 9c62af75..73621bc3 100644 --- a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/RollbarCocoaLumberjackLogger.m @@ -40,9 +40,9 @@ - (void)logMessage:(DDLogMessage *)logMessage { if (logMsg) { // let's send it to Rollbar: - [self->_rollbarLogger log:[RollbarCocoaLumberjackLogger convert:logMessage] + [self->_rollbarLogger log:[RollbarCocoaLumberjackLogger convertDDLogFlagToRollbarLevel:logMessage.flag] message:logMsg - data:nil + data:[RollbarCocoaLumberjackLogger dataWithDDLogMessage:logMessage] context:@"RollbarCocoaLumberjackLogger" ]; } @@ -53,11 +53,106 @@ - (void)logMessage:(DDLogMessage *)logMessage { + (NSDictionary *)dataWithDDLogMessage:(DDLogMessage *)logMessage { return @{ - //TODO: complete the data mapping... + @"DDLogMessage.message": + logMessage.message, + @"DDLogMessage.level": + [RollbarCocoaLumberjackLogger convertDDLogLevelToString:logMessage.level], + @"DDLogMessage.flag": + [RollbarCocoaLumberjackLogger convertDDLogFlagToString:logMessage.flag], + @"DDLogMessage.context": + [NSNumber numberWithInteger:logMessage.context], + @"DDLogMessage.file": + logMessage.file, + @"DDLogMessage.fileName": + logMessage.fileName, + @"DDLogMessage.function": + (nil != logMessage.function) ? logMessage.function : @"", + @"DDLogMessage.line": + [NSNumber numberWithUnsignedInteger:logMessage.line], + @"DDLogMessage.representedObject": + (nil != logMessage.representedObject) ? [logMessage.representedObject description] : @"", + @"DDLogMessage.options": + [RollbarCocoaLumberjackLogger convertDDLogMessageOptionsToString:logMessage.options], + @"DDLogMessage.timestamp": + logMessage.timestamp.description, // !!!!!!!!!!!! ********* + @"DDLogMessage.threadID": + logMessage.threadID, + @"DDLogMessage.threadName": + (nil != logMessage.threadName) ? logMessage.threadName : @"", + @"DDLogMessage.queueLabel": + logMessage.queueLabel, + @"DDLogMessage.qos": + [NSNumber numberWithUnsignedInteger:logMessage.qos], +// @"DDLogMessage.tag": +// (nil != logMessage.tag) ? [logMessage.tag description] : @"", }; } -+ (RollbarLevel) convert:(DDLogFlag) ddLogFlag { ++ (NSString *)convertDDLogMessageOptionsToString:(DDLogMessageOptions) options { + + NSString *stringValue = [NSString string]; + if (options & DDLogMessageCopyFile) { + if (stringValue.length > 0) { + stringValue = [stringValue stringByAppendingString:@" | "]; + } + stringValue = [stringValue stringByAppendingString:@"DDLogMessageCopyFile"]; + } + if (options & DDLogMessageCopyFunction) { + if (stringValue.length > 0) { + stringValue = [stringValue stringByAppendingString:@" | "]; + } + stringValue = [stringValue stringByAppendingString:@"DDLogMessageCopyFunction"]; + } + if (options & DDLogMessageDontCopyMessage) { + if (stringValue.length > 0) { + stringValue = [stringValue stringByAppendingString:@" | "]; + } + stringValue = [stringValue stringByAppendingString:@"DDLogMessageDontCopyMessage"]; + } + return stringValue; +} + ++ (NSString *)convertDDLogLevelToString:(DDLogLevel) logLevel { + + switch(logLevel) { + case DDLogLevelOff: + return @"DDLogLevelOff"; + case DDLogLevelAll: + return @"DDLogLevelAll"; + case DDLogLevelInfo: + return @"DDLogLevelError"; + case DDLogLevelError: + return @"DDLogLevelError"; + case DDLogLevelDebug: + return @"DDLogLevelDebug"; + case DDLogLevelWarning: + return @"DDLogLevelWarning"; + case DDLogLevelVerbose: + return @"DDLogLevelVerbose"; + default: + return @"Unexpected_DDLogLevel_value"; + } +} + ++ (NSString *)convertDDLogFlagToString:(DDLogFlag) ddLogFlag { + + switch(ddLogFlag) { + case DDLogFlagError: + return @"DDLogFlagError"; + case DDLogFlagWarning: + return @"DDLogFlagWarning"; + case DDLogFlagInfo: + return @"DDLogFlagInfo"; + case DDLogFlagDebug: + return @"DDLogFlagDebug"; + case DDLogFlagVerbose: + return @"DDLogFlagVerbose"; + default: + return @"Unexpected_DDLogFlag_value"; + } +} + ++ (RollbarLevel) convertDDLogFlagToRollbarLevel:(DDLogFlag) ddLogFlag { switch(ddLogFlag) { case DDLogFlagError: diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m index 45e81511..97577dd3 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -1,15 +1,71 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. #import +#import "../../../UnitTests/RollbarUnitTestSettings.h" +#import "RollbarTestUtil.h" + +#define LOG_LEVEL_DEF ddLogLevel +//#import +@import CocoaLumberjack; @import RollbarCocoaLumberjack; +static const DDLogLevel ddLogLevel = DDLogLevelDebug; + @interface RollbarCocoaLumberjackTests : XCTestCase @end @implementation RollbarCocoaLumberjackTests -- (void)testBasics { +- (void)setUp { + + [super setUp]; + + // Put setup code here. This method is called before the invocation of each test method in the class. + NSLog(@"Set to go..."); + + RollbarClearLogFile(); + + [DDLog addLogger:[DDOSLogger sharedInstance]]; + + DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; + fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling + fileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // he above code tells the application to keep a day worth of log files on the system. + + [DDLog addLogger:fileLogger]; +} + +- (void)tearDown { + // Put teardown code here. This method is called after the invocation of each test method in the class. + NSLog(@"Teared down."); +} + +- (void)testLiveRollbarCocoaLumberjackBasics { + + + DDLogError(@"Broken sprocket detected!"); + DDLogVerbose(@"User selected file:%@ withSize:%u", @"somewhere/file.ext", 100); + + RollbarConfig *config = [[RollbarConfig alloc] init]; + config.destination.accessToken = ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN; + config.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + config.developerOptions.transmit = YES; + config.developerOptions.logPayload = YES; + config.loggingOptions.maximumReportsPerMinute = 5000; + + [DDLog addLogger:[RollbarCocoaLumberjackLogger createWithRollbarConfig:config]]; + + DDLogDebug(@"*** Via CocoaLumberjack!!!"); + + [NSThread sleepForTimeInterval:5.0f]; +} + +- (void)testPerformanceExample { + // This is an example of a performance test case. + [self measureBlock:^{ + // Put the code you want to measure the time of here. + }]; } @end diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h new file mode 100644 index 00000000..161eb9ea --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h @@ -0,0 +1,16 @@ +// Copyright (c) 2018 Rollbar, Inc. All rights reserved. + +#import + +@import RollbarNotifier; + +void RollbarClearLogFile(void); +NSArray* RollbarReadLogItemFromFile(void); +void RollbarFlushFileThread(RollbarLogger *logger); + +@interface RollbarLogger (Tests) + +- (NSThread *)_rollbarThread; +- (void)_test_doNothing; + +@end diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m new file mode 100644 index 00000000..9eb67126 --- /dev/null +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m @@ -0,0 +1,66 @@ +// Copyright (c) 2018 Rollbar, Inc. All rights reserved. + +#import "RollbarTestUtil.h" +#import "RollbarFileReader.h" +#import "RollbarCachesDirectory.h" + +static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; +static NSString *QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; +static NSString *QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; + +NSString* _logFilePath() { + + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; +} + +void RollbarClearLogFile() { + + NSString *filePath = _logFilePath(); + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *error; + BOOL fileExists = [fileManager fileExistsAtPath:filePath]; + + if (fileExists) { + BOOL success = [fileManager removeItemAtPath:filePath + error:&error]; + if (!success) { + NSLog(@"Error: %@", [error localizedDescription]); + } + [[NSFileManager defaultManager] createFileAtPath:filePath + contents:nil + attributes:nil]; + } +} + +NSArray* RollbarReadLogItemFromFile() { + + NSString *filePath = _logFilePath(); + RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath + andOffset:0]; + + NSMutableArray *items = [NSMutableArray array]; + [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { + NSMutableDictionary *payload = + [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding] + options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) + error:nil + ]; + + + if (!payload) { + return; + } + + NSMutableDictionary *data = payload[@"data"]; + [items addObject:data]; + }]; + + return items; +} + +void RollbarFlushFileThread(RollbarLogger *logger) { + + [logger performSelector:@selector(_test_doNothing) + onThread:[logger _rollbarThread] withObject:nil waitUntilDone:YES]; +} diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m index 17ec4299..803321db 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCommonTests.m @@ -1,12 +1,3 @@ -// -// DTOsTests.m -// Rollbar -// -// Created by Andrey Kornich on 2019-10-10. -// Copyright © 2019 Rollbar. All rights reserved. -// - - @import Foundation; #if !TARGET_OS_WATCH diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m index ce559fea..6ac6f743 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarCrashReportUtilTest.m @@ -1,10 +1,3 @@ -// -// Test.m -// -// -// Created by Andrey Kornich on 2021-01-04. -// - #import @import Foundation; diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m index 81397456..8a4341b5 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarHostingProcessUtilTest.m @@ -1,10 +1,3 @@ -// -// Test.m -// -// -// Created by Andrey Kornich on 2021-05-06. -// - #import @import RollbarCommon; diff --git a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m index 98fc4825..f1294c0a 100644 --- a/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m +++ b/RollbarCommon/Tests/RollbarCommonTests-ObjC/RollbarPredicateBuilderTests.m @@ -1,10 +1,3 @@ -// -// RollbarPredicateBuilderTests.m -// -// -// Created by Andrey Kornich on 2021-04-29. -// - #import @import Foundation; diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m index 7246fa95..ed76a3ad 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m @@ -1018,6 +1018,8 @@ - (BOOL)checkPayloadResponse:(NSURLResponse *)response error:(NSError *)error data:(NSData *)data { + NSLog(@"HTTP response from Rollbar: %@", response); + // Lookup rate limiting headers and adjust reporting rate accordingly: NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response; NSDictionary *httpHeaders = [httpResponse allHeaderFields]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m index 5109c3df..9eb67126 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m @@ -5,6 +5,8 @@ #import "RollbarCachesDirectory.h" static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; +static NSString *QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; +static NSString *QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; NSString* _logFilePath() { From b82c3fe91590c3eac0705695b84824d36a411719 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Wed, 2 Mar 2022 16:52:18 -0800 Subject: [PATCH 07/32] feat: resolve #133 RollbarCocoaLumberjackLogger is code complete --- RollbarCocoaLumberjack/Package.swift | 5 +---- RollbarCocoaLumberjack/README.md | 2 +- .../include/RollbarCocoaLumberjackLogger.h | 10 ++++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/RollbarCocoaLumberjack/Package.swift b/RollbarCocoaLumberjack/Package.swift index 9a29d65e..9f025031 100644 --- a/RollbarCocoaLumberjack/Package.swift +++ b/RollbarCocoaLumberjack/Package.swift @@ -44,10 +44,7 @@ let package = Package( publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/RollbarCocoaLumberjack/**"), - // .headerSearchPath("Sources/RollbarSwift"), - // .headerSearchPath("Sources/RollbarSwift/include"), - // .headerSearchPath("Sources/RollbarSwift/DTOs"), - + // .headerSearchPath("Sources/RollbarCocoaLumberjack/DTOs"), // .define("DEFINES_MODULE"), ] ), diff --git a/RollbarCocoaLumberjack/README.md b/RollbarCocoaLumberjack/README.md index b1601be9..e7d8d3af 100644 --- a/RollbarCocoaLumberjack/README.md +++ b/RollbarCocoaLumberjack/README.md @@ -6,4 +6,4 @@ This SDK module implements integration of Rollbar into the popular CocoaLumberja So if you either already use CocoaLumberjack or you are planning to use it for your software product logging needs, then you can easily integrate Rollbar into it via this module and have all or some of the logs performed via the CocoaLumberjack framework redirected into a dedicated Rollbar project at www.rollbar.com and monitor the health of -your own software product/service remotely. +your software product/service remotely. diff --git a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h index 16289521..b4a7bdd9 100644 --- a/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h +++ b/RollbarCocoaLumberjack/Sources/RollbarCocoaLumberjack/include/RollbarCocoaLumberjackLogger.h @@ -4,6 +4,7 @@ NS_ASSUME_NONNULL_BEGIN +/// Rollbar logger for CocoaLumberjack @interface RollbarCocoaLumberjackLogger : DDAbstractLogger { @private RollbarLogger *_rollbarLogger; @@ -11,17 +12,26 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark - factory methods +/// Creates initialized instance of the Rollbar logger for CocoaLumberjack +/// @param rollbarLogger a RollbarLogger to use + (NSObject *)createWithRollbarLogger:(RollbarLogger *)rollbarLogger; +/// Creates initialized instance of the Rollbar logger for CocoaLumberjack +/// @param rollbarConfig a RollbarConfig to use + (NSObject *)createWithRollbarConfig:(RollbarConfig *)rollbarConfig; #pragma mark - instance initializers +/// Initializer +/// @param rollbarLogger a RollbarLogger to use - (instancetype)initWithRollbarLogger:(RollbarLogger *)rollbarLogger NS_DESIGNATED_INITIALIZER; +/// Initializer +/// @param rollbarConfig a RollbarConfig to use - (instancetype)initWithRollbarConfig:(RollbarConfig *)rollbarConfig; +/// Hides initializer - (instancetype)init NS_UNAVAILABLE; From 39073c35facf1c4ad452c69f57ef0044835d76e7 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 3 Mar 2022 00:39:42 -0800 Subject: [PATCH 08/32] chore: fixed RollbarCommon build warning --- RollbarCommon/Package.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/RollbarCommon/Package.swift b/RollbarCommon/Package.swift index 97da63bb..4d40c6e2 100644 --- a/RollbarCommon/Package.swift +++ b/RollbarCommon/Package.swift @@ -57,6 +57,7 @@ let package = Package( .testTarget( name: "RollbarCommonTests-ObjC", dependencies: ["RollbarCommon"], + exclude: ["TestData/rollbar-crash-report-147120812218-raw.txt"], cSettings: [ .headerSearchPath("Tests/RollbarCommonTests-ObjC/**"), // .headerSearchPath("Sources/RollbarCommon"), From 8e6896ef365c5ccc77a84419835de190d44dc337 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 8 Mar 2022 17:16:31 -0800 Subject: [PATCH 09/32] chore: ref #112 Upgrade to the latest PLCrashReporter 1.0.1 --- Package.swift | 2 +- .../RollbarCommon/include/RollbarCrashCollectorBase.h | 5 ++--- RollbarPLCrashReporter.podspec | 2 +- RollbarPLCrashReporter/Package.swift | 2 +- RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Package.swift b/Package.swift index a1b62311..283c4d07 100644 --- a/Package.swift +++ b/Package.swift @@ -48,7 +48,7 @@ let package = Package( ), .package(name:"PLCrashReporter", url: "https://github.com/microsoft/plcrashreporter.git", - from: "1.10.0" //Package.Dependency.Requirement.branch("master") + from: "1.10.1" //Package.Dependency.Requirement.branch("master") ), .package(name:"CocoaLumberjack", url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", diff --git a/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h b/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h index 6965eaae..aac64e03 100644 --- a/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h +++ b/RollbarCommon/Sources/RollbarCommon/include/RollbarCrashCollectorBase.h @@ -20,9 +20,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithObserver:(nullable id)observer NS_DESIGNATED_INITIALIZER; -/// Hides parametrless initializer. -- (instancetype)init -NS_UNAVAILABLE; +/// Initializer. +- (instancetype)init; @end diff --git a/RollbarPLCrashReporter.podspec b/RollbarPLCrashReporter.podspec index 8861d503..263d1334 100644 --- a/RollbarPLCrashReporter.podspec +++ b/RollbarPLCrashReporter.podspec @@ -50,7 +50,7 @@ Pod::Spec.new do |s| s.static_framework = true s.framework = "Foundation" s.dependency "RollbarCommon", "~> #{s.version}" - s.dependency "PLCrashReporter", "~> 1.10.0" + s.dependency "PLCrashReporter", "~> 1.10.1" # s.frameworks = "SomeFramework", "AnotherFramework" # s.library = "iconv" # s.libraries = "iconv", "xml2" diff --git a/RollbarPLCrashReporter/Package.swift b/RollbarPLCrashReporter/Package.swift index d5891ced..a12cb1aa 100644 --- a/RollbarPLCrashReporter/Package.swift +++ b/RollbarPLCrashReporter/Package.swift @@ -29,7 +29,7 @@ let package = Package( ), .package(name:"PLCrashReporter", url: "https://github.com/microsoft/plcrashreporter.git", - from: "1.10.0" //Package.Dependency.Requirement.branch("master") + from: "1.10.1" //Package.Dependency.Requirement.branch("master") ), ], targets: [ diff --git a/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved b/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved index 40e827fa..e862be07 100644 --- a/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/RollbarSDK.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -24,8 +24,8 @@ "repositoryURL": "https://github.com/microsoft/plcrashreporter.git", "state": { "branch": null, - "revision": "59513acde6194d93617afcf7b2c81c88638a6af2", - "version": "1.10.0" + "revision": "6b27393cad517c067dceea85fadf050e70c4ceaa", + "version": "1.10.1" } }, { From ab81c713c2b2c24fd336fc218438eb11948b9af6 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 8 Mar 2022 21:23:13 -0800 Subject: [PATCH 10/32] chore: updated change log --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4f2751d..80990c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,11 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ## Release Notes +**2.1.0 +- feat: resolve #133 - Implement RollbarCocoaLumberjack module +- test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack +- core: resolve #112 - Upgrade to the latest PLCrashReporter 1.0.1 + **2.0.3 - docs: resolve #122 - Update RollbarCommon public API doc comments so they are properly rendered by Xcode Quick Help - docs: resolve #124 - Update RollbarDeploys public API doc comments so they are properly rendered by Xcode Quick Help From 621968c3d3e859bbff41fb373915c0103abf46dc Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 8 Mar 2022 21:24:51 -0800 Subject: [PATCH 11/32] test: ref #134 setting up the shared UnitTesting package project --- RollbarCocoaLumberjack/Package.swift | 9 +++++---- .../RollbarCocoaLumberjackTests.m | 3 ++- UnitTesting/Package.swift | 19 ++++++++++++++++++- .../Sources/UnitTesting/RollbarTestSettings.m | 12 ++++++++++++ .../UnitTesting/RollbarUnitTestSettings.swift | 8 -------- .../UnitTesting/include/RollbarTestSettings.h | 16 ++++++++++++++++ .../include/RollbarUnitTestSettings.h | 16 ++++++++++++++++ .../UnitTesting/include/module.modulemap | 8 ++++++++ 8 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 UnitTesting/Sources/UnitTesting/RollbarTestSettings.m delete mode 100644 UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift create mode 100644 UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h create mode 100644 UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h create mode 100644 UnitTesting/Sources/UnitTesting/include/module.modulemap diff --git a/RollbarCocoaLumberjack/Package.swift b/RollbarCocoaLumberjack/Package.swift index 9f025031..8689e237 100644 --- a/RollbarCocoaLumberjack/Package.swift +++ b/RollbarCocoaLumberjack/Package.swift @@ -23,9 +23,7 @@ let package = Package( // .package(url: /* package url */, from: "1.0.0"), .package(path: "../RollbarCommon"), .package(path: "../RollbarNotifier"), - .package(name: "UnitTesting", - path: "../UnitTesting" - ), + .package(path: "../UnitTesting"), .package(name:"CocoaLumberjack", url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git", from: "3.7.4" //Package.Dependency.Requirement.branch("master") @@ -57,7 +55,10 @@ let package = Package( ), .testTarget( name: "RollbarCocoaLumberjackTests-ObjC", - dependencies: ["RollbarCocoaLumberjack"], + dependencies: [ + "UnitTesting", + "RollbarCocoaLumberjack", + ], cSettings: [ .headerSearchPath("Tests/RollbarCocoaLumberjackTests-ObjC/**"), ] diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m index 97577dd3..4d63be7e 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -1,12 +1,13 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" +//#import "../../../UnitTests/RollbarUnitTestSettings.h" #import "RollbarTestUtil.h" #define LOG_LEVEL_DEF ddLogLevel //#import @import CocoaLumberjack; +@import UnitTesting; @import RollbarCocoaLumberjack; diff --git a/UnitTesting/Package.swift b/UnitTesting/Package.swift index e0f59532..b32e3d08 100644 --- a/UnitTesting/Package.swift +++ b/UnitTesting/Package.swift @@ -5,6 +5,13 @@ import PackageDescription let package = Package( name: "UnitTesting", + platforms: [ + // Oldest targeted platform versions that are supported by this product. + .macOS(.v10_10), + .iOS(.v9), + .tvOS(.v11), + .watchOS(.v4), + ], products: [ // Products define the executables and libraries a package produces, and make them visible to other packages. .library( @@ -20,7 +27,17 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "UnitTesting", - dependencies: []), + dependencies: [], + publicHeadersPath: "include", + cSettings: [ + .headerSearchPath("Sources/UnitTesting/**"), + // .headerSearchPath("Sources/RollbarNotifier"), + // .headerSearchPath("Sources/RollbarNotifier/include"), + // .headerSearchPath("Sources/RollbarNotifier/DTOs"), + + // .define("DEFINES_MODULE"), + ] + ), .testTarget( name: "UnitTestingTests", dependencies: ["UnitTesting"]), diff --git a/UnitTesting/Sources/UnitTesting/RollbarTestSettings.m b/UnitTesting/Sources/UnitTesting/RollbarTestSettings.m new file mode 100644 index 00000000..97d0edd0 --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/RollbarTestSettings.m @@ -0,0 +1,12 @@ +// +// RollbarTestSettings.m +// +// +// Created by Andrey Kornich on 2022-03-08. +// + +#import "RollbarTestSettings.h" + +@implementation RollbarTestSettings + +@end diff --git a/UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift b/UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift deleted file mode 100644 index d89c71f1..00000000 --- a/UnitTesting/Sources/UnitTesting/RollbarUnitTestSettings.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation - -public struct RollbarUnitTestSettings { - public static let environment = "Rollbar-Apple-UnitTests"; - public static let payloadsPostAccessToken = "09da180aba21479e9ed3d91e0b8d58d6"; - public static let deploysWriteAccessToken = "efdc4b85d66045f293a7f9e99c732f61"; - public static let deploysReadAccessToken = "595cbf76b05b45f2b3ef661a2e0078d4"; -} diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h b/UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h new file mode 100644 index 00000000..852c33ac --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h @@ -0,0 +1,16 @@ +// +// RollbarTestSettings.h +// +// +// Created by Andrey Kornich on 2022-03-08. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RollbarTestSettings : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h b/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h new file mode 100644 index 00000000..69213114 --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h @@ -0,0 +1,16 @@ +#ifndef RollbarUnitTestSettings_h +#define RollbarUnitTestSettings_h + +static NSString * const ROLLBAR_UNIT_TEST_ENVIRONMENT = +@"Rollbar-Apple-UnitTests"; + +static NSString * const ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN = +@"09da180aba21479e9ed3d91e0b8d58d6"; + +static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN = +@"efdc4b85d66045f293a7f9e99c732f61"; + +static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN = +@"595cbf76b05b45f2b3ef661a2e0078d4"; + +#endif /* RollbarUnitTestSettings_h */ diff --git a/UnitTesting/Sources/UnitTesting/include/module.modulemap b/UnitTesting/Sources/UnitTesting/include/module.modulemap new file mode 100644 index 00000000..0eadb038 --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/include/module.modulemap @@ -0,0 +1,8 @@ +module UnitTesting { + umbrella "." + + export * + module * { export * } + + requires objc +} From 77440162315e6841e6b9a58da91d7a8b7bab30bb Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 8 Mar 2022 22:09:42 -0800 Subject: [PATCH 12/32] test: ref #134 --- .../xcschemes/RollbarCocoaLumberjack.xcscheme | 24 +++++++++++++++++++ .../RollbarCocoaLumberjackTests.m | 1 - .../RollbarCocoaLumberjackTests.swift | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme b/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme index a65d72e2..17a2082d 100644 --- a/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme +++ b/RollbarCocoaLumberjack/.swiftpm/xcode/xcshareddata/xcschemes/RollbarCocoaLumberjack.xcscheme @@ -20,6 +20,20 @@ ReferencedContainer = "container:"> + + + + + + + + -//#import "../../../UnitTests/RollbarUnitTestSettings.h" #import "RollbarTestUtil.h" #define LOG_LEVEL_DEF ddLogLevel diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift index 49535d92..52d6376e 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -6,6 +6,6 @@ final class RollbarCocoaLumberjackTests: XCTestCase { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct // results. - XCTAssertEqual(RollbarCocoaLumberjack().text, "Hello, World!") + //XCTAssertEqual(RollbarCocoaLumberjack().text, "Hello, World!") } } From cd64e4bbc58bd7e857b49527fc73fb705a63d7c2 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Wed, 9 Mar 2022 17:44:16 -0800 Subject: [PATCH 13/32] test: ref #134 refactored unit testing infrastructure --- .../RollbarCocoaLumberjackTests.m | 6 +- .../RollbarTestUtil.h | 16 --- .../RollbarTestUtil.m | 66 --------- .../RollbarDeploysTests.swift | 16 +-- RollbarNotifier/Package.swift | 5 +- .../Sources/RollbarNotifier/RollbarLogger.m | 126 +++++++++++++++--- .../include/RollbarLogger+Test.h | 27 ++++ .../PayloadTruncationTests.m | 10 +- .../RollbarTelemetryTests.m | 17 ++- .../RollbarTestUtil.h | 16 --- .../RollbarTestUtil.m | 66 --------- .../RollbarNotifierTests-ObjC/RollbarTests.m | 11 +- .../RollbarConfigurationTests.m | 97 +++++++++----- .../RollbarNotifierLoggerTests.swift | 10 +- .../RollbarNotifierTelemetryTests.swift | 4 +- .../RollbarNotifierTruncationTests.swift | 4 +- .../RollbarSwiftTests/RollbarSwiftTests.swift | 4 +- .../Sources/UnitTesting/RollbarTestHelper.m | 26 ++++ .../Sources/UnitTesting/RollbarTestSettings.m | 12 -- .../UnitTesting/include/RollbarTestHelper.h | 22 +++ .../UnitTesting/include/RollbarTestSettings.h | 16 --- .../include/RollbarUnitTestSettings.h | 8 +- 22 files changed, 303 insertions(+), 282 deletions(-) delete mode 100644 RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h delete mode 100644 RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m create mode 100644 RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h delete mode 100644 RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h delete mode 100644 RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m rename RollbarNotifier/Tests/RollbarNotifierTests-ObjC/{ => TestData}/RollbarConfigurationTests.m (81%) create mode 100644 UnitTesting/Sources/UnitTesting/RollbarTestHelper.m delete mode 100644 UnitTesting/Sources/UnitTesting/RollbarTestSettings.m create mode 100644 UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h delete mode 100644 UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m index ba86d9c6..19a84cbf 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -1,11 +1,12 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. #import -#import "RollbarTestUtil.h" +//#import "RollbarTestUtil.h" #define LOG_LEVEL_DEF ddLogLevel //#import @import CocoaLumberjack; +@import RollbarNotifier; @import UnitTesting; @import RollbarCocoaLumberjack; @@ -24,7 +25,8 @@ - (void)setUp { // Put setup code here. This method is called before the invocation of each test method in the class. NSLog(@"Set to go..."); - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); [DDLog addLogger:[DDOSLogger sharedInstance]]; diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h deleted file mode 100644 index 161eb9ea..00000000 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - -#import - -@import RollbarNotifier; - -void RollbarClearLogFile(void); -NSArray* RollbarReadLogItemFromFile(void); -void RollbarFlushFileThread(RollbarLogger *logger); - -@interface RollbarLogger (Tests) - -- (NSThread *)_rollbarThread; -- (void)_test_doNothing; - -@end diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m deleted file mode 100644 index 9eb67126..00000000 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarTestUtil.m +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - -#import "RollbarTestUtil.h" -#import "RollbarFileReader.h" -#import "RollbarCachesDirectory.h" - -static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; -static NSString *QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; -static NSString *QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; - -NSString* _logFilePath() { - - NSString *cachesDirectory = [RollbarCachesDirectory directory]; - return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; -} - -void RollbarClearLogFile() { - - NSString *filePath = _logFilePath(); - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSError *error; - BOOL fileExists = [fileManager fileExistsAtPath:filePath]; - - if (fileExists) { - BOOL success = [fileManager removeItemAtPath:filePath - error:&error]; - if (!success) { - NSLog(@"Error: %@", [error localizedDescription]); - } - [[NSFileManager defaultManager] createFileAtPath:filePath - contents:nil - attributes:nil]; - } -} - -NSArray* RollbarReadLogItemFromFile() { - - NSString *filePath = _logFilePath(); - RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath - andOffset:0]; - - NSMutableArray *items = [NSMutableArray array]; - [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { - NSMutableDictionary *payload = - [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding] - options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) - error:nil - ]; - - - if (!payload) { - return; - } - - NSMutableDictionary *data = payload[@"data"]; - [items addObject:data]; - }]; - - return items; -} - -void RollbarFlushFileThread(RollbarLogger *logger) { - - [logger performSelector:@selector(_test_doNothing) - onThread:[logger _rollbarThread] withObject:nil waitUntilDone:YES]; -} diff --git a/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift b/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift index 74a304e5..b0933d8a 100644 --- a/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift +++ b/RollbarDeploys/Tests/RollbarDeploysTests/RollbarDeploysTests.swift @@ -7,7 +7,7 @@ final class RollbarDeploysTests: XCTestCase { func testDeploymentDto() { - let environment = RollbarUnitTestSettings.environment; + let environment = RollbarTestHelper.getRollbarEnvironment(); let comment = "a new deploy"; let revision = "a_revision"; let localUsername = "UnitTestRunner"; @@ -41,7 +41,7 @@ final class RollbarDeploysTests: XCTestCase { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" - let environment = RollbarUnitTestSettings.environment; + let environment = RollbarTestHelper.getRollbarEnvironment(); let comment = "a new deploy at \(dateFormatter.string(from:Date.init()))"; let revision = "a_revision"; let localUsername = "UnitTestRunner"; @@ -58,8 +58,8 @@ final class RollbarDeploysTests: XCTestCase { ); let deploysManager = RollbarDeploysManager( - writeAccessToken:RollbarUnitTestSettings.deploysWriteAccessToken, - readAccessToken:RollbarUnitTestSettings.deploysReadAccessToken, + writeAccessToken:RollbarTestHelper.getRollbarDeploysWriteAccessToken(), + readAccessToken:RollbarTestHelper.getRollbarDeploysReadAccessToken(), deploymentRegistrationObserver:observer, deploymentDetailsObserver:observer, deploymentDetailsPageObserver:observer @@ -76,8 +76,8 @@ final class RollbarDeploysTests: XCTestCase { let observer = RollbarDeploysObserver(); let deploysManager = RollbarDeploysManager( - writeAccessToken:RollbarUnitTestSettings.deploysWriteAccessToken, - readAccessToken:RollbarUnitTestSettings.deploysReadAccessToken, + writeAccessToken:RollbarTestHelper.getRollbarDeploysWriteAccessToken(), + readAccessToken:RollbarTestHelper.getRollbarDeploysReadAccessToken(), deploymentRegistrationObserver:observer, deploymentDetailsObserver:observer, deploymentDetailsPageObserver:observer @@ -91,8 +91,8 @@ final class RollbarDeploysTests: XCTestCase { let observer = RollbarDeploysObserver(); let deploysManager = RollbarDeploysManager( - writeAccessToken:RollbarUnitTestSettings.deploysWriteAccessToken, - readAccessToken:RollbarUnitTestSettings.deploysReadAccessToken, + writeAccessToken:RollbarTestHelper.getRollbarDeploysWriteAccessToken(), + readAccessToken:RollbarTestHelper.getRollbarDeploysReadAccessToken(), deploymentRegistrationObserver:observer, deploymentDetailsObserver:observer, deploymentDetailsPageObserver:observer diff --git a/RollbarNotifier/Package.swift b/RollbarNotifier/Package.swift index a6e627bc..41e9d9f5 100644 --- a/RollbarNotifier/Package.swift +++ b/RollbarNotifier/Package.swift @@ -49,7 +49,10 @@ let package = Package( ), .testTarget( name: "RollbarNotifierTests-ObjC", - dependencies: ["RollbarNotifier"], + dependencies: [ + "UnitTesting", + "RollbarNotifier", + ], cSettings: [ .headerSearchPath("Tests/RollbarNotifierTests-ObjC/**"), // .headerSearchPath("Sources/RollbarNotifier"), diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m index ed76a3ad..9d9f10ba 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m @@ -7,6 +7,7 @@ @import RollbarCommon; #import "RollbarLogger.h" +#import "RollbarLogger+Test.h" #import "RollbarThread.h" #import "RollbarReachability.h" #import @@ -18,18 +19,18 @@ #define MAX_PAYLOAD_SIZE 128 // The maximum payload size in kb -static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; -static NSString *STATE_FILE_NAME = @"rollbar.state"; -static NSString *PAYLOADS_FILE_NAME = @"rollbar.payloads"; +static NSString * const QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; +static NSString * const QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; +static NSString * const PAYLOADS_FILE_NAME = @"rollbar.payloads"; // Rollbar API Service enforced payload rate limit: -static NSString *RESPONSE_HEADER_RATE_LIMIT = @"x-rate-limit-limit"; +static NSString * const RESPONSE_HEADER_RATE_LIMIT = @"x-rate-limit-limit"; // Rollbar API Service enforced remaining payload count until the limit is reached: -static NSString *RESPONSE_HEADER_REMAINING_COUNT = @"x-rate-limit-remaining"; +static NSString * const RESPONSE_HEADER_REMAINING_COUNT = @"x-rate-limit-remaining"; // Rollbar API Service enforced rate limit reset time for the current limit window: -static NSString *RESPONSE_HEADER_RESET_TIME = @"x-rate-limit-reset"; +static NSString * const RESPONSE_HEADER_RESET_TIME = @"x-rate-limit-reset"; // Rollbar API Service enforced rate limit remaining seconds of the current limit window: -static NSString *RESPONSE_HEADER_REMAINING_SECONDS = @"x-rate-limit-remaining-seconds"; +static NSString * const RESPONSE_HEADER_REMAINING_SECONDS = @"x-rate-limit-remaining-seconds"; static NSUInteger MAX_RETRY_COUNT = 5; @@ -45,14 +46,6 @@ static BOOL isNetworkReachable = YES; #endif -@interface RollbarLogger () - -- (NSThread *)_rollbarThread; - -- (void)_test_doNothing; - -@end - @implementation RollbarLogger { NSDate *nextSendTime; @@ -84,7 +77,7 @@ + (void)initialize { queuedItemsFilePath = [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; stateFilePath = - [cachesDirectory stringByAppendingPathComponent:STATE_FILE_NAME]; + [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_STATE_FILE_NAME]; // either create or overwrite the payloads log file: [[NSFileManager defaultManager] createFileAtPath:payloadsFilePath @@ -1136,12 +1129,107 @@ - (void)captureTelemetryDataForNetwork:(BOOL)reachable { #endif } -// THIS IS ONLY FOR TESTS, DO NOT ACTUALLY USE THIS METHOD, HENCE BEING "PRIVATE" -- (NSThread *)_rollbarThread { +@end + +static NSString * const QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; + +@implementation RollbarLogger (Test) + ++ (void)clearSdkDataStore { + + [RollbarLogger clearLogItemsStore]; + [RollbarLogger _clearFile:[RollbarLogger _telemetryItemsStorePath]]; +} + ++ (void)clearLogItemsStore { + + [RollbarLogger _clearFile:[RollbarLogger _logItemsStoreStatePath]]; + [RollbarLogger _clearFile:[RollbarLogger _logItemsStorePath]]; +} + ++ (NSArray *)readLogItemsFromStore { + + NSString *filePath = [RollbarLogger _logItemsStorePath]; + RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath + andOffset:0]; + + NSMutableArray *items = [NSMutableArray array]; + [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { + NSError *error = nil; + NSMutableDictionary *payload = + [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding] + options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) + error:&error + ]; + if ((nil == payload) && (nil != error)) { + RollbarSdkLog(@"Error serializing log item from the store: %@", [error localizedDescription]); + return; + } + else if (nil == payload) { + RollbarSdkLog(@"Error serializing log item from the store!"); + return; + } + + NSMutableDictionary *data = payload[@"data"]; + [items addObject:data]; + }]; + + return items; +} + ++ (void)flushRollbarThread { + + [RollbarLogger performSelector:@selector(_test_doNothing) + onThread:[RollbarLogger _test_rollbarThread] + withObject:nil + waitUntilDone:YES + ]; +} + ++ (void)_clearFile:(nonnull NSString *)filePath { + + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSError *error; + BOOL fileExists = [fileManager fileExistsAtPath:filePath]; + + if (fileExists) { + BOOL success = [fileManager removeItemAtPath:filePath + error:&error]; + if (!success) { + NSLog(@"Error: %@", [error localizedDescription]); + } + [[NSFileManager defaultManager] createFileAtPath:filePath + contents:nil + attributes:nil]; + } +} + ++ (nonnull NSString *)_logItemsStorePath { + + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; +} + ++ (nonnull NSString *)_logItemsStoreStatePath { + + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_STATE_FILE_NAME]; +} + ++ (nonnull NSString *)_telemetryItemsStorePath { + + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + return [cachesDirectory stringByAppendingPathComponent:QUEUED_TELEMETRY_ITEMS_FILE_NAME]; +} + ++ (NSThread *)_test_rollbarThread { + return rollbarThread; } -- (void)_test_doNothing { ++ (void)_test_doNothing { + + // no-Op simulation... } @end diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h new file mode 100644 index 00000000..972d735d --- /dev/null +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h @@ -0,0 +1,27 @@ +// +// RollbarLogger+Test.h +// +// +// Created by Andrey Kornich on 2022-03-09. +// + +#import +#import "RollbarLogger.h" + +NS_ASSUME_NONNULL_BEGIN + +/// Test category of RollbarLogger +///@note THIS CATEGORY IS TO BE USED FOR TESTING PURPOSES ONLY. +@interface RollbarLogger (Test) + ++ (void)flushRollbarThread; ++ (NSArray *)readLogItemsFromStore; ++ (void)clearLogItemsStore; ++ (void)clearSdkDataStore; + +//- (NSThread *)_test_rollbarThread; +//- (void)_test_doNothing; + +@end + +NS_ASSUME_NONNULL_END diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m index b518a05e..09cf60f7 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m @@ -1,11 +1,12 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. @import Foundation; +//@import UnitTesting; #if !TARGET_OS_WATCH #import #import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" +//#import "RollbarTestUtil.h" //#import "../Rollbar/Notifier/RollbarPayloadTruncator.h" @import RollbarNotifier; @@ -18,7 +19,7 @@ @implementation PayloadTruncationTests - (void)setUp { [super setUp]; - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; @@ -193,8 +194,9 @@ - (void)testPayloadTruncation { [Rollbar errorException:exception]; } - RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *items = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); + NSArray *items = [RollbarLogger readLogItemsFromStore]; //RollbarReadLogItemFromFile(); for (id payload in items) { NSMutableArray *frames = [payload mutableArrayValueForKeyPath:@"body.trace.frames"]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m index 546a71bf..198e85b1 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m @@ -1,11 +1,12 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" +//#import "../../../UnitTests/RollbarUnitTestSettings.h" +//#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -17,7 +18,8 @@ @implementation RollbarTelemetryTests - (void)setUp { [super setUp]; - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; @@ -44,9 +46,11 @@ - (void)testTelemetryCapture { [Rollbar recordManualEventForLevel:RollbarLevel_Debug withData:@{@"data": @"content"}]; [Rollbar debugMessage:@"Test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); NSDictionary *item = logItems[0]; NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; XCTAssertTrue(telemetryData.count > 0); @@ -95,7 +99,8 @@ - (void)testErrorReportingWithTelemetry { //[NSThread sleepForTimeInterval:8.0f]; - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); for (NSDictionary *item in logItems) { NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h deleted file mode 100644 index 161eb9ea..00000000 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.h +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - -#import - -@import RollbarNotifier; - -void RollbarClearLogFile(void); -NSArray* RollbarReadLogItemFromFile(void); -void RollbarFlushFileThread(RollbarLogger *logger); - -@interface RollbarLogger (Tests) - -- (NSThread *)_rollbarThread; -- (void)_test_doNothing; - -@end diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m deleted file mode 100644 index 9eb67126..00000000 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTestUtil.m +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - -#import "RollbarTestUtil.h" -#import "RollbarFileReader.h" -#import "RollbarCachesDirectory.h" - -static NSString *QUEUED_ITEMS_FILE_NAME = @"rollbar.items"; -static NSString *QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; -static NSString *QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; - -NSString* _logFilePath() { - - NSString *cachesDirectory = [RollbarCachesDirectory directory]; - return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; -} - -void RollbarClearLogFile() { - - NSString *filePath = _logFilePath(); - NSFileManager *fileManager = [NSFileManager defaultManager]; - NSError *error; - BOOL fileExists = [fileManager fileExistsAtPath:filePath]; - - if (fileExists) { - BOOL success = [fileManager removeItemAtPath:filePath - error:&error]; - if (!success) { - NSLog(@"Error: %@", [error localizedDescription]); - } - [[NSFileManager defaultManager] createFileAtPath:filePath - contents:nil - attributes:nil]; - } -} - -NSArray* RollbarReadLogItemFromFile() { - - NSString *filePath = _logFilePath(); - RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath - andOffset:0]; - - NSMutableArray *items = [NSMutableArray array]; - [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { - NSMutableDictionary *payload = - [NSJSONSerialization JSONObjectWithData:[line dataUsingEncoding:NSUTF8StringEncoding] - options:(NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves) - error:nil - ]; - - - if (!payload) { - return; - } - - NSMutableDictionary *data = payload[@"data"]; - [items addObject:data]; - }]; - - return items; -} - -void RollbarFlushFileThread(RollbarLogger *logger) { - - [logger performSelector:@selector(_test_doNothing) - onThread:[logger _rollbarThread] withObject:nil waitUntilDone:YES]; -} diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m index 2df0acf2..5b49b1d3 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m @@ -1,11 +1,12 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" +//#import "../../../UnitTests/RollbarUnitTestSettings.h" +//#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -19,7 +20,8 @@ - (void)setUp { [super setUp]; - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); if (!Rollbar.currentConfiguration) { @@ -156,7 +158,8 @@ - (void)testNotification { [NSThread sleepForTimeInterval:3.0f]; - NSArray *items = RollbarReadLogItemFromFile(); + NSArray *items = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); for (id item in items) { NSString *level = [item valueForKeyPath:@"level"]; NSString *message = [item valueForKeyPath:@"body.message.body"]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/TestData/RollbarConfigurationTests.m similarity index 81% rename from RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m rename to RollbarNotifier/Tests/RollbarNotifierTests-ObjC/TestData/RollbarConfigurationTests.m index 1a9d3923..53a325c3 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/TestData/RollbarConfigurationTests.m @@ -1,11 +1,12 @@ // Copyright (c) 2018 Rollbar, Inc. All rights reserved. @import Foundation; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -#import "RollbarTestUtil.h" +//#import "../../../UnitTests/RollbarUnitTestSettings.h" +//#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -17,7 +18,10 @@ @implementation RollbarConfigurationTests - (void)setUp { [super setUp]; - RollbarClearLogFile(); + + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); + if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:@""]; } @@ -42,10 +46,13 @@ - (void)testScrubSafeListFields { [Rollbar.currentConfiguration.dataScrubber addScrubField:key]; } [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); // verify the fields were scrubbed: - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue([content isEqualToString:scrubedContent], @@ -56,17 +63,21 @@ - (void)testScrubSafeListFields { ); } - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); // define scrub whitelist fields (the same as the scrub fields - to counterbalance them): for (NSString *key in keys) { [Rollbar.currentConfiguration.dataScrubber addScrubSafeListField:key]; } [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); // verify the fields were not scrubbed: - logItems = RollbarReadLogItemFromFile(); + logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue(![content isEqualToString:scrubedContent], @@ -79,7 +90,9 @@ - (void)testScrubSafeListFields { } - (void)testTelemetryEnabled { - RollbarClearLogFile(); + + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); BOOL expectedFlag = NO; Rollbar.currentConfiguration.telemetry.enabled = expectedFlag; @@ -178,8 +191,10 @@ - (void)testViewInputTelemetrScrubFieldsConfig { - (void)testEnabled { - RollbarClearLogFile(); - NSArray *logItems = RollbarReadLogItemFromFile(); + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 0, @"logItems count is expected to be 0. Actual value is %lu", (unsigned long) logItems.count @@ -189,8 +204,10 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = NO; Rollbar.currentLogger.configuration.developerOptions.enabled = NO; [Rollbar debugMessage:@"Test1"]; - RollbarFlushFileThread(Rollbar.currentLogger); - logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); + logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 0, @"logItems count is expected to be 0. Actual value is %lu", (unsigned long) logItems.count @@ -198,8 +215,10 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = YES; [Rollbar debugMessage:@"Test2"]; - RollbarFlushFileThread(Rollbar.currentLogger); - logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); + logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"logItems count is expected to be 1. Actual value is %lu", (unsigned long) logItems.count @@ -207,14 +226,17 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = NO; [Rollbar debugMessage:@"Test3"]; - RollbarFlushFileThread(Rollbar.currentLogger); - logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); + logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"logItems count is expected to be 1. Actual value is %lu", (unsigned long) logItems.count ); - RollbarClearLogFile(); + [RollbarLogger clearSdkDataStore]; + //RollbarClearLogFile(); } - (void)testMaximumTelemetryEvents { @@ -232,8 +254,10 @@ - (void)testMaximumTelemetryEvents { [Rollbar reapplyConfiguration]; [Rollbar debugMessage:@"Test"]; - RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); NSDictionary *item = logItems[0]; NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; XCTAssertTrue(telemetryData.count == max, @@ -245,15 +269,18 @@ - (void)testMaximumTelemetryEvents { - (void)testCheckIgnore { [Rollbar debugMessage:@"Don't ignore this"]; - RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"Log item count should be 1"); Rollbar.currentConfiguration.checkIgnoreRollbarData = ^BOOL(RollbarData *payloadData) { return true; }; [Rollbar debugMessage:@"Ignore this"]; - logItems = RollbarReadLogItemFromFile(); + logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"Log item count should be 1"); } @@ -269,9 +296,11 @@ - (void)testServerData { ]; [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); NSDictionary *item = logItems[0]; NSDictionary *server = item[@"server"]; @@ -308,9 +337,11 @@ - (void)testPayloadModification { }; [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); NSString *msg1 = [logItems[0] valueForKeyPath:@"body.message.body"]; NSString *msg2 = [logItems[0] valueForKeyPath:@"body.message.body2"]; @@ -335,9 +366,11 @@ - (void)testScrubField { } [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue([content isEqualToString:scrubedContent], @@ -361,9 +394,11 @@ - (void)testLogTelemetryAutoCapture { NSLog(logMsg); [Rollbar debugMessage:@"test"]; - RollbarFlushFileThread(Rollbar.currentLogger); + [RollbarLogger flushRollbarThread]; + //RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *logItems = RollbarReadLogItemFromFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; + //RollbarReadLogItemFromFile(); NSArray *telemetryData = [logItems[0] valueForKeyPath:@"body.telemetry"]; NSString *telemetryMsg = [telemetryData[0] valueForKeyPath:@"body.message"]; XCTAssertTrue([logMsg isEqualToString:telemetryMsg], diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift index 20beb747..d23570ed 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift @@ -17,9 +17,9 @@ final class RollbarNotifierLoggerTests: XCTestCase { //if Rollbar.currentConfiguration() != nil { - Rollbar.initWithAccessToken(RollbarUnitTestSettings.payloadsPostAccessToken); - Rollbar.currentConfiguration()?.destination.accessToken = RollbarUnitTestSettings.payloadsPostAccessToken; - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.initWithAccessToken(RollbarTestHelper.getRollbarPayloadsAccessToken()); + Rollbar.currentConfiguration()?.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); Rollbar.currentConfiguration()?.developerOptions.transmit = true; Rollbar.currentConfiguration()?.developerOptions.logPayload = true; Rollbar.currentConfiguration()?.loggingOptions.maximumReportsPerMinute = 5000; @@ -87,8 +87,8 @@ final class RollbarNotifierLoggerTests: XCTestCase { //RollbarTestUtil.clearLogFile(); //RollbarTestUtil.clearTelemetryFile(); - Rollbar.currentConfiguration()?.destination.accessToken = RollbarUnitTestSettings.deploysWriteAccessToken; - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.currentConfiguration()?.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); Rollbar.currentConfiguration()?.developerOptions.transmit = true; Rollbar.currentConfiguration()?.developerOptions.transmit = true; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift index 806a4b59..f6f2cfd2 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift @@ -15,8 +15,8 @@ final class RollbarNotifierTelemetryTests: XCTestCase { print("Info: Rollbar already pre-configured!"); } else { - Rollbar.initWithAccessToken(RollbarUnitTestSettings.payloadsPostAccessToken); - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.initWithAccessToken(RollbarTestHelper.getRollbarPayloadsAccessToken()); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); } } diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift index ab409746..010fe1d1 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift @@ -15,8 +15,8 @@ final class RollbarNotifierTruncationTests: XCTestCase { RollbarTestUtil.clearTelemetryFile(); //if Rollbar.currentConfiguration() != nil { - Rollbar.initWithAccessToken(RollbarUnitTestSettings.payloadsPostAccessToken); - Rollbar.currentConfiguration()?.destination.environment = RollbarUnitTestSettings.environment; + Rollbar.initWithAccessToken(RollbarTestHelper.getRollbarPayloadsAccessToken()); + Rollbar.currentConfiguration()?.destination.environment = RollbarTestHelper.getRollbarEnvironment(); //} } diff --git a/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift b/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift index cbbc54c2..13467c60 100644 --- a/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift +++ b/RollbarSwift/Tests/RollbarSwiftTests/RollbarSwiftTests.swift @@ -18,8 +18,8 @@ final class RollbarSwiftTests: XCTestCase { func createGuard() -> RollbarExceptionGuard { let config = RollbarConfig(); - config.destination.accessToken = RollbarUnitTestSettings.payloadsPostAccessToken; - config.destination.environment = RollbarUnitTestSettings.environment; + config.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + config.destination.environment = RollbarTestHelper.getRollbarEnvironment(); config.developerOptions.transmit = true; let logger = RollbarLogger(configuration: config); diff --git a/UnitTesting/Sources/UnitTesting/RollbarTestHelper.m b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.m new file mode 100644 index 00000000..b4762bee --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.m @@ -0,0 +1,26 @@ +#import "RollbarTestHelper.h" +#import "RollbarUnitTestSettings.h" + +@implementation RollbarTestHelper + ++ (nonnull NSString *)getRollbarEnvironment { + + return ROLLBAR_UNIT_TEST_ENVIRONMENT; +} + ++ (nonnull NSString *)getRollbarPayloadsAccessToken { + + return ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN; +} + ++ (nonnull NSString *)getRollbarDeploysWriteAccessToken { + + return ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN; +} + ++ (nonnull NSString *)getRollbarDeploysReadAccessToken { + + return ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN; +} + +@end diff --git a/UnitTesting/Sources/UnitTesting/RollbarTestSettings.m b/UnitTesting/Sources/UnitTesting/RollbarTestSettings.m deleted file mode 100644 index 97d0edd0..00000000 --- a/UnitTesting/Sources/UnitTesting/RollbarTestSettings.m +++ /dev/null @@ -1,12 +0,0 @@ -// -// RollbarTestSettings.m -// -// -// Created by Andrey Kornich on 2022-03-08. -// - -#import "RollbarTestSettings.h" - -@implementation RollbarTestSettings - -@end diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h b/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h new file mode 100644 index 00000000..0c8e338e --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h @@ -0,0 +1,22 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface RollbarTestHelper : NSObject + +#pragma mark - class methods + ++ (nonnull NSString *)getRollbarEnvironment; ++ (nonnull NSString *)getRollbarPayloadsAccessToken; ++ (nonnull NSString *)getRollbarDeploysWriteAccessToken; ++ (nonnull NSString *)getRollbarDeploysReadAccessToken; + +#pragma mark - instance initializers + +/// Hides initializer +- (instancetype)init +NS_UNAVAILABLE; + +@end + +NS_ASSUME_NONNULL_END diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h b/UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h deleted file mode 100644 index 852c33ac..00000000 --- a/UnitTesting/Sources/UnitTesting/include/RollbarTestSettings.h +++ /dev/null @@ -1,16 +0,0 @@ -// -// RollbarTestSettings.h -// -// -// Created by Andrey Kornich on 2022-03-08. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface RollbarTestSettings : NSObject - -@end - -NS_ASSUME_NONNULL_END diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h b/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h index 69213114..c1156486 100644 --- a/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h +++ b/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h @@ -1,16 +1,16 @@ #ifndef RollbarUnitTestSettings_h #define RollbarUnitTestSettings_h -static NSString * const ROLLBAR_UNIT_TEST_ENVIRONMENT = +static NSString * _Nonnull const ROLLBAR_UNIT_TEST_ENVIRONMENT = @"Rollbar-Apple-UnitTests"; -static NSString * const ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN = +static NSString * _Nonnull const ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN = @"09da180aba21479e9ed3d91e0b8d58d6"; -static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN = +static NSString * _Nonnull const ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN = @"efdc4b85d66045f293a7f9e99c732f61"; -static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN = +static NSString * _Nonnull const ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN = @"595cbf76b05b45f2b3ef661a2e0078d4"; #endif /* RollbarUnitTestSettings_h */ From 492bc91c93235064f8d8f80f917eb84d74047cb0 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Wed, 9 Mar 2022 18:48:13 -0800 Subject: [PATCH 14/32] test: ref #134 cleanup related to the unit test infrastructure refactoring --- RollbarAUL/Package.swift | 13 ++--- .../RollbarAulStoreMonitorTest.m | 2 +- .../RollbarCocoaLumberjackTests.m | 6 +-- RollbarDeploys/Package.swift | 5 +- .../RollbarDeploysTests.m | 4 +- RollbarNotifier/Package.swift | 8 +-- .../Sources/RollbarNotifier/RollbarLogger.m | 8 +-- .../include/RollbarLogger+Test.h | 21 ++++---- .../PayloadTruncationTests.m | 15 +++--- .../RollbarConfigurationTests.m | 50 ++++++------------- .../RollbarTelemetryTests.m | 24 ++++----- .../RollbarNotifierTests-ObjC/RollbarTests.m | 9 ++-- .../contents.xcworkspacedata | 7 --- .../UnitTesting/include/RollbarTestHelper.h | 8 +++ UnitTests/RollbarUnitTestSettings.h | 16 ------ 15 files changed, 74 insertions(+), 122 deletions(-) rename RollbarNotifier/Tests/RollbarNotifierTests-ObjC/{TestData => }/RollbarConfigurationTests.m (90%) delete mode 100644 UnitTests/RollbarUnitTestSettings.h diff --git a/RollbarAUL/Package.swift b/RollbarAUL/Package.swift index 3cf02f7b..73bf410f 100644 --- a/RollbarAUL/Package.swift +++ b/RollbarAUL/Package.swift @@ -23,9 +23,7 @@ let package = Package( // .package(url: /* package url */, from: "1.0.0"), .package(path: "../RollbarCommon"), .package(path: "../RollbarNotifier"), - .package(name: "UnitTesting", - path: "../UnitTesting" - ), + .package(path: "../UnitTesting"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -36,8 +34,6 @@ let package = Package( publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/RollbarAUL/**"), -// .headerSearchPath("Sources/RollbarAUL"), -// .headerSearchPath("Sources/RollbarAUL/include"), // .headerSearchPath("Sources/RollbarAUL/DTOs"), // .define("DEFINES_MODULE"), @@ -52,11 +48,12 @@ let package = Package( ), .testTarget( name: "RollbarAULTests-ObjC", - dependencies: ["RollbarAUL"], + dependencies: [ + "UnitTesting", + "RollbarAUL" + ], cSettings: [ .headerSearchPath("Tests/RollbarAULTests-ObjC/**"), -// .headerSearchPath("Sources/RollbarNotifier"), -// .headerSearchPath("Sources/RollbarNotifier/include"), // .headerSearchPath("Sources/RollbarNotifier/DTOs"), // .define("DEFINES_MODULE"), diff --git a/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m b/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m index a656070e..7dbeb343 100644 --- a/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m +++ b/RollbarAUL/Tests/RollbarAULTests-ObjC/RollbarAulStoreMonitorTest.m @@ -15,8 +15,8 @@ #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" +@import UnitTesting; @import RollbarNotifier; @import RollbarAUL; diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m index 19a84cbf..ad498b0b 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -1,10 +1,7 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - #import -//#import "RollbarTestUtil.h" #define LOG_LEVEL_DEF ddLogLevel -//#import + @import CocoaLumberjack; @import RollbarNotifier; @import UnitTesting; @@ -26,7 +23,6 @@ - (void)setUp { NSLog(@"Set to go..."); [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); [DDLog addLogger:[DDOSLogger sharedInstance]]; diff --git a/RollbarDeploys/Package.swift b/RollbarDeploys/Package.swift index 51740e02..22a1cd38 100644 --- a/RollbarDeploys/Package.swift +++ b/RollbarDeploys/Package.swift @@ -49,7 +49,10 @@ let package = Package( ), .testTarget( name: "RollbarDeploysTests-ObjC", - dependencies: ["RollbarDeploys"], + dependencies: [ + "UnitTesting", + "RollbarDeploys", + ], cSettings: [ .headerSearchPath("Tests/RollbarDeploysTests-ObjC/**"), // .headerSearchPath("Sources/RollbarDeploys"), diff --git a/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m b/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m index 7b6e8360..45ad164b 100644 --- a/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m +++ b/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m @@ -1,8 +1,6 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" +@import UnitTesting; @import RollbarDeploys; @interface RollbarDeploysObserver : NSObject diff --git a/RollbarNotifier/Package.swift b/RollbarNotifier/Package.swift index 41e9d9f5..cec121eb 100644 --- a/RollbarNotifier/Package.swift +++ b/RollbarNotifier/Package.swift @@ -33,10 +33,8 @@ let package = Package( publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/RollbarNotifier/**"), -// .headerSearchPath("Sources/RollbarNotifier"), -// .headerSearchPath("Sources/RollbarNotifier/include"), -// .headerSearchPath("Sources/RollbarNotifier/DTOs"), - + // .headerSearchPath("Sources/RollbarNotifier/DTOs"), + // .define("DEFINES_MODULE"), ] ), @@ -55,8 +53,6 @@ let package = Package( ], cSettings: [ .headerSearchPath("Tests/RollbarNotifierTests-ObjC/**"), -// .headerSearchPath("Sources/RollbarNotifier"), -// .headerSearchPath("Sources/RollbarNotifier/include"), // .headerSearchPath("Sources/RollbarNotifier/DTOs"), // .define("DEFINES_MODULE"), diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m index 9d9f10ba..ae379503 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m @@ -23,13 +23,13 @@ static NSString * const QUEUED_ITEMS_STATE_FILE_NAME = @"rollbar.state"; static NSString * const PAYLOADS_FILE_NAME = @"rollbar.payloads"; -// Rollbar API Service enforced payload rate limit: +/// Rollbar API Service enforced payload rate limit: static NSString * const RESPONSE_HEADER_RATE_LIMIT = @"x-rate-limit-limit"; -// Rollbar API Service enforced remaining payload count until the limit is reached: +/// Rollbar API Service enforced remaining payload count until the limit is reached: static NSString * const RESPONSE_HEADER_REMAINING_COUNT = @"x-rate-limit-remaining"; -// Rollbar API Service enforced rate limit reset time for the current limit window: +/// Rollbar API Service enforced rate limit reset time for the current limit window: static NSString * const RESPONSE_HEADER_RESET_TIME = @"x-rate-limit-reset"; -// Rollbar API Service enforced rate limit remaining seconds of the current limit window: +/// Rollbar API Service enforced rate limit remaining seconds of the current limit window: static NSString * const RESPONSE_HEADER_REMAINING_SECONDS = @"x-rate-limit-remaining-seconds"; static NSUInteger MAX_RETRY_COUNT = 5; diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h index 972d735d..622e30bb 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h @@ -1,10 +1,3 @@ -// -// RollbarLogger+Test.h -// -// -// Created by Andrey Kornich on 2022-03-09. -// - #import #import "RollbarLogger.h" @@ -14,13 +7,21 @@ NS_ASSUME_NONNULL_BEGIN ///@note THIS CATEGORY IS TO BE USED FOR TESTING PURPOSES ONLY. @interface RollbarLogger (Test) +/// Returns after all the queued up payloads are processed by the RollbarThread +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. + (void)flushRollbarThread; + +/// Reads all the payloads queued up in the persistent store +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. + (NSArray *)readLogItemsFromStore; + +/// Clears all the payloads queued up in the persistent store +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. + (void)clearLogItemsStore; -+ (void)clearSdkDataStore; -//- (NSThread *)_test_rollbarThread; -//- (void)_test_doNothing; +/// Clears all the SDK persisted data +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (void)clearSdkDataStore; @end diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m index 09cf60f7..93fcffcc 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m @@ -1,13 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; -//@import UnitTesting; +@import UnitTesting; #if !TARGET_OS_WATCH #import -#import "../../../UnitTests/RollbarUnitTestSettings.h" -//#import "RollbarTestUtil.h" -//#import "../Rollbar/Notifier/RollbarPayloadTruncator.h" @import RollbarNotifier; @@ -18,8 +13,11 @@ @interface PayloadTruncationTests : XCTestCase @implementation PayloadTruncationTests - (void)setUp { + [super setUp]; + [RollbarLogger clearSdkDataStore]; + if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; @@ -27,6 +25,7 @@ - (void)setUp { } - (void)tearDown { + [Rollbar updateConfiguration:[RollbarConfig new]]; [super tearDown]; } @@ -195,8 +194,8 @@ - (void)testPayloadTruncation { } [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); - NSArray *items = [RollbarLogger readLogItemsFromStore]; //RollbarReadLogItemFromFile(); + + NSArray *items = [RollbarLogger readLogItemsFromStore]; for (id payload in items) { NSMutableArray *frames = [payload mutableArrayValueForKeyPath:@"body.trace.frames"]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/TestData/RollbarConfigurationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m similarity index 90% rename from RollbarNotifier/Tests/RollbarNotifierTests-ObjC/TestData/RollbarConfigurationTests.m rename to RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m index 53a325c3..31de609a 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/TestData/RollbarConfigurationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarConfigurationTests.m @@ -1,12 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; @import UnitTesting; #if !TARGET_OS_WATCH #import -//#import "../../../UnitTests/RollbarUnitTestSettings.h" -//#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -17,10 +13,10 @@ @interface RollbarConfigurationTests : XCTestCase @implementation RollbarConfigurationTests - (void)setUp { + [super setUp]; [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:@""]; @@ -28,16 +24,19 @@ - (void)setUp { } - (void)tearDown { + [Rollbar updateConfiguration:[RollbarConfig new]]; [super tearDown]; } - (void)testDefaultRollbarConfiguration { + RollbarConfig *rc = [RollbarConfig new]; NSLog(@"%@", rc); } - (void)testScrubSafeListFields { + NSString *scrubedContent = @"*****"; NSArray *keys = @[@"client.ios.app_name", @"client.ios.os_version", @"body.message.body"]; @@ -48,11 +47,9 @@ - (void)testScrubSafeListFields { [Rollbar debugMessage:@"test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); // verify the fields were scrubbed: NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue([content isEqualToString:scrubedContent], @@ -64,7 +61,6 @@ - (void)testScrubSafeListFields { } [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); // define scrub whitelist fields (the same as the scrub fields - to counterbalance them): for (NSString *key in keys) { @@ -73,11 +69,9 @@ - (void)testScrubSafeListFields { [Rollbar debugMessage:@"test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); // verify the fields were not scrubbed: logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue(![content isEqualToString:scrubedContent], @@ -92,7 +86,6 @@ - (void)testScrubSafeListFields { - (void)testTelemetryEnabled { [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); BOOL expectedFlag = NO; Rollbar.currentConfiguration.telemetry.enabled = expectedFlag; @@ -192,9 +185,8 @@ - (void)testViewInputTelemetrScrubFieldsConfig { - (void)testEnabled { [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 0, @"logItems count is expected to be 0. Actual value is %lu", (unsigned long) logItems.count @@ -205,9 +197,8 @@ - (void)testEnabled { Rollbar.currentLogger.configuration.developerOptions.enabled = NO; [Rollbar debugMessage:@"Test1"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); + logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 0, @"logItems count is expected to be 0. Actual value is %lu", (unsigned long) logItems.count @@ -216,9 +207,8 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = YES; [Rollbar debugMessage:@"Test2"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); + logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"logItems count is expected to be 1. Actual value is %lu", (unsigned long) logItems.count @@ -227,16 +217,14 @@ - (void)testEnabled { Rollbar.currentConfiguration.developerOptions.enabled = NO; [Rollbar debugMessage:@"Test3"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); + logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"logItems count is expected to be 1. Actual value is %lu", (unsigned long) logItems.count ); [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); } - (void)testMaximumTelemetryEvents { @@ -255,9 +243,8 @@ - (void)testMaximumTelemetryEvents { [Rollbar debugMessage:@"Test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); NSDictionary *item = logItems[0]; NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; XCTAssertTrue(telemetryData.count == max, @@ -268,11 +255,11 @@ - (void)testMaximumTelemetryEvents { } - (void)testCheckIgnore { + [Rollbar debugMessage:@"Don't ignore this"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); + NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"Log item count should be 1"); Rollbar.currentConfiguration.checkIgnoreRollbarData = ^BOOL(RollbarData *payloadData) { @@ -280,11 +267,11 @@ - (void)testCheckIgnore { }; [Rollbar debugMessage:@"Ignore this"]; logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); XCTAssertTrue(logItems.count == 1, @"Log item count should be 1"); } - (void)testServerData { + NSString *host = @"testHost"; NSString *root = @"testRoot"; NSString *branch = @"testBranch"; @@ -297,10 +284,8 @@ - (void)testServerData { [Rollbar debugMessage:@"test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); NSDictionary *item = logItems[0]; NSDictionary *server = item[@"server"]; @@ -327,6 +312,7 @@ - (void)testServerData { } - (void)testPayloadModification { + NSString *newMsg = @"Modified message"; Rollbar.currentConfiguration.modifyRollbarData = ^RollbarData *(RollbarData *payloadData) { // [payloadData setValue:newMsg forKeyPath:@"body.message.body"]; @@ -338,10 +324,8 @@ - (void)testPayloadModification { [Rollbar debugMessage:@"test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); NSString *msg1 = [logItems[0] valueForKeyPath:@"body.message.body"]; NSString *msg2 = [logItems[0] valueForKeyPath:@"body.message.body2"]; @@ -358,6 +342,7 @@ - (void)testPayloadModification { } - (void)testScrubField { + NSString *scrubedContent = @"*****"; NSArray *keys = @[@"client.ios.app_name", @"client.ios.os_version", @"body.message.body"]; @@ -367,10 +352,8 @@ - (void)testScrubField { [Rollbar debugMessage:@"test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); for (NSString *key in keys) { NSString *content = [logItems[0] valueForKeyPath:key]; XCTAssertTrue([content isEqualToString:scrubedContent], @@ -383,9 +366,10 @@ - (void)testScrubField { } - (void)testLogTelemetryAutoCapture { + NSString *logMsg = @"log-message-testing"; [[RollbarTelemetry sharedInstance] clearAllData]; - //Rollbar.currentConfiguration.accessToken = ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN; + Rollbar.currentConfiguration.telemetry.enabled = YES; Rollbar.currentConfiguration.telemetry.captureLog = YES; [Rollbar reapplyConfiguration]; @@ -395,10 +379,8 @@ - (void)testLogTelemetryAutoCapture { [Rollbar debugMessage:@"test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); NSArray *telemetryData = [logItems[0] valueForKeyPath:@"body.telemetry"]; NSString *telemetryMsg = [telemetryData[0] valueForKeyPath:@"body.message"]; XCTAssertTrue([logMsg isEqualToString:telemetryMsg], diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m index 198e85b1..75284b56 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m @@ -1,12 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; @import UnitTesting; #if !TARGET_OS_WATCH #import -//#import "../../../UnitTests/RollbarUnitTestSettings.h" -//#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -17,9 +13,11 @@ @interface RollbarTelemetryTests : XCTestCase @implementation RollbarTelemetryTests - (void)setUp { + [super setUp]; + [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); + if (!Rollbar.currentConfiguration) { [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; @@ -32,9 +30,8 @@ - (void)tearDown { [super tearDown]; } -- (void)doNothing {} - - (void)testTelemetryCapture { + Rollbar.currentConfiguration.telemetry.enabled = YES; [Rollbar reapplyConfiguration]; @@ -47,10 +44,8 @@ - (void)testTelemetryCapture { [Rollbar debugMessage:@"Test"]; [RollbarLogger flushRollbarThread]; - //RollbarFlushFileThread(Rollbar.currentLogger); NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); NSDictionary *item = logItems[0]; NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; XCTAssertTrue(telemetryData.count > 0); @@ -82,15 +77,17 @@ - (void)testTelemetryCapture { } - (void)testErrorReportingWithTelemetry { + Rollbar.currentConfiguration.telemetry.enabled = YES; [Rollbar recordNavigationEventForLevel:RollbarLevel_Info from:@"SomeNavigationSource" to:@"SomeNavigationDestination"]; [Rollbar recordConnectivityEventForLevel:RollbarLevel_Info status:@"SomeConnectivityStatus"]; [Rollbar recordNetworkEventForLevel:RollbarLevel_Info method:@"POST" url:@"www.myservice.com" statusCode:@"200" extraData:nil]; [Rollbar recordErrorEventForLevel:RollbarLevel_Debug message:@"Some telemetry message..."]; - [Rollbar recordErrorEventForLevel:RollbarLevel_Error exception:[NSException exceptionWithName:@"someExceptionName" - reason:@"someExceptionReason" - userInfo:nil]]; + [Rollbar recordErrorEventForLevel:RollbarLevel_Error exception: + [NSException exceptionWithName:@"someExceptionName" + reason:@"someExceptionReason" + userInfo:nil]]; [Rollbar recordManualEventForLevel:RollbarLevel_Debug withData:@{@"myTelemetryParameter": @"itsValue"}]; [Rollbar debugMessage:@"Demonstrate Telemetry capture"]; @@ -100,7 +97,6 @@ - (void)testErrorReportingWithTelemetry { //[NSThread sleepForTimeInterval:8.0f]; NSArray *logItems = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); for (NSDictionary *item in logItems) { NSArray *telemetryData = [item valueForKeyPath:@"body.telemetry"]; @@ -133,6 +129,7 @@ - (void)testErrorReportingWithTelemetry { } - (void)testTelemetryViewEventScrubbing { + Rollbar.currentConfiguration.telemetry.enabled = YES; Rollbar.currentConfiguration.telemetry.viewInputsScrubber.enabled = YES; [Rollbar.currentConfiguration.telemetry.viewInputsScrubber addScrubField:@"password"]; @@ -156,6 +153,7 @@ - (void)testTelemetryViewEventScrubbing { } - (void)testRollbarLog { + Rollbar.currentConfiguration.telemetry.enabled = YES; Rollbar.currentConfiguration.telemetry.captureLog = YES; [Rollbar reapplyConfiguration]; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m index 5b49b1d3..d79e31c1 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m @@ -1,12 +1,8 @@ -// Copyright (c) 2018 Rollbar, Inc. All rights reserved. - @import Foundation; @import UnitTesting; #if !TARGET_OS_WATCH #import -//#import "../../../UnitTests/RollbarUnitTestSettings.h" -//#import "RollbarTestUtil.h" @import RollbarNotifier; @@ -21,7 +17,6 @@ - (void)setUp { [super setUp]; [RollbarLogger clearSdkDataStore]; - //RollbarClearLogFile(); if (!Rollbar.currentConfiguration) { @@ -41,11 +36,13 @@ - (void)setUp { } - (void)tearDown { + [Rollbar updateConfiguration:[RollbarConfig new]]; [super tearDown]; } - (void)testMultithreadedStressCase { + for( int i = 0; i < 20; i++) { dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY,0), ^(){ RollbarLogger *logger = [[RollbarLogger alloc] initWithAccessToken:Rollbar.currentConfiguration.destination.accessToken]; @@ -136,6 +133,7 @@ - (void)testRollbarTransmit { } - (void)testNotification { + NSDictionary *notificationText = @{ @"error": @[@"testing-error-with-message"], @"debug": @[@"testing-debug"], @@ -159,7 +157,6 @@ - (void)testNotification { [NSThread sleepForTimeInterval:3.0f]; NSArray *items = [RollbarLogger readLogItemsFromStore]; - //RollbarReadLogItemFromFile(); for (id item in items) { NSString *level = [item valueForKeyPath:@"level"]; NSString *message = [item valueForKeyPath:@"body.message.body"]; diff --git a/RollbarSDK.xcworkspace/contents.xcworkspacedata b/RollbarSDK.xcworkspace/contents.xcworkspacedata index 73e5248d..dc3a491b 100644 --- a/RollbarSDK.xcworkspace/contents.xcworkspacedata +++ b/RollbarSDK.xcworkspace/contents.xcworkspacedata @@ -4,13 +4,6 @@ - - - - diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h b/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h index 0c8e338e..79f075ef 100644 --- a/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h +++ b/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h @@ -2,13 +2,21 @@ NS_ASSUME_NONNULL_BEGIN +/// Utility class aiding in implementing SDK's unit tests @interface RollbarTestHelper : NSObject #pragma mark - class methods +/// returns Rollbar environment dedicated to the SDK's unit tests + (nonnull NSString *)getRollbarEnvironment; + +/// returns Rollbar access token dedicated to the payloads sent by SDK's live unit tests + (nonnull NSString *)getRollbarPayloadsAccessToken; + +/// returns Rollbar WRITE access token dedicated to the deploys registered by SDK's live unit tests + (nonnull NSString *)getRollbarDeploysWriteAccessToken; + +/// returns Rollbar READ access token dedicated to iterating over the deploys registered by SDK's live unit tests + (nonnull NSString *)getRollbarDeploysReadAccessToken; #pragma mark - instance initializers diff --git a/UnitTests/RollbarUnitTestSettings.h b/UnitTests/RollbarUnitTestSettings.h deleted file mode 100644 index 69213114..00000000 --- a/UnitTests/RollbarUnitTestSettings.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef RollbarUnitTestSettings_h -#define RollbarUnitTestSettings_h - -static NSString * const ROLLBAR_UNIT_TEST_ENVIRONMENT = -@"Rollbar-Apple-UnitTests"; - -static NSString * const ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN = -@"09da180aba21479e9ed3d91e0b8d58d6"; - -static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN = -@"efdc4b85d66045f293a7f9e99c732f61"; - -static NSString * const ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN = -@"595cbf76b05b45f2b3ef661a2e0078d4"; - -#endif /* RollbarUnitTestSettings_h */ From 74cdb7321308a2b64c492d9d5df1bb363e38dcb8 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 14:53:56 -0700 Subject: [PATCH 15/32] docs: ref #138 --- README.md | 7 ++- docs/README.md | 6 +++ docs/SDK overview.md | 108 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 docs/README.md create mode 100644 docs/SDK overview.md diff --git a/README.md b/README.md index 7b23d745..abbf7c6d 100644 --- a/README.md +++ b/README.md @@ -83,4 +83,9 @@ See our [Releases](https://github.com/rollbar/rollbar-apple/releases) page for a ## Help / Support -If you run into any problems, please email us at `support@rollbar.com` or [file a bug report](https://github.com/rollbar/rollbar-apple/issues/new). +- [Gitter Community](https://gitter.im/rollbar/SDK-Apple) +- [Stack Overflow](https://stackoverflow.com/questions/tagged/rollbar) +- [GitHub Issues](https://github.com/rollbar/rollbar-apple/issues) +- [GitHub Discussions](https://github.com/rollbar/rollbar-apple/discussions) +- [File a bug report](https://github.com/rollbar/rollbar-apple/issues/new) +- Rollbar Support: `support@rollbar.com` \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..0c765f97 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,6 @@ +# Rollbar-Apple SDK Documentation Folder + + +# Help / Support + +If you run into any problems, please email us at `support@rollbar.com` or [file a bug report](https://github.com/rollbar/rollbar-apple/issues/new). diff --git a/docs/SDK overview.md b/docs/SDK overview.md new file mode 100644 index 00000000..ea63af74 --- /dev/null +++ b/docs/SDK overview.md @@ -0,0 +1,108 @@ +# Rollbar-Apple SDK + +**Rollbar SDK for any Apple *OS (macOS, ipadOS, iOS, tvOS, watchOS, ...)** + +**Written in Objective-C. Works with Swift** + +--- + +[TOC] + +## What is Rollbar-Apple SDK? + +Objective-C & Swift SDK for remote crash, exception, error reporting, and logging with Rollbar. + +It works on all Apple *OS platforms (macOS, ipadOS, iOS, tvOS, watchOS, etc). + +It is the preferred SDK for sending log payloads to [Rollbar](http://rollbar.com). + +## How is Rollbar-Apple SDK different from Rollbar-iOS SDK? + +Look at Rollbar-Apple SDK as the next major reincarnation of Rollbar-iOS SDK. +It is v2 of Rollbar-iOS SDK under a new name that better describes its purpose. + +Rollbar-iOS will be available for a while to allow our customers to make a move to Rollbar-Apple SDK when it most convenient to them. + +All the new feature development will be happening here within Rollbar-Apple SDK. + +## Where can I get the SDK from? + +Rollbar-Apple SDK is an open-source project available on GitHub. +Its releases are published on GitHub as well. +The SDK can also be integrated into your codebase from the following package distribution systems: + +- Swift Package Manager (also known as SwiftPM or SPM) +- Cocoapods +- Carthage + +## Pay Attention + +Depending on the specific package management system, the SDK is available either as the whole (under `Rollbar-Apple` name) or on a per-module basis (for example, `RollbarCommon`, `RollbarNotifier`, `RollbarDeploys`, etc). + +Some package distribution systems also host packages associated with the older incarnation of this SDK, called Rollbar-iOS, that used to be published under Rollbar package name and versioned at either `v0.n.n` or `v1.n.n`. + +All the Rollbar-Apple SDK releases (and packages) versioned starting from v2 (since, as we already explained above, Rollbar-Apple is the `v2` of Rollbar-iOS SDK renamed into Rollbar-Apple). + + +## Getting Help and Support + +- [Gitter Community](https://gitter.im/rollbar/SDK-Apple) +- [Stack Overflow](https://stackoverflow.com/questions/tagged/rollbar) +- [GitHub Issues](https://github.com/rollbar/rollbar-apple/issues) +- [GitHub Discussions](https://github.com/rollbar/rollbar-apple/discussions) +- [File a bug report](https://github.com/rollbar/rollbar-apple/issues/new) +- Rollbar Support: `support@rollbar.com` + +## SDK Modules/Packages + +*RollbarNotifier* is the package that implements the `RollbarLogger` (i.e. Notifier) - that is the thing that supports a lot of configurational options and allows to capture, package, and forward (to the preconfigured Rollbar Project on rollbar.com) exceptions, errors, log messages, telemetry, and custom data. + +We offer a couple of optional crash reporting alternatives - one based on *KSCrash* and another one based on *PLCrashReporter*. Each package (*RollbarKSCrash*` or `*RollbarPLCrashReporter*) implements its own crash report collector adapter to a corresponding third-party crash reporter. +A collector is optional and can be supplied into a notifier (`RollbarLogger`) initializer along with the required `RollbarConfig` instance. + +*RollbarAUL* module implements *RollbarNotifier* integration with Apple Unified Logging (AUL) and allows capture of the AUL entries as corresponding Rollbar Telemetry log events. + +*RollbarSwift* implements components useful in cases when the SDK is used by a client code written in Swift. For example, any call chain made from Swift that eventually resolves into an Objective-C code being invoked can potentially produce an NSException that Swift cannot handle natively. So, the module provides utility classes and components that are helping to either handle or process such scenarios. + +*RollbarDeploys* is the package that should be used, for example by your CI Release pipeline, to track/manage your application releases/deployments so they are reported to the Rollbar Project and Rollbar would correlate the incoming payloads with specific deployment instance. + +*RollbarCommon* is just a shared package with types used by any of the other packages as well as some potentially useful public utility classes that you may find useful. + +## Installation + +Here are a few alternatives for installing the SDK into your software projects: + +### Via [GitHub](https://github.com/rollbar/rollbar-apple) + +Here are a few options: + +- you can download or clone the SDK source code directly from the GitHub repo; +- you can download a source code snapshot of a specific release from the repo Release page; +- you can integrate the the GitHub repo as a git submodule of your project git repository. + +### Via [Swift Package Manager](https://github.com/apple/swift-package-manager) + +For example, in Xcode, by pointing your project's build target SPM settings to https://github.com/rollbar/rollbar-apple.git repository and specifying the desired release version, or branch, or commit. + +### Via [Carthage](https://github.com/Carthage/Carthage) + +In your *Cartfile*, specify: + +```txt +github "rollbar/rollbar-apple" ~> n.n.n +``` + +where `n.n.n` is the desired pod version of the SDK to use. + +### Via [Cocoapods](https://cocoapods.org/) + +The SDK is configured for *Cocoapods* distribution on a pod-per-module basis, so you will have to separately specify each module pod dependency as needed. For example: + +```txt +pod "RollbarNotifier", "~> n.n.n" +pod "RollbarDeploys", "~> n.n.n" +``` + +where `n.n.n` is the desired pod version of the SDK to use. As the general rule, for multiple modules try using the same version. + +You do not have to worry about explicitly including other internal dependencies of the modules, like *RollbarCommon* module pod. The SDK modules' *podspec*s already specify these as needed. From 52330faa28d1a6ae6d317ee5a0d0862919717a55 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 15:25:43 -0700 Subject: [PATCH 16/32] docs: ref #138 --- docs/SDK overview.md | 76 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/docs/SDK overview.md b/docs/SDK overview.md index ea63af74..c4516ed0 100644 --- a/docs/SDK overview.md +++ b/docs/SDK overview.md @@ -1,6 +1,6 @@ # Rollbar-Apple SDK -**Rollbar SDK for any Apple *OS (macOS, ipadOS, iOS, tvOS, watchOS, ...)** +**Rollbar SDK for any Apple \*OS (macOS, ipadOS, iOS, tvOS, watchOS, ...)** **Written in Objective-C. Works with Swift** @@ -106,3 +106,77 @@ pod "RollbarDeploys", "~> n.n.n" where `n.n.n` is the desired pod version of the SDK to use. As the general rule, for multiple modules try using the same version. You do not have to worry about explicitly including other internal dependencies of the modules, like *RollbarCommon* module pod. The SDK modules' *podspec*s already specify these as needed. + +## Using SDK in Your Code + +### Import Necessary SDK Modules + +Before using any of the types provided by the SDK modules, you need to make sure you import the modules you need. For example: + +```Obj-C +@import RollbarNotifier; +@import RollbarKSCrash; // optional +@import RollbarPLCrashReporter; // optional alternative to RollbarKSCrash +``` + +```Swift +import RollbarNotifier +import RollbarKSCrash // optional +import RollbarPLCrashReporter // optional alternative to RollbarKSCrash +``` + +### Define the Shared Notifier's Configuration Instance + +When setting up a notifier configuration you must at least specify your Rollbar Project's access token: + +```Obj-C +RollbarConfig *config = [RollbarConfig new]; +config.destination.accessToken = @"YOUR_PROJECT_ACCESS_TOKEN"; +config.destination.environment = @"YOUR_ENVIRONMENT"; +``` + +```Swift +let config = RollbarConfig() +config.destination.accessToken = "YOUR_PROJECT_ACCESS_TOKEN" +config.destination.environment = "ENVIRONMENT" +``` + +### Optionally, Define A Crash Report Collector Instance + +```Obj-C + +id crashCollector = + [[RollbarPLCrashCollector alloc] init]; + //OR [[RollbarKSCrashCollector alloc] init]; + //OR nil; +``` + +```Swift + +let crashCollector = RollbarPLCrashCollector() +//OR let crashCollector = RollbarKSCrashCollector() +``` + +### Initialize the Shared Notifier + +```Obj-C +[Rollbar initWithConfiguration:config]; +//OR [Rollbar initWithConfiguration:config crashCollector:crashCollector]; +``` + +```Swift +Rollbar.initWithConfiguration(config) +//OR Rollbar.initWithConfiguration(config, crashCollector: crashCollector) +``` + +### Start Logging using the Shared Notifier + +```Obj-C +[Rollbar infoMessage:@"See this message on your Rollbar Project Dashboard..."]; +``` + +```Swift +Rollbar.infoMessage("See this message on your Rollbar Project Dashboard...") +``` + +There are other dedicated method overloads for logging `NSException`s, `NSError`s with different levels of log severity. \ No newline at end of file From c82585c2ef5bd012d6647b98454be4a1e2953a50 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 15:31:52 -0700 Subject: [PATCH 17/32] docs: ref #138 --- docs/SDK module - RollbarSwift.md | 56 +++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 docs/SDK module - RollbarSwift.md diff --git a/docs/SDK module - RollbarSwift.md b/docs/SDK module - RollbarSwift.md new file mode 100644 index 00000000..c83ac3a7 --- /dev/null +++ b/docs/SDK module - RollbarSwift.md @@ -0,0 +1,56 @@ +# SDK Module: RollbarSwift + +This module implements components useful in cases when the SDK is used by a client code written in Swift. For example, any call chain made from Swift that eventually resolves into an Objective-C code being invoked can potentially produce an NSException that Swift cannot handle natively. So, the RollbarSwift module provides utility classes and components that are helping to either handle or process such scenarios. + +--- + +## Essential Components of the Module + +### `RollbarTryCatch` + +This utility class provides an API to try Swift code blocks and to catch and to either handle or process any of `NSException` instances if thrown from the tried block. + +### `RollbarExceptionGuard` + +This component is meant to be initialized with a preconfigured instance of `RollbarLogger` so it can be used to try/guard a block of Swift code in cases when it might cause throwing of an `NSException` and to automatically report such `NSException` (if any) to a Rollbar.com Project. It also provides an alternative method that in addition converts the intercepted `NSException` into a matching `NSError` that could be natively tied and handled from within the Swift code. + +## Examples + +### Guarding Swift code that could potentially throw a NSException and reporting the exception (if any) to Rollbar + +```Swift +func generateObjCException() { + + //simulating Obj-C NSException: + RollbarTryCatch.throw("NSException from Obj-C..."); +} + +func handleObjCExceptionWithRollbar() { + + let exceptionGuard = createGuard(); + var success = true; + //execute code block while guarding it with RollbarExceptionGuard: + success = exceptionGuard.tryExecute { + self.generateObjCException(); + } + //if there was an NSException thrown withing the guarded block of code, + //the guard instance would return NO and internally report the + //exception details to Rollbar. + + print("Guarded execution succeeded: \(success)."); +} + +func createGuard() -> RollbarExceptionGuard { + + let config = RollbarConfig(); + config.destination.accessToken = "2ff...0f3"; + config.destination.environment = "samples"; + config.developerOptions.transmit = true; + + let logger = RollbarLogger(configuration: config); + + let exceptionGuard = RollbarExceptionGuard(logger: logger); + + return exceptionGuard; +} +``` From a2cc3a1a746b0e0bcd8401603e451050f7368b53 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 15:37:28 -0700 Subject: [PATCH 18/32] docs: ref #138 --- docs/{SDK overview.md => SDK Intro.md} | 0 docs/SDK module - RollbarSwift.md | 2 +- docs/SDK module - RollbarZZZ.md | 27 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) rename docs/{SDK overview.md => SDK Intro.md} (100%) create mode 100644 docs/SDK module - RollbarZZZ.md diff --git a/docs/SDK overview.md b/docs/SDK Intro.md similarity index 100% rename from docs/SDK overview.md rename to docs/SDK Intro.md diff --git a/docs/SDK module - RollbarSwift.md b/docs/SDK module - RollbarSwift.md index c83ac3a7..66ff8d3c 100644 --- a/docs/SDK module - RollbarSwift.md +++ b/docs/SDK module - RollbarSwift.md @@ -14,7 +14,7 @@ This utility class provides an API to try Swift code blocks and to catch and to This component is meant to be initialized with a preconfigured instance of `RollbarLogger` so it can be used to try/guard a block of Swift code in cases when it might cause throwing of an `NSException` and to automatically report such `NSException` (if any) to a Rollbar.com Project. It also provides an alternative method that in addition converts the intercepted `NSException` into a matching `NSError` that could be natively tied and handled from within the Swift code. -## Examples +## Examples ### Guarding Swift code that could potentially throw a NSException and reporting the exception (if any) to Rollbar diff --git a/docs/SDK module - RollbarZZZ.md b/docs/SDK module - RollbarZZZ.md new file mode 100644 index 00000000..64524ca2 --- /dev/null +++ b/docs/SDK module - RollbarZZZ.md @@ -0,0 +1,27 @@ +# SDK Module: RollbarZZZ + +This module implements components useful in cases when the SDK is used ... + +--- + +## Essential Components of the Module + +### `RollbarComp1` + +This utility class provides ... + +### `RollbarComp2` + +This component is meant to be initialized with ... + +## Examples + +### Example title + +```Obj-C + +``` + +```Swift + +``` From 92d34104d138117546d71c9ddca2a69cc0e50559 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 15:52:42 -0700 Subject: [PATCH 19/32] docs: resolve #138 --- docs/SDK module - RollbarAUL.md | 99 +++++++++++++++++++++++++++++++ docs/SDK module - RollbarSwift.md | 2 + docs/SDK module - RollbarZZZ.md | 4 ++ 3 files changed, 105 insertions(+) create mode 100644 docs/SDK module - RollbarAUL.md diff --git a/docs/SDK module - RollbarAUL.md b/docs/SDK module - RollbarAUL.md new file mode 100644 index 00000000..f1b97a9c --- /dev/null +++ b/docs/SDK module - RollbarAUL.md @@ -0,0 +1,99 @@ +# SDK Module: RollbarAUL + +This module implements `RollbarNotifier` integration with *Apple Unified Logging (AUL)* and allows capture of the AUL entries as corresponding Rollbar Telemetry log events. + +--- + +## Essential Components of the Module + +### `RollbarAulStoreMonitorOptions` DTO + +It implements configurational options for collecting relevant log entries from the Apple Unified Logging (AUL) store. +You can specify here lists of AUL subsystems and categories of interest. When these lists are empty, all the entries from the local AUL store related to the application process will be collected from the store. + +### `RollbarAulStoreMonitor` Service + +It implements a singleton-like component that monitors the AUL local store and retrieves relevant entries from it based on provided `RollbarAulStoreMonitorOptions` instance. These entries will be captured as Rollbar Telemetry log events. Hence, the Telemetry must be enabled as well as its capture of the log entries. +This component implements the following key protocols. + +### `RollbarAulStoreMonitoring` Protocol + +Allows to start and cancel the monitoring service as well as provides optional methods to configure the service with custom `RollbarAulStoreMonitorOptions` and/or a custom `RollbarLogger` instance. + +### `RollbarSingleInstancing` Protocol + +Defines access to the singleton of the type implementing this protocol. +Optionally, defines methods to test on the singleton instance existence and a method to define custom singleton deallocation logic. + + + +## Examples + +### Using the RollbarAulStoreMonitor to capture the application AUL entries + +1. Make sure you have properly configured `RollbarConfig` instance and the Telemetry and its log capture options are both enabled. +2. Setup a `RollbarLogger` instance with that `RolbarConfig` instance. +3. Configure the `RollbarAulStoreMonitor` service with that `RollbarLogger` instance. +4. Optionally, you can create a custom-configured `RollbarAulStoreMonitorOptions` instance and configure the `RollbarAulStoreMonitor` service with it. +5. Start the `RollbarAulStoreMonitor` service. +6. Any AUL entry made from your application process will be collected by the SDK as corresponding Telemetry log events according to the provided `RollbarAulStoreMonitorOptions`... + +#### Objective-C + +```Obj-C +// Create proper RollbarConfig instance making sure +// the Telemetry and its log capture are enabled: +RollbarConfig *rollbarConfig = [[RollbarConfig alloc] init]; +rollbarConfig.destination.accessToken = @""; +rollbarConfig.destination.environment = @""; +rollbarConfig.developerOptions.transmit = YES; +rollbarConfig.telemetry.enabled = YES; // required for AUL capture +rollbarConfig.telemetry.captureLog = YES; // required for AUL capture +rollbarConfig.telemetry.maximumTelemetryData = 100; + +// Setup shared RollbarLogger with the config: +[Rollbar initWithConfiguration:rollbarConfig]; + +// Configure the AUL monitor with the logger: +[RollbarAulStoreMonitor.sharedInstance configureRollbarLogger:Rollbar.currentLogger]; + +// Optionally, configure the AUL monitoring options: +RollbarAulStoreMonitorOptions *aulMonitorOptions = +[[RollbarAulStoreMonitorOptions alloc] init]; +[aulMonitorOptions addAulSubsystem:@"DataAccessLayer"]; +[aulMonitorOptions addAulSubsystem:@"Model"]; +[aulMonitorOptions addAulCategory:@"CompanyOrg"]; +[RollbarAulStoreMonitor.sharedInstance configureWithOptions:aulMonitorOptions]; + +// Start the AUL monitoring: +[RollbarAulStoreMonitor.sharedInstance start]; +``` + +#### Swift + +```Swift +// Create proper RollbarConfig instance making sure +// the Telemetry and its log capture are enabled: +let config = RollbarConfig(); +config.destination.accessToken = ""; +config.destination.environment = ""; +config.developerOptions.transmit = true; +config.telemetry.enabled = true; +config.telemetry.captureLog = true; + +// Setup shared RollbarLogger with the config: +Rollbar.initWithConfiguration(config); + +// Configure the AUL monitor with the logger: +RollbarAulStoreMonitor.sharedInstance().configureRollbarLogger(Rollbar.currentLogger()); + +// Optionally, configure the AUL monitoring options: +let aulOptions = RollbarAulStoreMonitorOptions(); +aulOptions.addAulSubsystem("DataAccessLayer"); +aulOptions.addAulSubsystem("Model"); +aulOptions.addAulCategory("CompanyOrg"); +RollbarAulStoreMonitor.sharedInstance().configure(with: aulOptions); + +// Start the AUL monitoring: +RollbarAulStoreMonitor.sharedInstance().start(); +``` diff --git a/docs/SDK module - RollbarSwift.md b/docs/SDK module - RollbarSwift.md index 66ff8d3c..e4706920 100644 --- a/docs/SDK module - RollbarSwift.md +++ b/docs/SDK module - RollbarSwift.md @@ -18,6 +18,8 @@ This component is meant to be initialized with a preconfigured instance of `Roll ### Guarding Swift code that could potentially throw a NSException and reporting the exception (if any) to Rollbar +#### Swift + ```Swift func generateObjCException() { diff --git a/docs/SDK module - RollbarZZZ.md b/docs/SDK module - RollbarZZZ.md index 64524ca2..1f335c1b 100644 --- a/docs/SDK module - RollbarZZZ.md +++ b/docs/SDK module - RollbarZZZ.md @@ -18,10 +18,14 @@ This component is meant to be initialized with ... ### Example title +#### Objective-C + ```Obj-C ``` +#### Swift + ```Swift ``` From bb28d669bc1087d1855d54b04f3402469991461d Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 15:58:09 -0700 Subject: [PATCH 20/32] docs: ref #138 --- docs/SDK Intro.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/SDK Intro.md b/docs/SDK Intro.md index c4516ed0..1f877691 100644 --- a/docs/SDK Intro.md +++ b/docs/SDK Intro.md @@ -113,12 +113,16 @@ You do not have to worry about explicitly including other internal dependencies Before using any of the types provided by the SDK modules, you need to make sure you import the modules you need. For example: +#### Objective-C + ```Obj-C @import RollbarNotifier; @import RollbarKSCrash; // optional @import RollbarPLCrashReporter; // optional alternative to RollbarKSCrash ``` +#### Swift + ```Swift import RollbarNotifier import RollbarKSCrash // optional @@ -129,12 +133,16 @@ import RollbarPLCrashReporter // optional alternative to RollbarKSCrash When setting up a notifier configuration you must at least specify your Rollbar Project's access token: +#### Objective-C + ```Obj-C RollbarConfig *config = [RollbarConfig new]; config.destination.accessToken = @"YOUR_PROJECT_ACCESS_TOKEN"; config.destination.environment = @"YOUR_ENVIRONMENT"; ``` +#### Swift + ```Swift let config = RollbarConfig() config.destination.accessToken = "YOUR_PROJECT_ACCESS_TOKEN" @@ -143,6 +151,8 @@ config.destination.environment = "ENVIRONMENT" ### Optionally, Define A Crash Report Collector Instance +#### Objective-C + ```Obj-C id crashCollector = @@ -151,6 +161,8 @@ id crashCollector = //OR nil; ``` +#### Swift + ```Swift let crashCollector = RollbarPLCrashCollector() @@ -159,11 +171,15 @@ let crashCollector = RollbarPLCrashCollector() ### Initialize the Shared Notifier +#### Objective-C + ```Obj-C [Rollbar initWithConfiguration:config]; //OR [Rollbar initWithConfiguration:config crashCollector:crashCollector]; ``` +#### Swift + ```Swift Rollbar.initWithConfiguration(config) //OR Rollbar.initWithConfiguration(config, crashCollector: crashCollector) @@ -171,10 +187,14 @@ Rollbar.initWithConfiguration(config) ### Start Logging using the Shared Notifier +#### Objective-C + ```Obj-C [Rollbar infoMessage:@"See this message on your Rollbar Project Dashboard..."]; ``` +#### Swift + ```Swift Rollbar.infoMessage("See this message on your Rollbar Project Dashboard...") ``` From cdd5490ec19d916f238eb4a39dc07f7181077d6e Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 16:00:44 -0700 Subject: [PATCH 21/32] docs: ref #139 --- docs/SDK module - RollbarCocoaLumberjack.md | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 docs/SDK module - RollbarCocoaLumberjack.md diff --git a/docs/SDK module - RollbarCocoaLumberjack.md b/docs/SDK module - RollbarCocoaLumberjack.md new file mode 100644 index 00000000..4bcc588b --- /dev/null +++ b/docs/SDK module - RollbarCocoaLumberjack.md @@ -0,0 +1,31 @@ +# SDK Module: RollbarCocoaLumberjack + +This module implements components useful in cases when the SDK is used ... + +--- + +## Essential Components of the Module + +### `RollbarComp1` + +This utility class provides ... + +### `RollbarComp2` + +This component is meant to be initialized with ... + +## Examples + +### Example title + +#### Objective-C + +```Obj-C + +``` + +#### Swift + +```Swift + +``` From a3025981bffebccd5bfc6f9346a8852eacd64eb4 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 17:04:00 -0700 Subject: [PATCH 22/32] docs: ref #139 --- docs/SDK module - RollbarCocoaLumberjack.md | 34 +++++++++++++++------ 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/docs/SDK module - RollbarCocoaLumberjack.md b/docs/SDK module - RollbarCocoaLumberjack.md index 4bcc588b..62c0b3e8 100644 --- a/docs/SDK module - RollbarCocoaLumberjack.md +++ b/docs/SDK module - RollbarCocoaLumberjack.md @@ -1,27 +1,43 @@ # SDK Module: RollbarCocoaLumberjack -This module implements components useful in cases when the SDK is used ... +This SDK module implements integration of Rollbar into the popular CocoaLumberjack logging framework. + +So if you either already use CocoaLumberjack or you are planning to use it for your software product logging needs, then you can easily integrate Rollbar into it via this module and have all or some of the logs performed via the *CocoaLumberjack* framework redirected into a dedicated Rollbar project at www.rollbar.com and monitor the health of your software product/service remotely. --- ## Essential Components of the Module -### `RollbarComp1` - -This utility class provides ... - -### `RollbarComp2` +### `RollbarCocoaLumberjackLogger` -This component is meant to be initialized with ... +Implements CocoaLumberjack compatible logger (`DDLogger`) capable of "intercepting" log events going through the CocoaLumberjack infrastructure, converting them to Rollbar compatible payloads, and sending the payloads to a Rollbar.com Project. ## Examples -### Example title +### Integrating Rollbar-Apple into existing CocoaLumberjack use case + +1. Identify place(s) in the code where you already define currently used CocoaLumberjack loggers. That is where you would want to also add a `RollbarCocoaLumberjackLogger` instance. +2. Accordingly, import our *RollbarCocoaLumberjack* module. +3. Setup properly configured `RollbarConfig` object. +4. Create a `RollbarCocoaLumberjackLogger` instance using the preconfigured `RollbarConfig` instance and add it to the `DDLog` +5. Fro this point on, all relevant log entries made anywhere via the *CocoaLumberjack* logging methods will be "forked" to Rollbar based on filtering conditions specified on both levels: *CocoaLumberjackLogger* configuration and in `RollbarConfig` instances defined above. #### Objective-C ```Obj-C - +@import RollbarCocoaLumberjack; +//... + +//... + RollbarConfig *config = [[RollbarConfig alloc] init]; + config.destination.accessToken = @"ROLLBAR_ACCESS_TOKEN"; + config.destination.environment = @"ROLLBAR_ENVIRONMENT"; + config.developerOptions.transmit = YES; + config.developerOptions.logPayload = YES; + config.loggingOptions.maximumReportsPerMinute = 5000; + + [DDLog addLogger:[RollbarCocoaLumberjackLogger createWithRollbarConfig:config]]; +//... ``` #### Swift From c7f142f51ad624bd3d630459b7610d64847b19b9 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 17:04:24 -0700 Subject: [PATCH 23/32] docs: ref #138, #139 --- CHANGELOG.md | 77 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 80990c1d..0041f9c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ## Release Notes Tagging Conventions -1. Every entry within the PackageReleaseNotes element is expected to be started with +1. Every entry within the PackageReleaseNotes element is expected to be started with at least one of the tags listed: feat: A new feature @@ -16,21 +16,25 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co test: Adding or modifying unit test code chore: Changes to the build process or auxiliary tools and libraries such as documentation generation, etc. -2. Every entry within the PackageReleaseNotes element is expected to be tagged with - EITHER +2. Every entry within the PackageReleaseNotes element is expected to be tagged with + EITHER "resolve #GITHUB_ISSUE_NUMBER:" - meaning completely addresses the GitHub issue - OR + OR "ref #GITHUB_ISSUE_NUMBER:" - meaning relevant to the GitHub issue depending on what is more appropriate in each case. ## Release Notes -**2.1.0 +### 2.1.0 + - feat: resolve #133 - Implement RollbarCocoaLumberjack module - test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack - core: resolve #112 - Upgrade to the latest PLCrashReporter 1.0.1 +- docs: resolve #138 - Move current SDK documentation from readme.io to the repo +- docs: resolve #139 - Document new RollbarCocoaLumberjack module + +### 2.0.3 -**2.0.3 - docs: resolve #122 - Update RollbarCommon public API doc comments so they are properly rendered by Xcode Quick Help - docs: resolve #124 - Update RollbarDeploys public API doc comments so they are properly rendered by Xcode Quick Help - docs: resolve #126 - Update RollbarSwift, RollbarAUL, RollbarPLCrashReporter, and RollbarKSCrash public API doc comments so they are properly rendered by Xcode Quick Help @@ -38,64 +42,83 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co - chore: resolve #114 - Consolidate destination parameters for samples - chore: resolve #113 - Consolidate destination parameters for unit tests -**2.0.2 +### 2.0.2 + - fix: resolve #110 - Xcode autocomplete for Swift expects person.id, but codebase expects person.ID - chore: resolve #118 - Remove source file header comments from RollbarCommon -**2.0.1 +### 2.0.1 + - moving from Beta to GA -**2.0.0-beta.23** +### 2.0.0-beta.23 + - refactor: upgraded KSCRash to v1.15.25 - refactor: upgraded PLCrashReporter to v1.10.0 - chore: updated macosAppObjC Xcode scheme - chore: update SonarCloud build wrapper - chore: update SonarCloud scanner -**2.0.0-beta.22** -**2.0.0-beta.21** +### 2.0.0-beta.22 + +### 2.0.0-beta.21 + - feat: new RollbarAUL module is code complete -**2.0.0-beta.15** +### 2.0.0-beta.15 + - fix: resolve #81 - SPM - Resolving Package Graph Failed -**2.0.0-beta.14** +### 2.0.0-beta.14 + - feat: allocated new RollbarAUL module project - fix: resolve #72 - Rollbar* pods 2.0.0-beta.10 not all published -**2.0.0-beta.13** -**2.0.0-beta.12** -**2.0.0-beta.11** +### 2.0.0-beta.13 + +### 2.0.0-beta.12 + +### 2.0.0-beta.11 + - fix: resolve #72 - Rollbar* pods 2.0.0-beta.10 not all published -**2.0.0-beta.10** +### 2.0.0-beta.10 + - fix: resolve #66 - App terminated due to signal 5 instantiating RollbarPLCrashCollector -**2.0.0-beta8** +### 2.0.0-beta8 + - fix: point all the Cocoapods podspecs to proper documentation site. -**2.0.0-beta7** -**2.0.0-beta6** -**2.0.0-beta5** -**2.0.0-beta4** +### 2.0.0-beta7 + +### 2.0.0-beta6 + +### 2.0.0-beta5 + +### 2.0.0-beta4 + - fix: RollbarSwift.podspec -**2.0.0-beta3** +### 2.0.0-beta3 + - feat: added RollbarSwift -**2.0.0-beta2** +### 2.0.0-beta2 + - feat: added new developer option: suppressSdkInfoLogging -**2.0.0-beta1** - comparing to Rollbar-iOS +### 2.0.0-beta1 - comparing to Rollbar-iOS + - feat: added RollbarPLCrashReporter module - feat: added RollbarKSCrash module -- feat: added explicit reporting of NSErrors +- feat: added explicit reporting of NSErrors - feat: defined default scrub fields - refactor: split out RollbarCommon, RollbarNotifier, RollbarDeploys - refactor: added use of lightweight generics - refactor: added use of nullability attributes - refactor: removed RollbarConfiguration and replaced it with RollbarConfig - refactor: changed WhitelistFields into SafeListFields when it comes to the RollbarScrubbingOptions -- refactor: removed all the deprecated API +- refactor: removed all the deprecated API - refactor: replaced NSString-like log level parameters in RollbarLogger interface with RollbarLevel enum - refactor: replaced sync-all log methods of Rollbar and RolbarLogger with ones dedicated to each type of payload: string-message, NSException, NSError, etc. From 4741ab933a9b2ad3f1035085186c636a8e7d7bc9 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 17:06:17 -0700 Subject: [PATCH 24/32] docs: ref #139 --- docs/SDK module - RollbarCocoaLumberjack.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/SDK module - RollbarCocoaLumberjack.md b/docs/SDK module - RollbarCocoaLumberjack.md index 62c0b3e8..2ff2f559 100644 --- a/docs/SDK module - RollbarCocoaLumberjack.md +++ b/docs/SDK module - RollbarCocoaLumberjack.md @@ -25,6 +25,7 @@ Implements CocoaLumberjack compatible logger (`DDLogger`) capable of "intercepti #### Objective-C ```Obj-C +//... @import RollbarCocoaLumberjack; //... From 311fa48deb4151b6f1c7446583b9751d9851119b Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Thu, 17 Mar 2022 17:29:35 -0700 Subject: [PATCH 25/32] fix: resolve #136 --- CHANGELOG.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0041f9c5..8baf3846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,11 +27,12 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ### 2.1.0 -- feat: resolve #133 - Implement RollbarCocoaLumberjack module -- test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack -- core: resolve #112 - Upgrade to the latest PLCrashReporter 1.0.1 -- docs: resolve #138 - Move current SDK documentation from readme.io to the repo -- docs: resolve #139 - Document new RollbarCocoaLumberjack module +- feat: resolve #133 - Implement RollbarCocoaLumberjack module +- test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack +- fix: resolve #136 - RollbarPLCrashReporter.init() no longer available +- chore: resolve #112 - Upgrade to the latest PLCrashReporter 1.0.1 +- docs: resolve #138 - Move current SDK documentation from readme.io to the repo +- docs: resolve #139 - Document new RollbarCocoaLumberjack module ### 2.0.3 From ccfbcf81350fc2ee16baa447b0709c0f4b899d31 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 21 Mar 2022 16:48:58 -0700 Subject: [PATCH 26/32] test: factoring out common/reusable unit test functionality --- .../RollbarCocoaLumberjackTests.m | 4 +-- .../RollbarCocoaLumberjackTests.swift | 33 ++++++++++++++++--- RollbarCommon/Package.swift | 4 +-- .../NSDictionary+RollbarTest.swift | 8 ----- .../NSJSONSerialization+RollbarTests.swift | 15 --------- .../RollbarCommonTests.swift | 21 ++++++------ .../RollbarTriStateFlagTests.swift | 17 ---------- .../RollbarDeploysTests.m | 16 ++++----- RollbarNotifier/Package.swift | 4 ++- .../PayloadTruncationTests.m | 4 +-- .../RollbarTelemetryTests.m | 4 +-- .../RollbarNotifierTests-ObjC/RollbarTests.m | 8 ++--- .../RollbarNotifierConfigUtilTests.swift | 2 +- .../RollbarNotifierConfigurationTests.swift | 3 +- .../RollbarNotifierDTOsTests.swift | 2 +- .../RollbarNotifierLoggerTests.swift | 2 +- .../RollbarNotifierTelemetryTests.swift | 2 +- .../RollbarNotifierTruncationTests.swift | 2 +- UnitTesting/Package.swift | 10 +++++- .../Sources/UnitTesting/RollbarTestHelper.m | 26 --------------- .../UnitTesting/RollbarTestHelper.swift | 29 ++++++++++++++++ .../UnitTesting}/RollbarTestUtil.swift | 21 ++++++------ .../UnitTesting/include/RollbarTestHelper.h | 30 ----------------- .../include/RollbarUnitTestSettings.h | 16 --------- .../UnitTesting/include/module.modulemap | 8 ----- 25 files changed, 117 insertions(+), 174 deletions(-) delete mode 100644 UnitTesting/Sources/UnitTesting/RollbarTestHelper.m create mode 100644 UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift rename {RollbarNotifier/Tests/RollbarNotifierTests => UnitTesting/Sources/UnitTesting}/RollbarTestUtil.swift (91%) delete mode 100644 UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h delete mode 100644 UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h delete mode 100644 UnitTesting/Sources/UnitTesting/include/module.modulemap diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m index ad498b0b..cc4266c7 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -46,8 +46,8 @@ - (void)testLiveRollbarCocoaLumberjackBasics { DDLogVerbose(@"User selected file:%@ withSize:%u", @"somewhere/file.ext", 100); RollbarConfig *config = [[RollbarConfig alloc] init]; - config.destination.accessToken = ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN; - config.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + config.destination.accessToken = [RollbarTestHelper getRollbarPayloadsAccessToken]; + config.destination.environment = [RollbarTestHelper getRollbarEnvironment]; config.developerOptions.transmit = YES; config.developerOptions.logPayload = YES; config.loggingOptions.maximumReportsPerMinute = 5000; diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift index 52d6376e..268fb32f 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -1,11 +1,34 @@ import XCTest +import UnitTesting @testable import RollbarCocoaLumberjack final class RollbarCocoaLumberjackTests: XCTestCase { - func testExample() throws { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - //XCTAssertEqual(RollbarCocoaLumberjack().text, "Hello, World!") + + override func setUp() { + + super.setUp(); + + //RollbarTestHelper. + } + + func testBasics() { + + } + + func testBasicsMore() { + + } + +// func testExample() throws { +// // This is an example of a functional test case. +// // Use XCTAssert and related functions to verify your tests produce the correct +// // results. +// //XCTAssertEqual(RollbarCocoaLumberjack().text, "Hello, World!") +// } + +// static var allTests = [ +// ("testBasics", testBasics), +// ("testExample", testExample), +// ] } diff --git a/RollbarCommon/Package.swift b/RollbarCommon/Package.swift index 4d40c6e2..155f897a 100644 --- a/RollbarCommon/Package.swift +++ b/RollbarCommon/Package.swift @@ -29,7 +29,7 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), - .package(path: "../UnitTesting"), + //.package(path: "../UnitTesting"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. @@ -50,7 +50,7 @@ let package = Package( .testTarget( name: "RollbarCommonTests", dependencies: [ - "UnitTesting", + //"UnitTesting", "RollbarCommon", ] ), diff --git a/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift b/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift index 8d7a660f..1583debe 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/NSDictionary+RollbarTest.swift @@ -1,10 +1,3 @@ -// -// File.swift -// -// -// Created by Andrey Kornich on 2020-09-30. -// - import XCTest import Foundation import RollbarCommon @@ -40,6 +33,5 @@ final class NSDictionaryRollbarTests: XCTestCase { static var allTests = [ ("testNSDictionaryRollbar_keyPresent", testNSDictionaryRollbar_keyPresent), - //("testExample", testExample), ] } diff --git a/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift b/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift index 599d36e9..c904f87b 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/NSJSONSerialization+RollbarTests.swift @@ -1,10 +1,3 @@ -// -// NSJSONSerialization+RollbarTests.swift -// -// -// Created by Andrey Kornich on 2020-05-26. -// - import XCTest import Foundation @testable import RollbarCommon @@ -89,17 +82,9 @@ final class NSJSONSerializationRollbarTests: XCTestCase { } } -// func testExample() { -// // This is an example of a functional test case. -// // Use XCTAssert and related functions to verify your tests produce the correct -// // results. -// XCTAssertEqual(RollbarDeploys().text, "Hello, World!") -// } - static var allTests = [ ("testNSJSONSerializationRollbar_measureJSONDataByteSize", testNSJSONSerializationRollbar_measureJSONDataByteSize), ("testNSJSONSerializationRollbar_dataWithJSONObject", testNSJSONSerializationRollbar_dataWithJSONObject), ("testNSJSONSerializationRollbar_safeDataFromJSONObject", testNSJSONSerializationRollbar_safeDataFromJSONObject), - //("testExample", testExample), ] } diff --git a/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift b/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift index a5d3e534..cdc1f826 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/RollbarCommonTests.swift @@ -2,14 +2,15 @@ import XCTest @testable import RollbarCommon final class RollbarCommonTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - //XCTAssertEqual(RollbarCommon().text, "Hello, World!") - } - - static var allTests = [ - ("testExample", testExample), - ] + +// func testExample() { +// // This is an example of a functional test case. +// // Use XCTAssert and related functions to verify your tests produce the correct +// // results. +// //XCTAssertEqual(RollbarCommon().text, "Hello, World!") +// } +// +// static var allTests = [ +// ("testExample", testExample), +// ] } diff --git a/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift b/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift index 528b0dca..ecdbd210 100644 --- a/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift +++ b/RollbarCommon/Tests/RollbarCommonTests/RollbarTriStateFlagTests.swift @@ -1,10 +1,3 @@ -// -// RollbarTriStateFlagTests.swift -// -// -// Created by Andrey Kornich on 2020-05-26. -// - import XCTest import Foundation @testable import RollbarCommon @@ -13,8 +6,6 @@ final class RollbarTriStateFlagTests: XCTestCase { func testRollbarTriStateFlagUtil_FromStringConversion() { - //XCTAssertTrue(); - XCTAssertEqual(RollbarTriStateFlag.none, RollbarTriStateFlagUtil.triStateFlag(from: "None")); XCTAssertEqual(RollbarTriStateFlag.none, RollbarTriStateFlagUtil.triStateFlag(from: "none")); XCTAssertEqual(RollbarTriStateFlag.none, RollbarTriStateFlagUtil.triStateFlag(from: "NONE")); @@ -47,16 +38,8 @@ final class RollbarTriStateFlagTests: XCTestCase { XCTAssertEqual("ON", RollbarTriStateFlagUtil.triStateFlag(toString: RollbarTriStateFlag.on)); } -// func testExample() { -// // This is an example of a functional test case. -// // Use XCTAssert and related functions to verify your tests produce the correct -// // results. -// XCTAssertEqual(RollbarDeploys().text, "Hello, World!") -// } - static var allTests = [ ("testRollbarTriStateFlagUtil_FromStringConversion", testRollbarTriStateFlagUtil_FromStringConversion), ("testRollbarTriStateFlagUtil_ToStringConversion", testRollbarTriStateFlagUtil_ToStringConversion), - //("testExample", testExample), ] } diff --git a/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m b/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m index 45ad164b..603ae528 100644 --- a/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m +++ b/RollbarDeploys/Tests/RollbarDeploysTests-ObjC/RollbarDeploysTests.m @@ -47,7 +47,7 @@ @interface RollbarDeploysTests : XCTestCase @implementation RollbarDeploysTests - (void)testDeploymentDto { - NSString * const environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + NSString * const environment = [RollbarTestHelper getRollbarEnvironment]; NSString * const comment = @"a new deploy"; NSString * const revision = @"a_revision"; NSString * const localUsername = @"UnitTestRunner"; @@ -76,7 +76,7 @@ - (void)testDeploymentRegistration { NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; - NSString * const environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + NSString * const environment = [RollbarTestHelper getRollbarEnvironment]; NSString * const comment = [NSString stringWithFormat:@"a new deploy at %@", [dateFormatter stringFromDate:[NSDate date]]]; NSString * const revision = @"a_revision"; @@ -90,8 +90,8 @@ - (void)testDeploymentRegistration { localUserName:localUsername rollbarUserName:rollbarUsername]; RollbarDeploysManager *deploysManager = - [[RollbarDeploysManager alloc] initWithWriteAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN - readAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN + [[RollbarDeploysManager alloc] initWithWriteAccessToken:[RollbarTestHelper getRollbarDeploysWriteAccessToken] + readAccessToken:[RollbarTestHelper getRollbarDeploysReadAccessToken] deploymentRegistrationObserver:observer deploymentDetailsObserver:observer deploymentDetailsPageObserver:observer @@ -103,8 +103,8 @@ - (void)testGetDeploymentDetailsById { NSString * const testDeploymentId = @"23922850"; RollbarDeploysObserver *observer = [[RollbarDeploysObserver alloc] init]; RollbarDeploysManager *deploysManager = - [[RollbarDeploysManager alloc] initWithWriteAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN - readAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN + [[RollbarDeploysManager alloc] initWithWriteAccessToken:[RollbarTestHelper getRollbarDeploysWriteAccessToken] + readAccessToken:[RollbarTestHelper getRollbarDeploysReadAccessToken] deploymentRegistrationObserver:observer deploymentDetailsObserver:observer deploymentDetailsPageObserver:observer @@ -115,8 +115,8 @@ - (void)testGetDeploymentDetailsById { - (void)testGetDeploymentsPage { RollbarDeploysObserver *observer = [[RollbarDeploysObserver alloc] init]; RollbarDeploysManager *deploysManager = - [[RollbarDeploysManager alloc] initWithWriteAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN - readAccessToken:ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN + [[RollbarDeploysManager alloc] initWithWriteAccessToken:[RollbarTestHelper getRollbarDeploysWriteAccessToken] + readAccessToken:[RollbarTestHelper getRollbarDeploysReadAccessToken] deploymentRegistrationObserver:observer deploymentDetailsObserver:observer deploymentDetailsPageObserver:observer diff --git a/RollbarNotifier/Package.swift b/RollbarNotifier/Package.swift index cec121eb..1406f752 100644 --- a/RollbarNotifier/Package.swift +++ b/RollbarNotifier/Package.swift @@ -29,7 +29,9 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "RollbarNotifier", - dependencies: ["RollbarCommon",], + dependencies: [ + "RollbarCommon", + ], publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/RollbarNotifier/**"), diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m index 93fcffcc..735c9abc 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/PayloadTruncationTests.m @@ -19,8 +19,8 @@ - (void)setUp { [RollbarLogger clearSdkDataStore]; if (!Rollbar.currentConfiguration) { - [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; - Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + [Rollbar initWithAccessToken:[RollbarTestHelper getRollbarPayloadsAccessToken]]; + Rollbar.currentConfiguration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; } } diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m index 75284b56..f9ca5a9d 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTelemetryTests.m @@ -19,8 +19,8 @@ - (void)setUp { [RollbarLogger clearSdkDataStore]; if (!Rollbar.currentConfiguration) { - [Rollbar initWithAccessToken:ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN]; - Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + [Rollbar initWithAccessToken: [RollbarTestHelper getRollbarPayloadsAccessToken]]; + Rollbar.currentConfiguration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; } } diff --git a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m index d79e31c1..db7e8dba 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m +++ b/RollbarNotifier/Tests/RollbarNotifierTests-ObjC/RollbarTests.m @@ -21,8 +21,8 @@ - (void)setUp { if (!Rollbar.currentConfiguration) { RollbarConfig *config = [[RollbarConfig alloc] init]; - config.destination.accessToken = ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN; - config.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + config.destination.accessToken = [RollbarTestHelper getRollbarPayloadsAccessToken]; + config.destination.environment = [RollbarTestHelper getRollbarEnvironment]; config.developerOptions.transmit = YES; config.developerOptions.logPayload = YES; config.loggingOptions.maximumReportsPerMinute = 5000; @@ -46,7 +46,7 @@ - (void)testMultithreadedStressCase { for( int i = 0; i < 20; i++) { dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY,0), ^(){ RollbarLogger *logger = [[RollbarLogger alloc] initWithAccessToken:Rollbar.currentConfiguration.destination.accessToken]; - logger.configuration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + logger.configuration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; for (int j = 0; j < 20; j++) { [logger log:RollbarLevel_Error message:@"error" @@ -106,7 +106,7 @@ - (void)testRollbarNotifiersIndependentConfiguration { - (void)testRollbarTransmit { Rollbar.currentConfiguration.destination.accessToken = @"09da180aba21479e9ed3d91e0b8d58d6"; - Rollbar.currentConfiguration.destination.environment = ROLLBAR_UNIT_TEST_ENVIRONMENT; + Rollbar.currentConfiguration.destination.environment = [RollbarTestHelper getRollbarEnvironment]; Rollbar.currentConfiguration.developerOptions.transmit = YES; Rollbar.currentConfiguration.developerOptions.transmit = YES; diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift index 980365cd..5fde124e 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigUtilTests.swift @@ -27,7 +27,7 @@ final class RolllbarNotifierConfigUtilTests: XCTestCase { print("Error: \(error) \n Stack Symbols: \(stackSymbols)") } - override class func setUp() { + override func setUp() { do { _ = try RollbarConfigUtil.deleteDefaultRollbarConfigFile(); } diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift index 23f2c9ce..2e207850 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierConfigurationTests.swift @@ -2,11 +2,12 @@ import XCTest import Foundation import os.log +import UnitTesting @testable import RollbarNotifier final class RollbarNotifierConfigurationTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift index c145c6f5..565aaacc 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierDTOsTests.swift @@ -5,7 +5,7 @@ import Foundation final class RollbarNotifierDTOsTests: XCTestCase { - override class func setUp() { + override func setUp() { } override func tearDown() { diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift index d23570ed..0d81396a 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierLoggerTests.swift @@ -7,7 +7,7 @@ import os.log final class RollbarNotifierLoggerTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift index f6f2cfd2..0d742d65 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTelemetryTests.swift @@ -7,7 +7,7 @@ import UnitTesting final class RollbarNotifierTelemetryTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); RollbarTestUtil.clearLogFile(); RollbarTestUtil.clearTelemetryFile(); diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift index 010fe1d1..71016c7e 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift +++ b/RollbarNotifier/Tests/RollbarNotifierTests/RollbarNotifierTruncationTests.swift @@ -7,7 +7,7 @@ import os.log final class RollbarNotifierTruncationTests: XCTestCase { - override class func setUp() { + override func setUp() { super.setUp(); diff --git a/UnitTesting/Package.swift b/UnitTesting/Package.swift index b32e3d08..69ef04a3 100644 --- a/UnitTesting/Package.swift +++ b/UnitTesting/Package.swift @@ -21,13 +21,16 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(path: "../RollbarCommon"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "UnitTesting", - dependencies: [], + dependencies: [ + "RollbarCommon", + ], publicHeadersPath: "include", cSettings: [ .headerSearchPath("Sources/UnitTesting/**"), @@ -41,5 +44,10 @@ let package = Package( .testTarget( name: "UnitTestingTests", dependencies: ["UnitTesting"]), + ], + swiftLanguageVersions: [ + SwiftVersion.v4, + SwiftVersion.v4_2, + SwiftVersion.v5, ] ) diff --git a/UnitTesting/Sources/UnitTesting/RollbarTestHelper.m b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.m deleted file mode 100644 index b4762bee..00000000 --- a/UnitTesting/Sources/UnitTesting/RollbarTestHelper.m +++ /dev/null @@ -1,26 +0,0 @@ -#import "RollbarTestHelper.h" -#import "RollbarUnitTestSettings.h" - -@implementation RollbarTestHelper - -+ (nonnull NSString *)getRollbarEnvironment { - - return ROLLBAR_UNIT_TEST_ENVIRONMENT; -} - -+ (nonnull NSString *)getRollbarPayloadsAccessToken { - - return ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN; -} - -+ (nonnull NSString *)getRollbarDeploysWriteAccessToken { - - return ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN; -} - -+ (nonnull NSString *)getRollbarDeploysReadAccessToken { - - return ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN; -} - -@end diff --git a/UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift new file mode 100644 index 00000000..dee66c00 --- /dev/null +++ b/UnitTesting/Sources/UnitTesting/RollbarTestHelper.swift @@ -0,0 +1,29 @@ +import Foundation + +@objc public class RollbarTestHelper: NSObject { + + private static let rollbarUnitTestEnvironment = "Rollbar-Apple-UnitTests"; + private static let rollbarUnitTestPayloadsAccessToken = "09da180aba21479e9ed3d91e0b8d58d6"; + private static let rollbarUnitTestDeploysWriteAccessToken = "efdc4b85d66045f293a7f9e99c732f61"; + private static let rollbarUnitTestDeploysReadAccessToken = "595cbf76b05b45f2b3ef661a2e0078d4"; + + + @objc public static func getRollbarEnvironment() -> String { + return RollbarTestHelper.rollbarUnitTestEnvironment; + } + + @objc public static func getRollbarPayloadsAccessToken() -> String { + return RollbarTestHelper.rollbarUnitTestPayloadsAccessToken; + } + + @objc public static func getRollbarDeploysWriteAccessToken() -> String { + return RollbarTestHelper.rollbarUnitTestDeploysWriteAccessToken; + } + + @objc public static func getRollbarDeploysReadAccessToken() -> String { + return RollbarTestHelper.rollbarUnitTestDeploysReadAccessToken; + } + + private override init() { + } +} diff --git a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarTestUtil.swift b/UnitTesting/Sources/UnitTesting/RollbarTestUtil.swift similarity index 91% rename from RollbarNotifier/Tests/RollbarNotifierTests/RollbarTestUtil.swift rename to UnitTesting/Sources/UnitTesting/RollbarTestUtil.swift index a7eeff5a..e6a22b6e 100644 --- a/RollbarNotifier/Tests/RollbarNotifierTests/RollbarTestUtil.swift +++ b/UnitTesting/Sources/UnitTesting/RollbarTestUtil.swift @@ -7,9 +7,8 @@ import Foundation import RollbarCommon -import RollbarNotifier -class RollbarTestUtil { +@objc public class RollbarTestUtil: NSObject { private static let queuedItemsFileName = "rollbar.items"; private static let queuedItemsStateFileName = "rollbar.state"; @@ -32,7 +31,7 @@ class RollbarTestUtil { return filePath.path; } - public static func clearTelemetryFile() { + @objc public static func clearTelemetryFile() { let filePath = RollbarTestUtil.getTelemetryFilePath(); let fileManager = FileManager.default; let fileExists = fileManager.fileExists(atPath: filePath); @@ -46,7 +45,7 @@ class RollbarTestUtil { } } - public static func clearLogFile() { + @objc public static func clearLogFile() { let itemsStateFilePath = RollbarTestUtil.getQueuedItemsStateFilePath(); let itemsFilePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileManager = FileManager.default; @@ -67,7 +66,7 @@ class RollbarTestUtil { } } - public static func readFirstItemStringsFromLogFile() -> String? { + @objc public static func readFirstItemStringsFromLogFile() -> String? { let filePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileReader = RollbarFileReader(filePath: filePath, andOffset: 0); @@ -75,7 +74,7 @@ class RollbarTestUtil { return item; } - public static func readItemStringsFromLogFile() -> [String] { + @objc public static func readItemStringsFromLogFile() -> [String] { let filePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileReader = RollbarFileReader(filePath: filePath, andOffset: 0); @@ -89,7 +88,7 @@ class RollbarTestUtil { return items; } - public static func readItemsFromLogFile() -> [NSMutableDictionary] { + @objc public static func readItemsFromLogFile() -> [NSMutableDictionary] { let filePath = RollbarTestUtil.getQueuedItemsFilePath(); let fileReader = RollbarFileReader(filePath: filePath, andOffset: 0); var items = [NSMutableDictionary] (); @@ -115,7 +114,7 @@ class RollbarTestUtil { return items; } - public static func waitForPesistenceToComplete(waitTimeInSeconds: TimeInterval = 0.5) { + @objc public static func waitForPesistenceToComplete(waitTimeInSeconds: TimeInterval = 0.5) { Thread.sleep(forTimeInterval: waitTimeInSeconds); } @@ -129,7 +128,7 @@ class RollbarTestUtil { } } - public static func makeTroubledCall() throws { + @objc public static func makeTroubledCall() throws { try makeInnerTroubledCall(); } @@ -159,7 +158,7 @@ class RollbarTestUtil { } -enum RollbarTestUtilError: Error { +public enum RollbarTestUtilError: Error { case basicError case simulatedError(errorDescription: String) case simulatedException(errorDescription: String, errorCallStack: [String] = Thread.callStackSymbols) @@ -167,7 +166,7 @@ enum RollbarTestUtilError: Error { } -protocol BackTracedErrorProtocol : Error /*OR LocalizedError OR CustomNSError*/ { +public protocol BackTracedErrorProtocol : Error /*OR LocalizedError OR CustomNSError*/ { var errorDescription: String { get } var errorCallStack: [String] { get } } diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h b/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h deleted file mode 100644 index 79f075ef..00000000 --- a/UnitTesting/Sources/UnitTesting/include/RollbarTestHelper.h +++ /dev/null @@ -1,30 +0,0 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -/// Utility class aiding in implementing SDK's unit tests -@interface RollbarTestHelper : NSObject - -#pragma mark - class methods - -/// returns Rollbar environment dedicated to the SDK's unit tests -+ (nonnull NSString *)getRollbarEnvironment; - -/// returns Rollbar access token dedicated to the payloads sent by SDK's live unit tests -+ (nonnull NSString *)getRollbarPayloadsAccessToken; - -/// returns Rollbar WRITE access token dedicated to the deploys registered by SDK's live unit tests -+ (nonnull NSString *)getRollbarDeploysWriteAccessToken; - -/// returns Rollbar READ access token dedicated to iterating over the deploys registered by SDK's live unit tests -+ (nonnull NSString *)getRollbarDeploysReadAccessToken; - -#pragma mark - instance initializers - -/// Hides initializer -- (instancetype)init -NS_UNAVAILABLE; - -@end - -NS_ASSUME_NONNULL_END diff --git a/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h b/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h deleted file mode 100644 index c1156486..00000000 --- a/UnitTesting/Sources/UnitTesting/include/RollbarUnitTestSettings.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef RollbarUnitTestSettings_h -#define RollbarUnitTestSettings_h - -static NSString * _Nonnull const ROLLBAR_UNIT_TEST_ENVIRONMENT = -@"Rollbar-Apple-UnitTests"; - -static NSString * _Nonnull const ROLLBAR_UNIT_TEST_PAYLOADS_ACCESS_TOKEN = -@"09da180aba21479e9ed3d91e0b8d58d6"; - -static NSString * _Nonnull const ROLLBAR_UNIT_TEST_DEPLOYS_WRITE_ACCESS_TOKEN = -@"efdc4b85d66045f293a7f9e99c732f61"; - -static NSString * _Nonnull const ROLLBAR_UNIT_TEST_DEPLOYS_READ_ACCESS_TOKEN = -@"595cbf76b05b45f2b3ef661a2e0078d4"; - -#endif /* RollbarUnitTestSettings_h */ diff --git a/UnitTesting/Sources/UnitTesting/include/module.modulemap b/UnitTesting/Sources/UnitTesting/include/module.modulemap deleted file mode 100644 index 0eadb038..00000000 --- a/UnitTesting/Sources/UnitTesting/include/module.modulemap +++ /dev/null @@ -1,8 +0,0 @@ -module UnitTesting { - umbrella "." - - export * - module * { export * } - - requires objc -} From 56c9bab9ea334704034a82b871260914a0775067 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 21 Mar 2022 22:52:11 -0700 Subject: [PATCH 27/32] tests: fixing CocoaLumberjack use with Swift code --- RollbarCocoaLumberjack/Package.swift | 2 ++ .../RollbarCocoaLumberjackTests.swift | 28 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/RollbarCocoaLumberjack/Package.swift b/RollbarCocoaLumberjack/Package.swift index 8689e237..e96d181c 100644 --- a/RollbarCocoaLumberjack/Package.swift +++ b/RollbarCocoaLumberjack/Package.swift @@ -50,7 +50,9 @@ let package = Package( name: "RollbarCocoaLumberjackTests", dependencies: [ "UnitTesting", + "CocoaLumberjack", "RollbarCocoaLumberjack", + .productItem(name: "CocoaLumberjackSwift", package: "CocoaLumberjack", condition: nil), ] ), .testTarget( diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift index 268fb32f..7360fa00 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -1,5 +1,7 @@ import XCTest import UnitTesting +import RollbarNotifier +import CocoaLumberjackSwift @testable import RollbarCocoaLumberjack final class RollbarCocoaLumberjackTests: XCTestCase { @@ -8,12 +10,36 @@ final class RollbarCocoaLumberjackTests: XCTestCase { super.setUp(); - //RollbarTestHelper. + RollbarLogger.clearSdkDataStore(); + let rollbarConfig = RollbarConfig(); + rollbarConfig.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + rollbarConfig.destination.environment = RollbarTestHelper.getRollbarEnvironment(); + //rollbarConfig.developerOptions.transmit = false; + + XCTAssertTrue(RollbarLogger.readLogItemsFromStore().count == 0); + XCTAssertEqual(RollbarLogger.readLogItemsFromStore().count, 0); + + dynamicLogLevel = DDLogLevel.debug; + DDLog.add(DDOSLogger .sharedInstance); + let ddFileLogger = DDFileLogger(); + ddFileLogger.rollingFrequency = 60 * 60 * 24; // 24-hours rolling + ddFileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // he above code tells the application to keep a day worth of log files on the system. + DDLog.add(ddFileLogger); + + DDLog.add(RollbarCocoaLumberjackLogger.create(with: rollbarConfig)); } func testBasics() { + XCTAssertEqual(RollbarLogger.readLogItemsFromStore().count, 0); + + DDLogError("Get it to Rollbar!"); + + //Thread.sleep(forTimeInterval: 5.0); + + XCTAssertEqual(RollbarLogger.readLogItemsFromStore().count, 1); } func testBasicsMore() { From 0e460f12f8819971bbbd863f8a7975bdadf4327c Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 22 Mar 2022 15:46:12 -0700 Subject: [PATCH 28/32] feat: resolve #141 Apply developer options of the persisted payload when sending the payload --- .../Sources/RollbarNotifier/RollbarLogger.m | 74 +++++++++++++++---- 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m index ae379503..f7b5d4bb 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m +++ b/RollbarNotifier/Sources/RollbarNotifier/RollbarLogger.m @@ -78,7 +78,9 @@ + (void)initialize { [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; stateFilePath = [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_STATE_FILE_NAME]; - + payloadsFilePath = + [cachesDirectory stringByAppendingPathComponent:PAYLOADS_FILE_NAME]; + // either create or overwrite the payloads log file: [[NSFileManager defaultManager] createFileAtPath:payloadsFilePath contents:nil @@ -790,33 +792,48 @@ - (BOOL)sendItem:(NSDictionary *)payload NSUInteger retryCount = [queueState[@"retry_count"] unsignedIntegerValue]; - if (0 == retryCount && YES == self.configuration.developerOptions.logPayload) { - if (NO == self.configuration.developerOptions.suppressSdkInfoLogging) { + RollbarConfig *rollbarConfig = + [[RollbarConfig alloc] initWithDictionary:rollbarPayload.data.notifier.jsonFriendlyData[@"configured_options"]]; + + if (0 == retryCount && YES == rollbarConfig.developerOptions.logPayload) { + if (NO == rollbarConfig.developerOptions.suppressSdkInfoLogging) { RollbarSdkLog(@"About to send payload: %@", [[NSString alloc] initWithData:jsonPayload encoding:NSUTF8StringEncoding] ); } + // - save this payload into a proper payloads log file: + //***************************************************** + + // compose the payloads log file path: + NSString *cachesDirectory = [RollbarCachesDirectory directory]; + NSString *payloadsLogFilePath = + [cachesDirectory stringByAppendingPathComponent:rollbarConfig.developerOptions.payloadLogFile]; + // create the payloads log file if it does not exist already: + if (![[NSFileManager defaultManager] fileExistsAtPath:payloadsLogFilePath]) { + + [[NSFileManager defaultManager] createFileAtPath:payloadsLogFilePath + contents:nil + attributes:nil]; + } // append-save this jsonPayload into the payloads log file: NSFileHandle *fileHandle = - [NSFileHandle fileHandleForWritingAtPath:payloadsFilePath]; - + [NSFileHandle fileHandleForWritingAtPath:payloadsLogFilePath]; [fileHandle seekToEndOfFile]; [fileHandle writeData:jsonPayload]; [fileHandle writeData:[@"\n" dataUsingEncoding:NSUTF8StringEncoding]]; [fileHandle closeFile]; } - RollbarConfig *rollbarConfig = - [[RollbarConfig alloc] initWithDictionary:rollbarPayload.data.notifier.jsonFriendlyData[@"configured_options"]]; - BOOL success = rollbarConfig ? [self sendPayload:jsonPayload usingConfig:rollbarConfig] : [self sendPayload:jsonPayload]; // backward compatibility with just upgraded very old SDKs... if (!success) { + if (retryCount < MAX_RETRY_COUNT) { + queueState[@"retry_count"] = [NSNumber numberWithUnsignedInteger:retryCount + 1]; @@ -1131,6 +1148,8 @@ - (void)captureTelemetryDataForNetwork:(BOOL)reachable { @end +#pragma mark - RollbarLogger (Test) + static NSString * const QUEUED_TELEMETRY_ITEMS_FILE_NAME = @"rollbar.telemetry"; @implementation RollbarLogger (Test) @@ -1139,6 +1158,7 @@ + (void)clearSdkDataStore { [RollbarLogger clearLogItemsStore]; [RollbarLogger _clearFile:[RollbarLogger _telemetryItemsStorePath]]; + [RollbarLogger _clearFile:[RollbarLogger _payloadsLogStorePath]]; } + (void)clearLogItemsStore { @@ -1147,13 +1167,29 @@ + (void)clearLogItemsStore { [RollbarLogger _clearFile:[RollbarLogger _logItemsStorePath]]; } -+ (NSArray *)readLogItemsFromStore { ++ (void)clearSdkFile:(nonnull NSString *)sdkFileName { + + [RollbarLogger _clearFile:[RollbarLogger _getSDKDataFilePath:sdkFileName]]; +} + ++ (nonnull NSArray *)readLogItemsFromStore { NSString *filePath = [RollbarLogger _logItemsStorePath]; + return [RollbarLogger readPayloadsDataFromFile:filePath]; +} + ++ (nonnull NSArray *)readPayloadsFromSdkLog { + + NSString *filePath = [RollbarLogger _payloadsLogStorePath]; + return [RollbarLogger readPayloadsDataFromFile:filePath]; +} + ++ (nonnull NSArray *)readPayloadsDataFromFile:(nonnull NSString *)filePath { + RollbarFileReader *reader = [[RollbarFileReader alloc] initWithFilePath:filePath andOffset:0]; - NSMutableArray *items = [NSMutableArray array]; + NSMutableArray *items = [NSMutableArray array]; [reader enumerateLinesUsingBlock:^(NSString *line, NSUInteger nextOffset, BOOL *stop) { NSError *error = nil; NSMutableDictionary *payload = @@ -1206,20 +1242,28 @@ + (void)_clearFile:(nonnull NSString *)filePath { + (nonnull NSString *)_logItemsStorePath { - NSString *cachesDirectory = [RollbarCachesDirectory directory]; - return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_FILE_NAME]; + return [RollbarLogger _getSDKDataFilePath:QUEUED_ITEMS_FILE_NAME]; } + (nonnull NSString *)_logItemsStoreStatePath { - NSString *cachesDirectory = [RollbarCachesDirectory directory]; - return [cachesDirectory stringByAppendingPathComponent:QUEUED_ITEMS_STATE_FILE_NAME]; + return [RollbarLogger _getSDKDataFilePath:QUEUED_ITEMS_STATE_FILE_NAME]; } + (nonnull NSString *)_telemetryItemsStorePath { + return [RollbarLogger _getSDKDataFilePath:QUEUED_TELEMETRY_ITEMS_FILE_NAME]; +} + ++ (nonnull NSString *)_payloadsLogStorePath { + + return [RollbarLogger _getSDKDataFilePath:PAYLOADS_FILE_NAME]; +} + ++ (nonnull NSString *)_getSDKDataFilePath:(nonnull NSString *)sdkFileName { + NSString *cachesDirectory = [RollbarCachesDirectory directory]; - return [cachesDirectory stringByAppendingPathComponent:QUEUED_TELEMETRY_ITEMS_FILE_NAME]; + return [cachesDirectory stringByAppendingPathComponent:sdkFileName]; } + (NSThread *)_test_rollbarThread { From 18584ef1891b265f0f9c88c112f1482d517b0e59 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 22 Mar 2022 15:49:42 -0700 Subject: [PATCH 29/32] test: resolve #140 --- .../RollbarNotifier/include/RollbarLogger+Test.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h index 622e30bb..758bc56b 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h +++ b/RollbarNotifier/Sources/RollbarNotifier/include/RollbarLogger+Test.h @@ -13,7 +13,15 @@ NS_ASSUME_NONNULL_BEGIN /// Reads all the payloads queued up in the persistent store ///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. -+ (NSArray *)readLogItemsFromStore; ++ (nonnull NSArray *)readLogItemsFromStore; + +/// Reads all payloads from the default payloads log +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (nonnull NSArray *)readPayloadsFromSdkLog; + +/// Reads all payloads from the provided file path +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (nonnull NSArray *)readPayloadsDataFromFile:(nonnull NSString *)filePath; /// Clears all the payloads queued up in the persistent store ///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. @@ -23,6 +31,11 @@ NS_ASSUME_NONNULL_BEGIN ///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. + (void)clearSdkDataStore; +/// Clears data from the specified file within the SDK data folder +/// @param sdkFileName fileName within the SDK data folder +///@note THIS METHOD IS TO BE USED FOR TESTING PURPOSES ONLY. ++ (void)clearSdkFile:(nonnull NSString *)sdkFileName; + @end NS_ASSUME_NONNULL_END From 278e8b396ed2d9106ea9c9faebe7b2569f922c44 Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 22 Mar 2022 15:53:04 -0700 Subject: [PATCH 30/32] test: resolve #134 --- CHANGELOG.md | 24 ++++++++++--------- .../RollbarCocoaLumberjackTests.swift | 23 +++++++++--------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8baf3846..f136cf3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,19 +27,21 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ### 2.1.0 -- feat: resolve #133 - Implement RollbarCocoaLumberjack module -- test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack -- fix: resolve #136 - RollbarPLCrashReporter.init() no longer available +- feat: resolve #141 - Apply developer options of the persisted payload when sending the payload +- feat: resolve #133 - Implement RollbarCocoaLumberjack module +- test: resolve #134 - Implement unit tests for RollbarCocoaLumberjack +- fix: resolve #136 - RollbarPLCrashReporter.init() no longer available +- test: resolve #140 - Factor out common SDK unit testing API - chore: resolve #112 - Upgrade to the latest PLCrashReporter 1.0.1 -- docs: resolve #138 - Move current SDK documentation from readme.io to the repo -- docs: resolve #139 - Document new RollbarCocoaLumberjack module +- docs: resolve #138 - Move current SDK documentation from readme.io to the repo +- docs: resolve #139 - Document new RollbarCocoaLumberjack module ### 2.0.3 -- docs: resolve #122 - Update RollbarCommon public API doc comments so they are properly rendered by Xcode Quick Help -- docs: resolve #124 - Update RollbarDeploys public API doc comments so they are properly rendered by Xcode Quick Help -- docs: resolve #126 - Update RollbarSwift, RollbarAUL, RollbarPLCrashReporter, and RollbarKSCrash public API doc comments so they are properly rendered by Xcode Quick Help -- docs: resolve #127 - Update RollbarNotifier public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #122 - Update RollbarCommon public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #124 - Update RollbarDeploys public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #126 - Update RollbarSwift, RollbarAUL, RollbarPLCrashReporter, and RollbarKSCrash public API doc comments so they are properly rendered by Xcode Quick Help +- docs: resolve #127 - Update RollbarNotifier public API doc comments so they are properly rendered by Xcode Quick Help - chore: resolve #114 - Consolidate destination parameters for samples - chore: resolve #113 - Consolidate destination parameters for unit tests @@ -73,7 +75,7 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ### 2.0.0-beta.14 - feat: allocated new RollbarAUL module project -- fix: resolve #72 - Rollbar* pods 2.0.0-beta.10 not all published +- fix: resolve #72 - Rollbar pods 2.0.0-beta.10 not all published ### 2.0.0-beta.13 @@ -81,7 +83,7 @@ The change log has moved to this repo's [GitHub Releases Page](https://github.co ### 2.0.0-beta.11 -- fix: resolve #72 - Rollbar* pods 2.0.0-beta.10 not all published +- fix: resolve #72 - Rollbar pods 2.0.0-beta.10 not all published ### 2.0.0-beta.10 diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift index 7360fa00..4f86bbb7 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -15,10 +15,11 @@ final class RollbarCocoaLumberjackTests: XCTestCase { let rollbarConfig = RollbarConfig(); rollbarConfig.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); rollbarConfig.destination.environment = RollbarTestHelper.getRollbarEnvironment(); - //rollbarConfig.developerOptions.transmit = false; - - XCTAssertTrue(RollbarLogger.readLogItemsFromStore().count == 0); - XCTAssertEqual(RollbarLogger.readLogItemsFromStore().count, 0); + rollbarConfig.developerOptions.transmit = false; + rollbarConfig.developerOptions.logPayload = true; + + XCTAssertTrue(RollbarLogger.readPayloadsFromSdkLog().count == 0); + XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 0); dynamicLogLevel = DDLogLevel.debug; DDLog.add(DDOSLogger .sharedInstance); @@ -33,17 +34,15 @@ final class RollbarCocoaLumberjackTests: XCTestCase { func testBasics() { - XCTAssertEqual(RollbarLogger.readLogItemsFromStore().count, 0); - - DDLogError("Get it to Rollbar!"); + XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 0); - //Thread.sleep(forTimeInterval: 5.0); + DDLogError("Get it to Rollbar #1!"); + DDLogError("Get it to Rollbar #2!"); + DDLogError("Get it to Rollbar #3!"); - XCTAssertEqual(RollbarLogger.readLogItemsFromStore().count, 1); - } + Thread.sleep(forTimeInterval: 3.0); - func testBasicsMore() { - + XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 3); } // func testExample() throws { From ebf1f48bd0d40a1c074b678ad51afc10ae5d770d Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Tue, 22 Mar 2022 16:42:37 -0700 Subject: [PATCH 31/32] docs: resolve #139 --- .../RollbarCocoaLumberjackTests.m | 2 +- .../RollbarCocoaLumberjackTests.swift | 4 +- .../contents.xcworkspacedata | 3 ++ docs/SDK module - RollbarCocoaLumberjack.md | 41 +++++++++++++++++-- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m index cc4266c7..cf06cf7e 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests-ObjC/RollbarCocoaLumberjackTests.m @@ -29,7 +29,7 @@ - (void)setUp { DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling fileLogger.logFileManager.maximumNumberOfLogFiles = 1; - // he above code tells the application to keep a day worth of log files on the system. + // the above code tells the application to keep a day worth of log files on the system. [DDLog addLogger:fileLogger]; } diff --git a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift index 4f86bbb7..768a650d 100644 --- a/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift +++ b/RollbarCocoaLumberjack/Tests/RollbarCocoaLumberjackTests/RollbarCocoaLumberjackTests.swift @@ -22,11 +22,11 @@ final class RollbarCocoaLumberjackTests: XCTestCase { XCTAssertEqual(RollbarLogger.readPayloadsFromSdkLog().count, 0); dynamicLogLevel = DDLogLevel.debug; - DDLog.add(DDOSLogger .sharedInstance); + DDLog.add(DDOSLogger.sharedInstance); let ddFileLogger = DDFileLogger(); ddFileLogger.rollingFrequency = 60 * 60 * 24; // 24-hours rolling ddFileLogger.logFileManager.maximumNumberOfLogFiles = 1; - // he above code tells the application to keep a day worth of log files on the system. + // the above code tells the application to keep a day worth of log files on the system. DDLog.add(ddFileLogger); DDLog.add(RollbarCocoaLumberjackLogger.create(with: rollbarConfig)); diff --git a/RollbarSDK.xcworkspace/contents.xcworkspacedata b/RollbarSDK.xcworkspace/contents.xcworkspacedata index dc3a491b..2ae6dedb 100644 --- a/RollbarSDK.xcworkspace/contents.xcworkspacedata +++ b/RollbarSDK.xcworkspace/contents.xcworkspacedata @@ -4,6 +4,9 @@ + + diff --git a/docs/SDK module - RollbarCocoaLumberjack.md b/docs/SDK module - RollbarCocoaLumberjack.md index 2ff2f559..bf2d27e6 100644 --- a/docs/SDK module - RollbarCocoaLumberjack.md +++ b/docs/SDK module - RollbarCocoaLumberjack.md @@ -20,23 +20,34 @@ Implements CocoaLumberjack compatible logger (`DDLogger`) capable of "intercepti 2. Accordingly, import our *RollbarCocoaLumberjack* module. 3. Setup properly configured `RollbarConfig` object. 4. Create a `RollbarCocoaLumberjackLogger` instance using the preconfigured `RollbarConfig` instance and add it to the `DDLog` -5. Fro this point on, all relevant log entries made anywhere via the *CocoaLumberjack* logging methods will be "forked" to Rollbar based on filtering conditions specified on both levels: *CocoaLumberjackLogger* configuration and in `RollbarConfig` instances defined above. +5. From this point on, all relevant log entries made anywhere via the *CocoaLumberjack* logging methods will be "forked" to Rollbar based on filtering conditions specified on both levels: *CocoaLumberjackLogger* configuration and in `RollbarConfig` instances defined above. #### Objective-C ```Obj-C //... +#define LOG_LEVEL_DEF ddLogLevel +//... +@import CocoaLumberjack; @import RollbarCocoaLumberjack; //... //... + // setting up CocoaLumberjack usage: + [DDLog addLogger:[DDOSLogger sharedInstance]]; + + DDFileLogger *fileLogger = [[DDFileLogger alloc] init]; + fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling + fileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // the above code tells the application to keep a day worth of log files on the system. + [DDLog addLogger:fileLogger]; + + // create a valid RTollbar config: RollbarConfig *config = [[RollbarConfig alloc] init]; config.destination.accessToken = @"ROLLBAR_ACCESS_TOKEN"; config.destination.environment = @"ROLLBAR_ENVIRONMENT"; - config.developerOptions.transmit = YES; - config.developerOptions.logPayload = YES; - config.loggingOptions.maximumReportsPerMinute = 5000; + // add Rollbar logger plug-in for CocoaLumberjack: [DDLog addLogger:[RollbarCocoaLumberjackLogger createWithRollbarConfig:config]]; //... ``` @@ -44,5 +55,27 @@ Implements CocoaLumberjack compatible logger (`DDLogger`) capable of "intercepti #### Swift ```Swift +//... +import CocoaLumberjackSwift +import RollbarCocoaLumberjack +//... +//... + // setting up CocoaLumberjack usage: + dynamicLogLevel = DDLogLevel.debug; + DDLog.add(DDOSLogger.sharedInstance); + + let ddFileLogger = DDFileLogger(); + ddFileLogger.rollingFrequency = 60 * 60 * 24; // 24-hours rolling + ddFileLogger.logFileManager.maximumNumberOfLogFiles = 1; + // the above code tells the application to keep a day worth of log files on the system. + DDLog.add(ddFileLogger); + + // create a valid RTollbar config: + let rollbarConfig = RollbarConfig(); + rollbarConfig.destination.accessToken = RollbarTestHelper.getRollbarPayloadsAccessToken(); + rollbarConfig.destination.environment = RollbarTestHelper.getRollbarEnvironment(); + + // add Rollbar logger plug-in for CocoaLumberjack: + DDLog.add(RollbarCocoaLumberjackLogger.create(with: rollbarConfig)); ``` From 6d7be238cf4b28aa226ddfa54224908670b2fc5a Mon Sep 17 00:00:00 2001 From: Andrey Kornich Date: Mon, 18 Apr 2022 15:43:00 -0700 Subject: [PATCH 32/32] chore: incremented version --- RollbarAUL.podspec | 2 +- RollbarCommon.podspec | 2 +- RollbarDeploys.podspec | 2 +- RollbarKSCrash.podspec | 2 +- RollbarNotifier.podspec | 2 +- RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m | 2 +- RollbarPLCrashReporter.podspec | 2 +- RollbarSDK.experimental_podspec | 2 +- RollbarSwift.podspec | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/RollbarAUL.podspec b/RollbarAUL.podspec index c7552930..1c14c879 100644 --- a/RollbarAUL.podspec +++ b/RollbarAUL.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarAUL" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarCommon.podspec b/RollbarCommon.podspec index d11d958c..339ec334 100644 --- a/RollbarCommon.podspec +++ b/RollbarCommon.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarCommon" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarDeploys.podspec b/RollbarDeploys.podspec index a75824d2..f3f230c9 100644 --- a/RollbarDeploys.podspec +++ b/RollbarDeploys.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarDeploys" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarKSCrash.podspec b/RollbarKSCrash.podspec index d78836aa..54fe7e25 100644 --- a/RollbarKSCrash.podspec +++ b/RollbarKSCrash.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarKSCrash" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier.podspec b/RollbarNotifier.podspec index 1c38bf94..72c1e3a5 100644 --- a/RollbarNotifier.podspec +++ b/RollbarNotifier.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarNotifier" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m index 0ddb117f..153aacb6 100644 --- a/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m +++ b/RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarConfig.m @@ -14,7 +14,7 @@ #pragma mark - constants -static NSString * const NOTIFIER_VERSION = @"2.0.3"; +static NSString * const NOTIFIER_VERSION = @"2.1.0"; static NSString * const NOTIFIER_NAME = @"rollbar-apple"; diff --git a/RollbarPLCrashReporter.podspec b/RollbarPLCrashReporter.podspec index 263d1334..2313f85d 100644 --- a/RollbarPLCrashReporter.podspec +++ b/RollbarPLCrashReporter.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarPLCrashReporter" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC diff --git a/RollbarSDK.experimental_podspec b/RollbarSDK.experimental_podspec index d61a9a4b..8b8ef4a3 100644 --- a/RollbarSDK.experimental_podspec +++ b/RollbarSDK.experimental_podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |sdk| # Rollbar SDK: # ============ - sdk.version = "2.0.3" + sdk.version = "2.1.0" sdk.name = "RollbarSDK" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." sdk.description = <<-DESC diff --git a/RollbarSwift.podspec b/RollbarSwift.podspec index 786dac9c..90a0f688 100644 --- a/RollbarSwift.podspec +++ b/RollbarSwift.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| - s.version = "2.0.3" + s.version = "2.1.0" s.name = "RollbarSwift" s.summary = "Application or client side SDK for interacting with the Rollbar API Server." s.description = <<-DESC