|
| 1 | +import 'dart:io'; |
| 2 | + |
| 3 | +import 'package:sentry/sentry.dart'; |
| 4 | +import 'package:sentry_file/sentry_file.dart'; |
| 5 | +import 'package:test/expect.dart'; |
| 6 | +import 'package:test/scaffolding.dart'; |
| 7 | + |
| 8 | +import 'mock_sentry_client.dart'; |
| 9 | + |
| 10 | +void main() { |
| 11 | + late IOOverrides? current; |
| 12 | + late Fixture fixture; |
| 13 | + |
| 14 | + setUp(() { |
| 15 | + current = IOOverrides.current; |
| 16 | + fixture = Fixture(); |
| 17 | + }); |
| 18 | + |
| 19 | + tearDown(() { |
| 20 | + IOOverrides.global = current; |
| 21 | + }); |
| 22 | + |
| 23 | + test('adding integration installs io overrides', () { |
| 24 | + fixture.options.tracesSampleRate = 1.0; |
| 25 | + |
| 26 | + final sut = fixture.getSut(); |
| 27 | + sut.call(fixture.hub, fixture.options); |
| 28 | + |
| 29 | + expect( |
| 30 | + fixture.options.sdk.integrations.contains('sentryIOOverridesIntegration'), |
| 31 | + isTrue, |
| 32 | + ); |
| 33 | + expect(IOOverrides.current is SentryIOOverrides, isTrue); |
| 34 | + }); |
| 35 | + |
| 36 | + test('not installed when tracing disabled', () { |
| 37 | + final sut = fixture.getSut(); |
| 38 | + sut.call(fixture.hub, fixture.options); |
| 39 | + |
| 40 | + expect( |
| 41 | + fixture.options.sdk.integrations.contains('sentryIOOverridesIntegration'), |
| 42 | + isFalse, |
| 43 | + ); |
| 44 | + expect(IOOverrides.current is SentryIOOverrides, isFalse); |
| 45 | + }); |
| 46 | + |
| 47 | + test('global overrides restored', () { |
| 48 | + final previous = IOOverrides.current; |
| 49 | + |
| 50 | + fixture.options.tracesSampleRate = 1.0; |
| 51 | + |
| 52 | + final sut = fixture.getSut(); |
| 53 | + sut.call(fixture.hub, fixture.options); |
| 54 | + sut.close(); |
| 55 | + |
| 56 | + expect(IOOverrides.current, previous); |
| 57 | + }); |
| 58 | + |
| 59 | + test('files created are sentry file after adding integration', () { |
| 60 | + fixture.options.tracesSampleRate = 1.0; |
| 61 | + |
| 62 | + final sut = fixture.getSut(); |
| 63 | + sut.call(fixture.hub, fixture.options); |
| 64 | + |
| 65 | + final file = File("/home"); |
| 66 | + expect(file is SentryFile, true); |
| 67 | + }); |
| 68 | +} |
| 69 | + |
| 70 | +class Fixture { |
| 71 | + final options = SentryOptions(dsn: fakeDsn); |
| 72 | + late final hub = Hub(options); |
| 73 | + |
| 74 | + SentryIOOverridesIntegration getSut() { |
| 75 | + return SentryIOOverridesIntegration(); |
| 76 | + } |
| 77 | +} |
0 commit comments