Skip to content

Commit

Permalink
test: use options.automatedTestMode everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Sep 13, 2024
1 parent d0971e0 commit ac151ad
Show file tree
Hide file tree
Showing 103 changed files with 319 additions and 305 deletions.
4 changes: 2 additions & 2 deletions dart/test/debug_image_extractor_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:test/test.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry/src/debug_image_extractor.dart';

import 'mocks/mock_platform.dart';
import 'mocks/mock_platform_checker.dart';
import 'test_utils.dart';

void main() {
group(DebugImageExtractor, () {
Expand Down Expand Up @@ -112,7 +112,7 @@ isolate_dso_base: 10000000

class Fixture {
DebugImageExtractor getSut({required MockPlatform platform}) {
final options = SentryOptions(dsn: 'https://public@sentry.example.com/1')
final options = defaultTestOptions()
..platformChecker = MockPlatformChecker(platform: platform);
return DebugImageExtractor(options);
}
Expand Down
4 changes: 3 additions & 1 deletion dart/test/diagnostic_logger_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'package:sentry/sentry.dart';
import 'package:sentry/src/diagnostic_logger.dart';
import 'package:test/test.dart';

import 'test_utils.dart';

void main() {
late Fixture fixture;

Expand Down Expand Up @@ -44,7 +46,7 @@ void main() {
}

class Fixture {
var options = SentryOptions();
var options = defaultTestOptions();

Object? loggedMessage;

Expand Down
7 changes: 3 additions & 4 deletions dart/test/environment_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:test/test.dart';

import 'mocks.dart';
import 'mocks/mock_environment_variables.dart';
import 'test_utils.dart';

void main() {
// See https://docs.sentry.io/platforms/dart/configuration/options/
Expand All @@ -13,7 +14,7 @@ void main() {
});

test('SentryOptions are not overriden by environment', () async {
final options = SentryOptions(dsn: fakeDsn);
final options = defaultTestOptions();
options.release = 'release-1.2.3';
options.dist = 'foo';
options.environment = 'prod';
Expand All @@ -23,7 +24,6 @@ void main() {
release: 'release-9.8.7',
dist: 'bar',
);
options.automatedTestMode = true;

await Sentry.init(
(options) => options,
Expand All @@ -37,14 +37,13 @@ void main() {
});

test('SentryOptions are overriden by environment', () async {
final options = SentryOptions();
final options = defaultTestOptions();
options.environmentVariables = MockEnvironmentVariables(
dsn: fakeDsn,
environment: 'staging',
release: 'release-9.8.7',
dist: 'bar',
);
options.automatedTestMode = true;

await Sentry.init(
(options) => options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:test/test.dart';
import '../mocks.dart';
import '../mocks/mock_hub.dart';
import '../mocks/mock_transport.dart';
import '../test_utils.dart';

void main() {
group('$DeduplicationEventProcessor', () {
Expand Down Expand Up @@ -77,14 +78,13 @@ void main() {

final transport = MockTransport();

final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true;
await Sentry.init(
(options) {
options.dsn = fakeDsn;
options.transport = transport;
options.enableDeduplication = true;
},
options: options,
options: defaultTestOptions(),
);

// The test doesn't work if `outerTestMethod` is passed as
Expand Down Expand Up @@ -114,7 +114,7 @@ class Fixture {

DeduplicationEventProcessor getSut(bool enabled,
[int? maxDeduplicationItems]) {
final options = SentryOptions(dsn: fakeDsn)
final options = defaultTestOptions()
..enableDeduplication = enabled
..maxDeduplicationItems = maxDeduplicationItems ?? 5;

Expand Down
17 changes: 7 additions & 10 deletions dart/test/event_processor/enricher/io_enricher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:test/test.dart';

import '../../mocks.dart';
import '../../mocks/mock_platform_checker.dart';
import '../../test_utils.dart';

void main() {
group('io_enricher', () {
Expand Down Expand Up @@ -164,20 +165,17 @@ void main() {
});

test('$IoEnricherEventProcessor gets added on init', () async {
final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true;
late SentryOptions configuredOptions;
final options = defaultTestOptions();
await Sentry.init(
(options) {
options.dsn = fakeDsn;
configuredOptions = options;
},
options: options,
);
await Sentry.close();

final ioEnricherCount = configuredOptions.eventProcessors
.whereType<IoEnricherEventProcessor>()
.length;
final ioEnricherCount =
options.eventProcessors.whereType<IoEnricherEventProcessor>().length;
expect(ioEnricherCount, 1);
});
});
Expand All @@ -188,10 +186,9 @@ class Fixture {
bool hasNativeIntegration = false,
bool includePii = false,
}) {
final options = SentryOptions(
dsn: fakeDsn,
checker:
MockPlatformChecker(hasNativeIntegration: hasNativeIntegration))
final options = defaultTestOptions()
..platformChecker =
MockPlatformChecker(hasNativeIntegration: hasNativeIntegration)
..sendDefaultPii = includePii;

return IoEnricherEventProcessor(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ library dart_test;

import 'dart:io';

import 'package:sentry/sentry.dart';
import 'package:sentry/src/event_processor/enricher/io_platform_memory.dart';
import 'package:test/test.dart';

import '../../test_utils.dart';

void main() {
late Fixture fixture;

Expand Down Expand Up @@ -52,7 +53,7 @@ void main() {
}

class Fixture {
var options = SentryOptions();
var options = defaultTestOptions();

PlatformMemory getSut() {
return PlatformMemory(options);
Expand Down
6 changes: 3 additions & 3 deletions dart/test/event_processor/enricher/web_enricher_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:test/test.dart';

import '../../mocks.dart';
import '../../mocks/mock_platform_checker.dart';
import '../../test_utils.dart';

// can be tested on command line with
// `dart test -p chrome --name web_enricher`
Expand Down Expand Up @@ -201,9 +202,8 @@ void main() {

class Fixture {
WebEnricherEventProcessor getSut() {
final options = SentryOptions(
dsn: fakeDsn,
checker: MockPlatformChecker(hasNativeIntegration: false));
final options = defaultTestOptions()
..platformChecker = MockPlatformChecker(hasNativeIntegration: false);
return enricherEventProcessor(options) as WebEnricherEventProcessor;
}
}
4 changes: 2 additions & 2 deletions dart/test/exception_identifier_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import 'package:sentry/src/dart_exception_type_identifier.dart';
import 'package:sentry/src/sentry_exception_factory.dart';
import 'package:test/test.dart';

import 'mocks.dart';
import 'mocks.mocks.dart';
import 'mocks/mock_transport.dart';
import 'sentry_client_test.dart';
import 'test_utils.dart';

void main() {
late Fixture fixture;
Expand Down Expand Up @@ -165,7 +165,7 @@ void main() {
}

class Fixture {
SentryOptions options = SentryOptions(dsn: fakeDsn);
SentryOptions options = defaultTestOptions();
}

// We use this PlaceHolder exception to mimic an obfuscated runtimeType
Expand Down
3 changes: 2 additions & 1 deletion dart/test/http_client/failed_request_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:test/test.dart';
import '../mocks.dart';
import '../mocks/mock_hub.dart';
import '../mocks/mock_transport.dart';
import '../test_utils.dart';

final requestUri = Uri.parse('https://example.com?foo=bar#myFragment');

Expand Down Expand Up @@ -359,7 +360,7 @@ MockClient createThrowingClient() {
class CloseableMockClient extends Mock implements BaseClient {}

class Fixture {
final options = SentryOptions(dsn: fakeDsn);
final options = defaultTestOptions();
late Hub _hub;
final transport = MockTransport();
Fixture() {
Expand Down
4 changes: 2 additions & 2 deletions dart/test/http_client/io_client_provider_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:sentry/sentry.dart';
import 'package:sentry/src/http_client/io_client_provider.dart';
import 'package:test/test.dart';

import '../mocks.dart';
import '../test_utils.dart';

void main() {
group('getClient', () {
Expand Down Expand Up @@ -77,7 +77,7 @@ void main() {
}

class Fixture {
final options = SentryOptions(dsn: fakeDsn);
final options = defaultTestOptions();
final mockHttpClient = MockHttpClient();

String? mockUser;
Expand Down
4 changes: 2 additions & 2 deletions dart/test/http_client/tracing_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:sentry/src/http_client/tracing_client.dart';
import 'package:sentry/src/sentry_tracer.dart';
import 'package:test/test.dart';

import '../mocks.dart';
import '../mocks/mock_transport.dart';
import '../test_utils.dart';

final requestUri = Uri.parse('https://example.com?foo=bar#baz');

Expand Down Expand Up @@ -220,7 +220,7 @@ MockClient createThrowingClient() {
}

class Fixture {
final _options = SentryOptions(dsn: fakeDsn);
final _options = defaultTestOptions();
late Hub _hub;
final transport = MockTransport();
Fixture() {
Expand Down
15 changes: 8 additions & 7 deletions dart/test/hub_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'mocks.dart';
import 'mocks.mocks.dart';
import 'mocks/mock_client_report_recorder.dart';
import 'mocks/mock_sentry_client.dart';
import 'test_utils.dart';

void main() {
bool scopeEquals(Scope? a, Scope b) {
Expand All @@ -25,7 +26,7 @@ void main() {

group('Hub instantiation', () {
test('should instantiate with a dsn', () {
final hub = Hub(SentryOptions(dsn: fakeDsn));
final hub = Hub(defaultTestOptions());
expect(hub.isEnabled, true);
});
});
Expand Down Expand Up @@ -458,11 +459,11 @@ void main() {
});

group('Hub scope', () {
var hub = Hub(SentryOptions(dsn: fakeDsn));
var hub = Hub(defaultTestOptions());
var client = MockSentryClient();

setUp(() {
hub = Hub(SentryOptions(dsn: fakeDsn));
hub = Hub(defaultTestOptions());
client = MockSentryClient();
hub.bindClient(client);
});
Expand All @@ -487,7 +488,7 @@ void main() {
expect(client.captureEventCalls.first.scope, isNotNull);
final scope = client.captureEventCalls.first.scope;

final otherScope = Scope(SentryOptions(dsn: fakeDsn))
final otherScope = Scope(defaultTestOptions())
..level = SentryLevel.debug
..fingerprint = ['1', '2'];

Expand All @@ -511,7 +512,7 @@ void main() {
await hub.captureEvent(fakeEvent);

final scope = client.captureEventCalls.first.scope;
final otherScope = Scope(SentryOptions(dsn: fakeDsn));
final otherScope = Scope(defaultTestOptions());
await otherScope.setUser(fakeUser);

expect(
Expand Down Expand Up @@ -593,7 +594,7 @@ void main() {
SentryOptions options;

setUp(() {
options = SentryOptions(dsn: fakeDsn);
options = defaultTestOptions();
hub = Hub(options);
client = MockSentryClient();
hub.bindClient(client);
Expand Down Expand Up @@ -756,7 +757,7 @@ class Fixture {
final client = MockSentryClient();
final recorder = MockClientReportRecorder();

final options = SentryOptions(dsn: fakeDsn);
final options = defaultTestOptions();
late SentryTransactionContext _context;
late SentryTracer tracer;

Expand Down
5 changes: 3 additions & 2 deletions dart/test/initialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:sentry/sentry.dart';
import 'package:test/test.dart';

import 'mocks.dart';
import 'test_utils.dart';

// Tests for the following issue
// https://github.com/getsentry/sentry-dart/issues/508
Expand All @@ -15,7 +16,7 @@ void main() {
});

test('async re-initilization', () async {
final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true;
final options = defaultTestOptions();
await Sentry.init(
(options) {
options.dsn = fakeDsn;
Expand All @@ -36,7 +37,7 @@ void main() {
// This is the failure from
// https://github.com/getsentry/sentry-dart/issues/508
test('re-initilization', () async {
final options = SentryOptions(dsn: fakeDsn)..automatedTestMode = true;
final options = defaultTestOptions();
await Sentry.init(
(options) {
options.dsn = fakeDsn;
Expand Down
3 changes: 2 additions & 1 deletion dart/test/load_dart_debug_images_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:test/test.dart';

import 'mocks/mock_platform.dart';
import 'mocks/mock_platform_checker.dart';
import 'test_utils.dart';

void main() {
group(LoadDartDebugImagesIntegration, () {
Expand Down Expand Up @@ -92,7 +93,7 @@ isolate_dso_base: 10000000
}

class Fixture {
final options = SentryOptions(dsn: 'https://public@sentry.example.com/1');
final options = defaultTestOptions();

Fixture() {
final integration = LoadDartDebugImagesIntegration();
Expand Down
Loading

0 comments on commit ac151ad

Please sign in to comment.