-
-
Notifications
You must be signed in to change notification settings - Fork 342
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
Showing
14 changed files
with
289 additions
and
43 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
115 changes: 115 additions & 0 deletions
115
packages/core/RNSentryCocoaTester/RNSentryCocoaTesterTests/RNSentryStartFromFileTests.swift
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,115 @@ | ||
import XCTest | ||
|
||
final class RNSentryStartFromFileTests: XCTestCase { | ||
|
||
func testNoThrowOnMissingOptionsFile() { | ||
var wasConfigurationCalled = false | ||
|
||
RNSentrySDK.start(getNonExistingOptionsPath(), configureOptions: { _ in | ||
wasConfigurationCalled = true | ||
}) | ||
|
||
XCTAssertTrue(wasConfigurationCalled) | ||
|
||
let actualOptions = PrivateSentrySDKOnly.options | ||
XCTAssertNil(actualOptions.dsn) | ||
XCTAssertNil(actualOptions.parsedDsn) | ||
} | ||
|
||
func testNoThrowOnInvalidFileType() { | ||
var wasConfigurationCalled = false | ||
|
||
RNSentrySDK.start(getInvalidOptionsTypePath(), configureOptions: { _ in | ||
wasConfigurationCalled = true | ||
}) | ||
|
||
XCTAssertTrue(wasConfigurationCalled) | ||
|
||
let actualOptions = PrivateSentrySDKOnly.options | ||
XCTAssertNil(actualOptions.dsn) | ||
XCTAssertNil(actualOptions.parsedDsn) | ||
} | ||
|
||
func testNoThrowOnInvalidOptions() { | ||
var wasConfigurationCalled = false | ||
|
||
RNSentrySDK.start(getInvalidOptionsPath(), configureOptions: { _ in | ||
wasConfigurationCalled = true | ||
}) | ||
|
||
XCTAssertTrue(wasConfigurationCalled) | ||
|
||
let actualOptions = PrivateSentrySDKOnly.options | ||
XCTAssertNil(actualOptions.dsn) | ||
XCTAssertNotNil(actualOptions.parsedDsn) | ||
XCTAssertEqual(actualOptions.environment, "environment-from-invalid-file") | ||
} | ||
|
||
func testLoadValidOptions() { | ||
var wasConfigurationCalled = false | ||
|
||
RNSentrySDK.start(getValidOptionsPath(), configureOptions: { _ in | ||
wasConfigurationCalled = true | ||
}) | ||
|
||
XCTAssertTrue(wasConfigurationCalled) | ||
|
||
let actualOptions = PrivateSentrySDKOnly.options | ||
XCTAssertNil(actualOptions.dsn) | ||
XCTAssertNotNil(actualOptions.parsedDsn) | ||
XCTAssertEqual(actualOptions.environment, "environment-from-valid-file") | ||
} | ||
|
||
func testOptionsFromFileInConfigureOptions() { | ||
var wasConfigurationCalled = false | ||
|
||
RNSentrySDK.start(getValidOptionsPath()) { options in | ||
wasConfigurationCalled = true | ||
XCTAssertEqual(options.environment, "environment-from-valid-file") | ||
} | ||
|
||
XCTAssertTrue(wasConfigurationCalled) | ||
} | ||
|
||
func testOptionsOverwrittenInConfigureOptions() { | ||
RNSentrySDK.start(getValidOptionsPath()) { options in | ||
options.environment = "new-environment" | ||
} | ||
|
||
let actualOptions = PrivateSentrySDKOnly.options | ||
XCTAssertEqual(actualOptions.environment, "new-environment") | ||
} | ||
|
||
func getNonExistingOptionsPath() -> String { | ||
return "/non-existing.options.json" | ||
} | ||
|
||
func getInvalidOptionsTypePath() -> String { | ||
guard let path = getTestBundle().path(forResource: "invalid.options", ofType: "txt") else { | ||
fatalError("Could not get invalid type options path") | ||
} | ||
return path | ||
} | ||
|
||
func getInvalidOptionsPath() -> String { | ||
guard let path = getTestBundle().path(forResource: "invalid.options", ofType: "json") else { | ||
fatalError("Could not get invalid options path") | ||
} | ||
return path | ||
} | ||
|
||
func getValidOptionsPath() -> String { | ||
guard let path = getTestBundle().path(forResource: "valid.options", ofType: "json") else { | ||
fatalError("Could not get invalid options path") | ||
} | ||
return path | ||
} | ||
|
||
func getTestBundle() -> Bundle { | ||
let maybeBundle = Bundle.allBundles.first(where: { $0.bundlePath.hasSuffix(".xctest") }) | ||
guard let bundle = maybeBundle else { | ||
fatalError("Could not find test bundle") | ||
} | ||
return bundle | ||
} | ||
} |
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,9 @@ | ||
#import "RNSentrySDK.h" | ||
|
||
@interface | ||
RNSentrySDK (Test) | ||
|
||
+ (void)start:(NSString *)path | ||
configureOptions:(void (^)(SentryOptions *_Nonnull options))configureOptions; | ||
|
||
@end |
5 changes: 5 additions & 0 deletions
5
packages/core/RNSentryCocoaTester/TestAssets/invalid.options.json
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,5 @@ | ||
{ | ||
"dsn": "https://[email protected]/123456", | ||
"environment": "environment-from-invalid-file", | ||
"invalid-option": 123 | ||
} |
1 change: 1 addition & 0 deletions
1
packages/core/RNSentryCocoaTester/TestAssets/invalid.options.txt
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 @@ | ||
invalid-options |
4 changes: 4 additions & 0 deletions
4
packages/core/RNSentryCocoaTester/TestAssets/valid.options.json
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,4 @@ | ||
{ | ||
"dsn": "https://[email protected]/123456", | ||
"environment": "environment-from-valid-file" | ||
} |
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
Oops, something went wrong.