|
1 | 1 | import 'dart:async'; |
2 | 2 | import 'dart:convert'; |
| 3 | +import 'dart:typed_data'; |
3 | 4 |
|
4 | 5 | import 'package:sentry/sentry.dart'; |
| 6 | +import 'package:sentry/src/sentry_item_type.dart'; |
5 | 7 | import 'package:sentry/src/sentry_stack_trace_factory.dart'; |
6 | 8 | import 'package:sentry/src/sentry_tracer.dart'; |
7 | 9 | import 'package:test/test.dart'; |
@@ -347,6 +349,64 @@ void main() { |
347 | 349 | expect(capturedEvent['exception'], isNull); |
348 | 350 | }); |
349 | 351 |
|
| 352 | + test('attachments not added to captured transaction per default', () async { |
| 353 | + final attachment = SentryAttachment.fromUint8List( |
| 354 | + Uint8List.fromList([0, 0, 0, 0]), |
| 355 | + 'test.txt', |
| 356 | + ); |
| 357 | + final scope = Scope(fixture.options); |
| 358 | + scope.addAttachment(attachment); |
| 359 | + |
| 360 | + final client = fixture.getSut(); |
| 361 | + final tr = SentryTransaction(fixture.tracer); |
| 362 | + await client.captureTransaction(tr, scope: scope); |
| 363 | + |
| 364 | + final capturedEnvelope = (fixture.transport).envelopes.first; |
| 365 | + final capturedAttachments = capturedEnvelope.items |
| 366 | + .where((item) => item.header.type == SentryItemType.attachment); |
| 367 | + |
| 368 | + expect(capturedAttachments.isEmpty, true); |
| 369 | + }); |
| 370 | + |
| 371 | + test('attachments added to captured event', () async { |
| 372 | + final attachment = SentryAttachment.fromUint8List( |
| 373 | + Uint8List.fromList([0, 0, 0, 0]), |
| 374 | + 'test.txt', |
| 375 | + addToTransactions: true, |
| 376 | + ); |
| 377 | + final scope = Scope(fixture.options); |
| 378 | + scope.addAttachment(attachment); |
| 379 | + |
| 380 | + final client = fixture.getSut(); |
| 381 | + final tr = SentryTransaction(fixture.tracer); |
| 382 | + await client.captureTransaction(tr, scope: scope); |
| 383 | + |
| 384 | + final capturedEnvelope = (fixture.transport).envelopes.first; |
| 385 | + final capturedAttachments = capturedEnvelope.items |
| 386 | + .where((item) => item.header.type == SentryItemType.attachment); |
| 387 | + |
| 388 | + expect(capturedAttachments.isNotEmpty, true); |
| 389 | + }); |
| 390 | + |
| 391 | + test('attachments added to captured event per default', () async { |
| 392 | + final attachment = SentryAttachment.fromUint8List( |
| 393 | + Uint8List.fromList([0, 0, 0, 0]), |
| 394 | + 'test.txt', |
| 395 | + ); |
| 396 | + final scope = Scope(fixture.options); |
| 397 | + scope.addAttachment(attachment); |
| 398 | + |
| 399 | + final client = fixture.getSut(); |
| 400 | + final event = SentryEvent(); |
| 401 | + await client.captureEvent(event, scope: scope); |
| 402 | + |
| 403 | + final capturedEnvelope = (fixture.transport).envelopes.first; |
| 404 | + final capturedAttachments = capturedEnvelope.items |
| 405 | + .where((item) => item.header.type == SentryItemType.attachment); |
| 406 | + |
| 407 | + expect(capturedAttachments.isNotEmpty, true); |
| 408 | + }); |
| 409 | + |
350 | 410 | test('should return empty for when transaction is discarded', () async { |
351 | 411 | final client = fixture.getSut(eventProcessor: DropAllEventProcessor()); |
352 | 412 | final tr = SentryTransaction(fixture.tracer); |
|
0 commit comments