-
-
Notifications
You must be signed in to change notification settings - Fork 277
loadContextsIntegration tests #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1b5c498
add a loadContextsIntegration test
rxlabz fc06571
add an iOSPlatformChecker param to SentryFlutter.init
rxlabz d8cdbc0
more loadContextsIntegration tests
rxlabz f93812f
changelog
rxlabz 05507c9
minor
rxlabz 0376e46
minor
rxlabz 9d5f84f
remove mock doublon
rxlabz 10e2615
minor test refacto
rxlabz bc897d3
add tests : loadContextsIntegration is added only on ios
rxlabz 3f38da6
remove useless import
rxlabz 533b457
add a isWeb param to sentry_flutter_test
rxlabz 1bb5ddf
minor
rxlabz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| ## 4.0.0-alpha.3 (Next) | ||
|
|
||
| - Development. | ||
| - add loadContextsIntegration tests | ||
|
|
||
| ## 4.0.0-alpha.2 | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,146 @@ | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import 'package:mockito/mockito.dart'; | ||
| import 'package:sentry/sentry.dart'; | ||
| import 'package:sentry_flutter/sentry_flutter.dart'; | ||
|
|
||
| import 'mocks.dart'; | ||
|
|
||
| class MockTransport extends Mock implements Transport {} | ||
marandaneto marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| void main() { | ||
| const MethodChannel _channel = MethodChannel('sentry_flutter'); | ||
|
|
||
| TestWidgetsFlutterBinding.ensureInitialized(); | ||
|
|
||
| bool called = false; | ||
|
|
||
| setUp(() { | ||
| _channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
| called = true; | ||
| return { | ||
| 'integrations': ['NativeIntegration'], | ||
| 'package': {'sdk_name': 'native-package', 'version': '1.0'}, | ||
| 'contexts': { | ||
| 'device': {'name': 'Device1'}, | ||
| 'app': {'app_name': 'test-app'}, | ||
| 'os': {'name': 'os1'}, | ||
| 'gpu': {'name': 'gpu1'}, | ||
| 'browser': {'name': 'browser1'}, | ||
| 'runtime': {'name': 'RT1'}, | ||
| 'theme': 'material', | ||
| } | ||
| }; | ||
| }); | ||
| }); | ||
|
|
||
| tearDown(() { | ||
| _channel.setMockMethodCallHandler(null); | ||
| }); | ||
|
|
||
| test('should apply the loadContextsIntegration eventProcessor', () async { | ||
| final options = SentryOptions()..dsn = fakeDsn; | ||
| final hub = Hub(options); | ||
|
|
||
| loadContextsIntegration(options, _channel)(hub, options); | ||
|
|
||
| expect(options.eventProcessors.length, 1); | ||
|
|
||
| final e = SentryEvent(); | ||
| final event = await options.eventProcessors.first(e, null); | ||
|
|
||
| expect(called, true); | ||
| expect(event.contexts.device.name, 'Device1'); | ||
| expect(event.contexts.app.name, 'test-app'); | ||
| expect(event.contexts.operatingSystem.name, 'os1'); | ||
| expect(event.contexts.gpu.name, 'gpu1'); | ||
| expect(event.contexts.browser.name, 'browser1'); | ||
| expect( | ||
| event.contexts.runtimes.any((element) => element.name == 'RT1'), true); | ||
| expect(event.contexts['theme'], 'material'); | ||
| expect( | ||
| event.sdk.packages.any((element) => element.name == 'native-package'), | ||
| true, | ||
| ); | ||
| expect(event.sdk.integrations.contains('NativeIntegration'), true); | ||
| }); | ||
|
|
||
| test( | ||
| 'should not override event contexts with the loadContextsIntegration infos', | ||
| () async { | ||
| final options = SentryOptions()..dsn = fakeDsn; | ||
| final hub = Hub(options); | ||
|
|
||
| loadContextsIntegration(options, _channel)(hub, options); | ||
|
|
||
| expect(options.eventProcessors.length, 1); | ||
|
|
||
| final eventContexts = Contexts( | ||
| device: const Device(name: 'eDevice'), | ||
| app: const App(name: 'eApp'), | ||
| operatingSystem: const OperatingSystem(name: 'eOS'), | ||
| gpu: const Gpu(name: 'eGpu'), | ||
| browser: const Browser(name: 'eBrowser'), | ||
| runtimes: [const SentryRuntime(name: 'eRT')]) | ||
| ..['theme'] = 'cuppertino'; | ||
| final e = SentryEvent(contexts: eventContexts); | ||
| final event = await options.eventProcessors.first(e, null); | ||
|
|
||
| expect(called, true); | ||
| expect(event.contexts.device.name, 'eDevice'); | ||
| expect(event.contexts.app.name, 'eApp'); | ||
| expect(event.contexts.operatingSystem.name, 'eOS'); | ||
| expect(event.contexts.gpu.name, 'eGpu'); | ||
| expect(event.contexts.browser.name, 'eBrowser'); | ||
| expect( | ||
| event.contexts.runtimes.any((element) => element.name == 'RT1'), true); | ||
| expect( | ||
| event.contexts.runtimes.any((element) => element.name == 'eRT'), true); | ||
| expect(event.contexts['theme'], 'cuppertino'); | ||
| }); | ||
|
|
||
| test( | ||
| 'should merge event and loadContextsIntegration sdk packages and integration', | ||
| () async { | ||
| final options = SentryOptions()..dsn = fakeDsn; | ||
| final hub = Hub(options); | ||
|
|
||
| loadContextsIntegration(options, _channel)(hub, options); | ||
|
|
||
| final eventSdk = SdkVersion( | ||
| name: 'sdk1', | ||
| version: '1.0', | ||
| integrations: ['EventIntegration'], | ||
| packages: [const SentryPackage('event-package', '2.0')], | ||
| ); | ||
| final e = SentryEvent(sdk: eventSdk); | ||
| final event = await options.eventProcessors.first(e, null); | ||
|
|
||
| expect( | ||
| event.sdk.packages.any((element) => element.name == 'native-package'), | ||
| true, | ||
| ); | ||
| expect( | ||
| event.sdk.packages.any((element) => element.name == 'event-package'), | ||
| true, | ||
| ); | ||
| expect(event.sdk.integrations.contains('NativeIntegration'), true); | ||
| expect(event.sdk.integrations.contains('EventIntegration'), true); | ||
| }, | ||
| ); | ||
|
|
||
| test('should not throw on loadContextsIntegration exception', () async { | ||
| _channel.setMockMethodCallHandler((MethodCall methodCall) async { | ||
| throw null; | ||
| }); | ||
| final options = SentryOptions()..dsn = fakeDsn; | ||
| final hub = Hub(options); | ||
|
|
||
| loadContextsIntegration(options, _channel)(hub, options); | ||
|
|
||
| final e = SentryEvent(); | ||
| final event = await options.eventProcessors.first(e, null); | ||
|
|
||
| expect(event, isNotNull); | ||
| }); | ||
| } | ||
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.