|
2 | 2 | // The lint above is okay, because we're using another Sentry package
|
3 | 3 | import 'dart:convert';
|
4 | 4 | import 'dart:typed_data';
|
| 5 | +import 'dart:ui'; |
5 | 6 |
|
6 | 7 | import 'package:flutter/services.dart';
|
7 | 8 | import 'package:flutter_test/flutter_test.dart';
|
@@ -137,6 +138,53 @@ void main() {
|
137 | 138 | expect(span.context.description, 'AssetBundle.loadString: test.txt');
|
138 | 139 | });
|
139 | 140 |
|
| 141 | + test('loadBuffer: creates a span if transaction is bound to scope', |
| 142 | + () async { |
| 143 | + final sut = fixture.getSut(); |
| 144 | + final tr = fixture._hub.startTransaction( |
| 145 | + 'name', |
| 146 | + 'op', |
| 147 | + bindToScope: true, |
| 148 | + ); |
| 149 | + |
| 150 | + await sut.loadBuffer(_testFileName); |
| 151 | + |
| 152 | + await tr.finish(); |
| 153 | + |
| 154 | + final tracer = (tr as SentryTracer); |
| 155 | + final span = tracer.children.first; |
| 156 | + |
| 157 | + expect(span.status, SpanStatus.ok()); |
| 158 | + expect(span.finished, true); |
| 159 | + expect(span.context.operation, 'file.read'); |
| 160 | + expect(span.data['file.path'], 'resources/test.txt'); |
| 161 | + expect(span.data['file.size'], 12); |
| 162 | + expect(span.context.description, 'AssetBundle.loadBuffer: test.txt'); |
| 163 | + }); |
| 164 | + |
| 165 | + test('loadBuffer: end span with error if exception is thrown', () async { |
| 166 | + final sut = fixture.getSut(throwException: true); |
| 167 | + final tr = fixture._hub.startTransaction( |
| 168 | + 'name', |
| 169 | + 'op', |
| 170 | + bindToScope: true, |
| 171 | + ); |
| 172 | + |
| 173 | + try { |
| 174 | + await sut.loadBuffer(_testFileName); |
| 175 | + } catch (_) {} |
| 176 | + |
| 177 | + await tr.finish(); |
| 178 | + |
| 179 | + final tracer = (tr as SentryTracer); |
| 180 | + final span = tracer.children.first; |
| 181 | + |
| 182 | + expect(span.status, SpanStatus.internalError()); |
| 183 | + expect(span.finished, true); |
| 184 | + expect(span.context.operation, 'file.read'); |
| 185 | + expect(span.context.description, 'AssetBundle.loadBuffer: test.txt'); |
| 186 | + }); |
| 187 | + |
140 | 188 | test(
|
141 | 189 | 'loadStructuredData: does not create any spans and just forwords the call to the underlying assetbundle if disabled',
|
142 | 190 | () async {
|
@@ -359,4 +407,18 @@ class TestAssetBundle extends CachingAssetBundle {
|
359 | 407 | super.evict(key);
|
360 | 408 | evictKey = key;
|
361 | 409 | }
|
| 410 | + |
| 411 | + @override |
| 412 | + // This is an override on Flutter greater than 3.1 |
| 413 | + // ignore: override_on_non_overriding_member |
| 414 | + Future<ImmutableBuffer> loadBuffer(String key) async { |
| 415 | + if (throwException) { |
| 416 | + throw Exception('exception thrown for testing purposes'); |
| 417 | + } |
| 418 | + if (key == _testFileName) { |
| 419 | + return ImmutableBuffer.fromUint8List( |
| 420 | + Uint8List.fromList(utf8.encode('Hello World!'))); |
| 421 | + } |
| 422 | + return ImmutableBuffer.fromUint8List(Uint8List.fromList([])); |
| 423 | + } |
362 | 424 | }
|
0 commit comments