|
| 1 | +import 'package:sentry/sentry.dart'; |
| 2 | +import 'package:sentry/src/diagnostic_logger.dart'; |
| 3 | +import 'package:test/test.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + late Fixture fixture; |
| 7 | + |
| 8 | + setUp(() { |
| 9 | + fixture = Fixture(); |
| 10 | + }); |
| 11 | + |
| 12 | + test('$DiagnosticLogger do not log if debug is disabled', () { |
| 13 | + fixture.options.debug = false; |
| 14 | + |
| 15 | + fixture.getSut().log(SentryLevel.error, 'foobar'); |
| 16 | + |
| 17 | + expect(fixture.loggedMessage, isNull); |
| 18 | + }); |
| 19 | + |
| 20 | + test('$DiagnosticLogger log if debug is enabled', () { |
| 21 | + fixture.options.debug = true; |
| 22 | + |
| 23 | + fixture.getSut().log(SentryLevel.error, 'foobar'); |
| 24 | + |
| 25 | + expect(fixture.loggedMessage, 'foobar'); |
| 26 | + }); |
| 27 | + |
| 28 | + test('$DiagnosticLogger do not log if level is too low', () { |
| 29 | + fixture.options.debug = true; |
| 30 | + fixture.options.diagnosticLevel = SentryLevel.error; |
| 31 | + |
| 32 | + fixture.getSut().log(SentryLevel.warning, 'foobar'); |
| 33 | + |
| 34 | + expect(fixture.loggedMessage, isNull); |
| 35 | + }); |
| 36 | + |
| 37 | + test('$DiagnosticLogger always log fatal', () { |
| 38 | + fixture.options.debug = false; |
| 39 | + |
| 40 | + fixture.getSut().log(SentryLevel.fatal, 'foobar'); |
| 41 | + |
| 42 | + expect(fixture.loggedMessage, 'foobar'); |
| 43 | + }); |
| 44 | +} |
| 45 | + |
| 46 | +class Fixture { |
| 47 | + var options = SentryOptions(); |
| 48 | + |
| 49 | + Object? loggedMessage; |
| 50 | + |
| 51 | + DiagnosticLogger getSut() { |
| 52 | + return DiagnosticLogger(mockLogger, options); |
| 53 | + } |
| 54 | + |
| 55 | + void mockLogger( |
| 56 | + SentryLevel level, |
| 57 | + String message, { |
| 58 | + String? logger, |
| 59 | + Object? exception, |
| 60 | + StackTrace? stackTrace, |
| 61 | + }) { |
| 62 | + loggedMessage = message; |
| 63 | + } |
| 64 | +} |
0 commit comments