@@ -24,7 +24,8 @@ void main() {
24
24
25
25
test ('captured span if successful request' , () async {
26
26
final sut = fixture.getSut (
27
- client: fixture.getClient (statusCode: 200 , reason: 'OK' ),
27
+ client:
28
+ fixture.getClient (statusCode: 200 , reason: 'OK' , contentLength: 2 ),
28
29
);
29
30
final tr = fixture._hub.startTransaction (
30
31
'name' ,
@@ -46,6 +47,8 @@ void main() {
46
47
expect (span.data['url' ], 'https://example.com' );
47
48
expect (span.data['http.query' ], 'foo=bar' );
48
49
expect (span.data['http.fragment' ], 'baz' );
50
+ expect (span.data['http.response.status_code' ], 200 );
51
+ expect (span.data['http.response_content_length' ], 2 );
49
52
});
50
53
51
54
test ('finish span if errored request' , () async {
@@ -175,16 +178,27 @@ class Fixture {
175
178
return dio;
176
179
}
177
180
178
- MockHttpClientAdapter getClient ({int statusCode = 200 , String ? reason}) {
181
+ MockHttpClientAdapter getClient ({
182
+ int statusCode = 200 ,
183
+ String ? reason,
184
+ int ? contentLength,
185
+ }) {
179
186
return MockHttpClientAdapter ((options, requestStream, cancelFuture) async {
180
187
expect (options.uri, requestUri);
188
+
189
+ final headers = options.headers.map (
190
+ (key, dynamic value) =>
191
+ MapEntry (key, < String > [value? .toString () ?? '' ]),
192
+ );
193
+
194
+ if (contentLength != null ) {
195
+ headers['Content-Length' ] = [contentLength.toString ()];
196
+ }
197
+
181
198
return ResponseBody .fromString (
182
- '' ,
199
+ '{} ' ,
183
200
statusCode,
184
- headers: options.headers.map (
185
- (key, dynamic value) =>
186
- MapEntry (key, < String > [value? .toString () ?? '' ]),
187
- ),
201
+ headers: headers,
188
202
);
189
203
});
190
204
}
0 commit comments