-
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.
refactor: rename Bugsnag.addAttribute to addMetadata, add tests
- Loading branch information
1 parent
6c74bfb
commit 84481f2
Showing
7 changed files
with
138 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// BugsnagTests.m | ||
// Tests | ||
// | ||
// Created by Robin Macharg on 04/02/2020. | ||
// Copyright © 2020 Bugsnag. All rights reserved. | ||
// | ||
// Unit tests of global Bugsnag behaviour | ||
|
||
#import "Bugsnag.h" | ||
#import "BugsnagTestConstants.h" | ||
#import <XCTest/XCTest.h> | ||
|
||
@interface BugsnagTests : XCTestCase | ||
|
||
@end | ||
|
||
@implementation BugsnagTests | ||
|
||
/** | ||
* Test that global metadata is added correctly, applied to each event, and | ||
* deleted appropriately. | ||
*/ | ||
- (void)testBugsnagMetadataAddition { | ||
|
||
NSError *error; | ||
BugsnagConfiguration *configuration = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1 error:&error]; | ||
[Bugsnag startBugsnagWithConfiguration:configuration]; | ||
[Bugsnag addMetadataToSection:@"mySection1" key:@"aKey1" value:@"aValue1"]; | ||
|
||
// We should see our added metadata in every request. Let's try a couple: | ||
|
||
NSException *exception1 = [[NSException alloc] initWithName:@"exception1" reason:@"reason1" userInfo:nil]; | ||
NSException *exception2 = [[NSException alloc] initWithName:@"exception2" reason:@"reason2" userInfo:nil]; | ||
|
||
[Bugsnag notify:exception1 block:^(BugsnagEvent * _Nonnull report) { | ||
XCTAssertEqual([[[report metaData] valueForKey:@"mySection1"] valueForKey:@"aKey1"], @"aValue1"); | ||
XCTAssertEqual([report errorClass], @"exception1"); | ||
XCTAssertEqual([report errorMessage], @"reason1"); | ||
XCTAssertNil([[report metaData] valueForKey:@"mySection2"]); | ||
|
||
// Add some additional metadata once we're sure it's not already there | ||
[Bugsnag addMetadataToSection:@"mySection2" key:@"aKey2" value:@"aValue2"]; | ||
}]; | ||
|
||
[Bugsnag notify:exception2 block:^(BugsnagEvent * _Nonnull report) { | ||
XCTAssertEqual([[[report metaData] valueForKey:@"mySection1"] valueForKey:@"aKey1"], @"aValue1"); | ||
XCTAssertEqual([[[report metaData] valueForKey:@"mySection2"] valueForKey:@"aKey2"], @"aValue2"); | ||
XCTAssertEqual([report errorClass], @"exception2"); | ||
XCTAssertEqual([report errorMessage], @"reason2"); | ||
}]; | ||
|
||
// Check nil value causes deletions | ||
|
||
[Bugsnag addMetadataToSection:@"mySection1" key:@"aKey1" value:nil]; | ||
[Bugsnag addMetadataToSection:@"mySection2" key:@"aKey2" value:nil]; | ||
|
||
[Bugsnag notify:exception1 block:^(BugsnagEvent * _Nonnull report) { | ||
XCTAssertNil([[[report metaData] valueForKey:@"mySection1"] valueForKey:@"aKey1"]); | ||
XCTAssertNil([[[report metaData] valueForKey:@"mySection2"] valueForKey:@"aKey2"]); | ||
}]; | ||
} | ||
|
||
@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
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,36 @@ | ||
// | ||
// BugsnagSwiftTests.swift | ||
// Tests | ||
// | ||
// Created by Robin Macharg on 05/02/2020. | ||
// Copyright © 2020 Bugsnag. All rights reserved. | ||
// | ||
// Swift unit tests of global Bugsnag behaviour | ||
|
||
import XCTest | ||
|
||
class BugsnagSwiftTests: XCTestCase { | ||
|
||
/** | ||
* Confirm that the method is exposed to Swift correctly | ||
*/ | ||
func testAddMetadataToSectionIsExposedToSwiftCorrectly() { | ||
do { | ||
if let configuration = try BugsnagConfiguration(DUMMY_APIKEY_32CHAR_1) { | ||
Bugsnag.start(with: configuration) | ||
Bugsnag.addMetadata("mySection1", key: "myKey1", value: "myValue1") | ||
|
||
let exception1 = NSException(name: NSExceptionName(rawValue: "exception1"), reason: "reason1", userInfo: nil) | ||
|
||
Bugsnag.notify(exception1) { (event) in | ||
// Arbitrary test, replicating the ObjC one | ||
let value = (event.metaData["mySection1"] as! [String : Any])["myKey1"] as! String | ||
XCTAssertEqual(value, "myValue1") | ||
} | ||
} | ||
} | ||
catch let e as NSError { | ||
print(e) | ||
} | ||
} | ||
} |