-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #493 from bugsnag/robin/add-additional-metadata-to…
…-error-breadcrumbs (feat) Increased detail in handled event breadcrumb
- Loading branch information
Showing
10 changed files
with
163 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// | ||
// BugsnagClientTests.m | ||
// Tests | ||
// | ||
// Created by Robin Macharg on 18/03/2020. | ||
// Copyright © 2020 Bugsnag. All rights reserved. | ||
// | ||
|
||
#import "Bugsnag.h" | ||
#import "BugsnagBreadcrumbs.h" | ||
#import "BugsnagClient.h" | ||
#import "BugsnagTestConstants.h" | ||
#import "BugsnagKeys.h" | ||
#import <XCTest/XCTest.h> | ||
|
||
@interface BugsnagClientTests : XCTestCase | ||
@end | ||
|
||
@interface Bugsnag () | ||
+ (BugsnagConfiguration *)configuration; | ||
+ (BugsnagClient *)client; | ||
@end | ||
|
||
@interface BugsnagClient () | ||
- (void)orientationChanged:(NSNotification *)notif; | ||
@end | ||
|
||
@interface BugsnagBreadcrumb () | ||
- (NSDictionary *)objectValue; | ||
@end | ||
|
||
@interface BugsnagConfiguration () | ||
@property(readonly, strong, nullable) BugsnagBreadcrumbs *breadcrumbs; | ||
@end | ||
|
||
NSString *BSGFormatSeverity(BSGSeverity severity); | ||
|
||
@implementation BugsnagClientTests | ||
|
||
/** | ||
* A boilerplate helper method to setup Bugsnag | ||
*/ | ||
-(void)setUpBugsnagWillCallNotify:(bool)willNotify { | ||
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
if (willNotify) { | ||
[configuration addOnSendBlock:^bool(BugsnagEvent * _Nonnull event) { return false; }]; | ||
} | ||
[Bugsnag startBugsnagWithConfiguration:configuration]; | ||
} | ||
|
||
/** | ||
* Handled events leave a breadcrumb when notify() is called. Test that values are inserted | ||
* correctly. | ||
*/ | ||
- (void)testAutomaticNotifyBreadcrumbData { | ||
|
||
[self setUpBugsnagWillCallNotify:false]; | ||
|
||
NSException *ex = [[NSException alloc] initWithName:@"myName" reason:@"myReason1" userInfo:nil]; | ||
|
||
__block NSString *eventErrorClass; | ||
__block NSString *eventErrorMessage; | ||
__block BOOL eventUnhandled; | ||
__block NSString *eventSeverity; | ||
|
||
// Check that the event is passed the apiKey | ||
[Bugsnag notify:ex block:^(BugsnagEvent * _Nonnull event) { | ||
XCTAssertEqual(event.apiKey, DUMMY_APIKEY_32CHAR_1); | ||
|
||
// Grab the values that end up in the event for later comparison | ||
eventErrorClass = [event errorClass]; | ||
eventErrorMessage = [event errorMessage]; | ||
eventUnhandled = [event valueForKeyPath:@"handledState.unhandled"] ? YES : NO; | ||
eventSeverity = BSGFormatSeverity([event severity]); | ||
}]; | ||
|
||
// Check that we can change it | ||
[Bugsnag notify:ex]; | ||
|
||
NSDictionary *breadcrumb = [[[[Bugsnag client] configuration] breadcrumbs][1] objectValue]; | ||
NSDictionary *metadata = [breadcrumb valueForKey:@"metaData"]; | ||
|
||
XCTAssertEqualObjects([breadcrumb valueForKey:@"type"], @"error"); | ||
XCTAssertEqualObjects([breadcrumb valueForKey:@"name"], eventErrorClass); | ||
XCTAssertEqualObjects([metadata valueForKey:@"errorClass"], eventErrorClass); | ||
XCTAssertEqualObjects([metadata valueForKey:@"name"], eventErrorMessage); | ||
XCTAssertEqual((bool)[metadata valueForKey:@"unhandled"], eventUnhandled); | ||
XCTAssertEqualObjects([metadata valueForKey:@"severity"], eventSeverity); | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.