Skip to content

Commit 907698f

Browse files
Fix network tests
1 parent 063faf4 commit 907698f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/instabug_custom_http_client_request.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class InstabugCustomHttpClientRequest implements HttpClientRequest {
5757

5858
@override
5959
Future<HttpClientResponse> close() async {
60-
var response = await _originalClientRequest.close();
60+
final response = await _originalClientRequest.close();
6161
logger.onResponse(response, _originalClientRequest);
6262
return response;
6363
}

test/network_logger_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart';
55
import 'package:flutter/services.dart';
66
import 'package:flutter_test/flutter_test.dart';
77
import 'package:instabug_flutter/instabug_custom_http_client.dart';
8+
import 'package:instabug_flutter/instabug_custom_http_client_request.dart';
89
import 'package:instabug_flutter/utils/http_client_logger.dart';
910
import 'package:mockito/annotations.dart';
1011
import 'package:mockito/mockito.dart';
@@ -27,6 +28,7 @@ void main() {
2728
const String path = '/posts';
2829

2930
late InstabugCustomHttpClient instabugCustomHttpClient;
31+
late InstabugCustomHttpClientRequest instabugCustomHttpClientRequest;
3032
late MockHttpClientRequest mockRequest;
3133
late MockHttpClientResponse mockResponse;
3234

@@ -45,6 +47,15 @@ void main() {
4547
mockRequest = MockHttpClientRequest();
4648
mockResponse = MockHttpClientResponse();
4749

50+
when(mockRequest.bufferOutput).thenAnswer((_) => true);
51+
when(mockRequest.contentLength).thenAnswer((_) => 100);
52+
when(mockRequest.encoding).thenAnswer((_) => systemEncoding);
53+
when(mockRequest.followRedirects).thenAnswer((_) => true);
54+
when(mockRequest.maxRedirects).thenAnswer((_) => 5);
55+
when(mockRequest.persistentConnection).thenAnswer((_) => true);
56+
57+
instabugCustomHttpClientRequest = InstabugCustomHttpClientRequest(mockRequest, instabugCustomHttpClient.logger);
58+
4859
expect(mockRequest, isInstanceOf<HttpClientRequest>());
4960
expect(mockResponse, isInstanceOf<HttpClientResponse>());
5061

@@ -62,6 +73,7 @@ void main() {
6273
.thenAnswer((_) async => mockRequest);
6374

6475
await instabugCustomHttpClient.getUrl(Uri.parse(url));
76+
await instabugCustomHttpClientRequest.close();
6577

6678
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
6779
verify(
@@ -75,6 +87,7 @@ void main() {
7587
.thenAnswer((_) async => mockRequest);
7688

7789
await instabugCustomHttpClient.get(url, port, path);
90+
await instabugCustomHttpClientRequest.close();
7891

7992
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
8093
verify(
@@ -89,6 +102,7 @@ void main() {
89102
.thenAnswer((_) async => mockRequest);
90103

91104
await instabugCustomHttpClient.deleteUrl(Uri.parse(url));
105+
await instabugCustomHttpClientRequest.close();
92106

93107
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
94108
verify(
@@ -102,6 +116,7 @@ void main() {
102116
.thenAnswer((_) async => mockRequest);
103117

104118
await instabugCustomHttpClient.delete(url, port, path);
119+
await instabugCustomHttpClientRequest.close();
105120

106121
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
107122
verify(
@@ -115,6 +130,7 @@ void main() {
115130
.thenAnswer((_) async => mockRequest);
116131

117132
await instabugCustomHttpClient.postUrl(Uri.parse(url));
133+
await instabugCustomHttpClientRequest.close();
118134

119135
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
120136
verify(
@@ -128,6 +144,7 @@ void main() {
128144
.thenAnswer((_) async => mockRequest);
129145

130146
await instabugCustomHttpClient.post(url, port, path);
147+
await instabugCustomHttpClientRequest.close();
131148

132149
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
133150
verify(
@@ -141,6 +158,7 @@ void main() {
141158
.thenAnswer((_) async => mockRequest);
142159

143160
await instabugCustomHttpClient.headUrl(Uri.parse(url));
161+
await instabugCustomHttpClientRequest.close();
144162

145163
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
146164
verify(
@@ -154,6 +172,7 @@ void main() {
154172
.thenAnswer((_) async => mockRequest);
155173

156174
await instabugCustomHttpClient.head(url, port, path);
175+
await instabugCustomHttpClientRequest.close();
157176

158177
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
159178
verify(
@@ -167,6 +186,7 @@ void main() {
167186
.thenAnswer((_) async => mockRequest);
168187

169188
await instabugCustomHttpClient.patchUrl(Uri.parse(url));
189+
await instabugCustomHttpClientRequest.close();
170190

171191
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
172192
verify(
@@ -180,6 +200,7 @@ void main() {
180200
.thenAnswer((_) async => mockRequest);
181201

182202
await instabugCustomHttpClient.patch(url, port, path);
203+
await instabugCustomHttpClientRequest.close();
183204

184205
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
185206
verify(
@@ -193,6 +214,7 @@ void main() {
193214
.thenAnswer((_) async => mockRequest);
194215

195216
await instabugCustomHttpClient.openUrl('GET', Uri.parse(url));
217+
await instabugCustomHttpClientRequest.close();
196218

197219
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
198220
verify(
@@ -206,6 +228,7 @@ void main() {
206228
.thenAnswer((_) async => mockRequest);
207229

208230
await instabugCustomHttpClient.open('GET', url, port, path);
231+
await instabugCustomHttpClientRequest.close();
209232

210233
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
211234
verify(
@@ -219,6 +242,7 @@ void main() {
219242
.thenAnswer((_) async => mockRequest);
220243

221244
await instabugCustomHttpClient.putUrl(Uri.parse(url));
245+
await instabugCustomHttpClientRequest.close();
222246

223247
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
224248
verify(
@@ -232,6 +256,7 @@ void main() {
232256
.thenAnswer((_) async => mockRequest);
233257

234258
await instabugCustomHttpClient.put(url, port, path);
259+
await instabugCustomHttpClientRequest.close();
235260

236261
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
237262
verify(
@@ -245,6 +270,7 @@ void main() {
245270
.thenAnswer((_) async => mockRequest);
246271

247272
await instabugCustomHttpClient.postUrl(Uri.parse(url));
273+
await instabugCustomHttpClientRequest.close();
248274

249275
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
250276
verify(
@@ -258,6 +284,7 @@ void main() {
258284
.thenAnswer((_) async => mockRequest);
259285

260286
await instabugCustomHttpClient.post(url, port, path);
287+
await instabugCustomHttpClientRequest.close();
261288

262289
verify(instabugCustomHttpClient.logger.onRequest(mockRequest));
263290
verify(
@@ -408,6 +435,7 @@ void main() {
408435

409436
for (int i = 0; i < 10000; i++) {
410437
await instabugCustomHttpClient.getUrl(Uri.parse(url));
438+
await instabugCustomHttpClientRequest.close();
411439
}
412440

413441
verify((instabugCustomHttpClient.logger as MockHttpClientLogger)

0 commit comments

Comments
 (0)