-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
83c98a8
commit e58f54e
Showing
10 changed files
with
301 additions
and
1 deletion.
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
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,195 @@ | ||
// | ||
// BugsnagOnBreadcrumbTest.m | ||
// Tests | ||
// | ||
// Created by Jamie Lynch on 19/03/2020. | ||
// Copyright © 2020 Bugsnag. All rights reserved. | ||
// | ||
|
||
#import <XCTest/XCTest.h> | ||
|
||
#import "Bugsnag.h" | ||
#import "BugsnagConfiguration.h" | ||
#import "BugsnagTestConstants.h" | ||
#import "BugsnagBreadcrumbs.h" | ||
|
||
@interface BugsnagConfiguration () | ||
@property NSMutableArray *onBreadcrumbBlocks; | ||
@property BugsnagBreadcrumbs *breadcrumbs; | ||
@end | ||
|
||
@interface BugsnagBreadcrumbs () | ||
@property(nonatomic, readwrite, strong) NSMutableArray *breadcrumbs; | ||
@end | ||
|
||
@interface BugsnagOnBreadcrumbTest : XCTestCase | ||
@end | ||
|
||
@implementation BugsnagOnBreadcrumbTest | ||
|
||
|
||
/** | ||
* Test that onBreadcrumb blocks get called once added | ||
*/ | ||
- (void)testAddOnBreadcrumbBlock { | ||
|
||
// Setup | ||
__block XCTestExpectation *expectation = [self expectationWithDescription:@"Remove On Breadcrumb Block"]; | ||
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
[config setEndpointsForNotify:@"http://notreal.bugsnag.com" sessions:@"http://notreal.bugsnag.com"]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
BugsnagOnBreadcrumbBlock crumbBlock = ^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
// We expect the breadcrumb block to be called | ||
[expectation fulfill]; | ||
return YES; | ||
}; | ||
[config addOnBreadcrumbBlock:crumbBlock]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
|
||
// Call onbreadcrumb blocks | ||
[Bugsnag startBugsnagWithConfiguration:config]; | ||
[Bugsnag leaveBreadcrumbWithMessage:@"Hello"]; | ||
[self waitForExpectationsWithTimeout:5.0 handler:nil]; | ||
} | ||
|
||
/** | ||
* Test that onBreadcrumb blocks do not get called once they've been removed | ||
*/ | ||
- (void)testRemoveOnBreadcrumbBlock { | ||
// Setup | ||
// We expect NOT to be called | ||
__block XCTestExpectation *calledExpectation = [self expectationWithDescription:@"Remove On Breadcrumb Block"]; | ||
calledExpectation.inverted = YES; | ||
|
||
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
[config setEndpointsForNotify:@"http://notreal.bugsnag.com" sessions:@"http://notreal.bugsnag.com"]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
BugsnagOnBreadcrumbBlock crumbBlock = ^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
[calledExpectation fulfill]; | ||
return YES; | ||
}; | ||
|
||
// It's there (and from other tests we know it gets called) and then it's not there | ||
[config addOnBreadcrumbBlock:crumbBlock]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
[config removeOnBreadcrumbBlock:crumbBlock]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
|
||
[Bugsnag startBugsnagWithConfiguration:config]; | ||
[Bugsnag leaveBreadcrumbWithMessage:@"Hello"]; | ||
|
||
// Wait a second NOT to be called | ||
[self waitForExpectationsWithTimeout:1.0 handler:nil]; | ||
} | ||
/** | ||
* Test that an onBreadcrumb block is called after being added, then NOT called after being removed. | ||
* This test could be expanded to verify the behaviour when multiple blocks are added. | ||
*/ | ||
- (void)testAddOnBreadcrumbBlockThenRemove { | ||
|
||
__block int called = 0; // A counter | ||
|
||
// Setup | ||
__block XCTestExpectation *expectation1 = [self expectationWithDescription:@"Remove On Breadcrumb Block 1"]; | ||
__block XCTestExpectation *expectation2 = [self expectationWithDescription:@"Remove On Breadcrumb Block 2"]; | ||
expectation2.inverted = YES; | ||
|
||
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
[config setEndpointsForNotify:@"http://notreal.bugsnag.com" sessions:@"http://notreal.bugsnag.com"]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
|
||
BugsnagOnBreadcrumbBlock crumbBlock = ^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
switch (called) { | ||
case 0: | ||
[expectation1 fulfill]; | ||
break; | ||
case 1: | ||
[expectation2 fulfill]; | ||
break; | ||
} | ||
return YES; | ||
}; | ||
|
||
[config addOnBreadcrumbBlock:crumbBlock]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
|
||
// Call onbreadcrumb blocks | ||
[Bugsnag startBugsnagWithConfiguration:config]; | ||
[Bugsnag leaveBreadcrumbWithMessage:@"Hello"]; | ||
[self waitForExpectations:@[expectation1] timeout:1.0]; | ||
|
||
// Check it's NOT called once the block's deleted | ||
called++; | ||
[config removeOnBreadcrumbBlock:crumbBlock]; | ||
[Bugsnag leaveBreadcrumbWithMessage:@"Hello"]; | ||
[self waitForExpectations:@[expectation2] timeout:1.0]; | ||
} | ||
|
||
/** | ||
* Make sure slightly invalid removals and duplicate additions don't break things | ||
*/ | ||
- (void)testRemoveNonexistentOnBreadcrumbBlocks { | ||
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
BugsnagOnBreadcrumbBlock crumbBlock1 = ^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
return YES; | ||
}; | ||
BugsnagOnBreadcrumbBlock crumbBlock2 = ^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
return YES; | ||
}; | ||
|
||
[config addOnBreadcrumbBlock:crumbBlock1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
[config removeOnBreadcrumbBlock:crumbBlock2]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
[config removeOnBreadcrumbBlock:crumbBlock1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
[config removeOnBreadcrumbBlock:crumbBlock2]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
[config removeOnBreadcrumbBlock:crumbBlock1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 0); | ||
|
||
[config addOnBreadcrumbBlock:crumbBlock1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
[config addOnBreadcrumbBlock:crumbBlock1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 2); | ||
[config addOnBreadcrumbBlock:crumbBlock1]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 3); | ||
} | ||
|
||
/** | ||
* Test that onBreadcrumb blocks mutate a crumb | ||
*/ | ||
- (void)testAddOnBreadcrumbMutation { | ||
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
[config setEndpointsForNotify:@"http://notreal.bugsnag.com" sessions:@"http://notreal.bugsnag.com"]; | ||
[config addOnBreadcrumbBlock:^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
crumb.message = @"Foo"; | ||
return YES; | ||
}]; | ||
|
||
// Call onbreadcrumb blocks | ||
[Bugsnag startBugsnagWithConfiguration:config]; | ||
XCTAssertEqual([[config onBreadcrumbBlocks] count], 1); | ||
BugsnagBreadcrumb *crumb = [[config breadcrumbs].breadcrumbs firstObject]; | ||
XCTAssertEqualObjects(@"Foo", crumb.message); | ||
} | ||
|
||
/** | ||
* Test that onBreadcrumb blocks can discard crumbs | ||
*/ | ||
- (void)testAddOnBreadcrumbRejection { | ||
BugsnagConfiguration *config = [[BugsnagConfiguration alloc] initWithApiKey:DUMMY_APIKEY_32CHAR_1]; | ||
[config setEndpointsForNotify:@"http://notreal.bugsnag.com" sessions:@"http://notreal.bugsnag.com"]; | ||
[config addOnBreadcrumbBlock:^(BugsnagBreadcrumb * _Nonnull crumb) { | ||
return NO; | ||
}]; | ||
|
||
// Call onbreadcrumb blocks | ||
[Bugsnag startBugsnagWithConfiguration:config]; | ||
XCTAssertEqual([[config breadcrumbs].breadcrumbs count], 0); | ||
[Bugsnag leaveBreadcrumbWithMessage:@"Hello"]; | ||
XCTAssertEqual([[config breadcrumbs].breadcrumbs count], 0); | ||
} | ||
|
||
@end |
Oops, something went wrong.