-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ dependencies: | |
|
||
dev_dependencies: | ||
lints: any | ||
test: any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:http/http.dart'; | ||
|
||
class CloseClientMock implements Client { | ||
bool closeWasCalled = false; | ||
|
||
@override | ||
void close() { | ||
closeWasCalled = true; | ||
} | ||
|
||
@override | ||
void noSuchMethod(Invocation invocation) { | ||
throw UnimplementedError(); | ||
} | ||
} | ||
|
||
class ClientMock implements Client { | ||
StreamedResponse? response; | ||
|
||
BaseRequest? request; | ||
|
||
@override | ||
Future<StreamedResponse> send(BaseRequest request) async { | ||
this.request = request; | ||
return response!; | ||
} | ||
|
||
@override | ||
void noSuchMethod(Invocation invocation) { | ||
throw UnimplementedError(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
plugins/http_compatibility_layer/test/conversion_layer_adapter_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:dio_http_compatibility_layer/dio_http_compatibility_layer.dart'; | ||
import 'package:http/http.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
import 'client_mock.dart'; | ||
|
||
void main() { | ||
test('close', () { | ||
final mock = CloseClientMock(); | ||
final cla = ConversionLayerAdapter(mock); | ||
|
||
cla.close(); | ||
|
||
expect(mock.closeWasCalled, true); | ||
}); | ||
|
||
test('close with force', () { | ||
final mock = CloseClientMock(); | ||
final cla = ConversionLayerAdapter(mock); | ||
|
||
cla.close(force: true); | ||
|
||
expect(mock.closeWasCalled, true); | ||
}); | ||
|
||
test('headers', () async { | ||
final mock = ClientMock()..response = StreamedResponse(Stream.empty(), 200); | ||
final cla = ConversionLayerAdapter(mock); | ||
|
||
await cla.fetch( | ||
RequestOptions(path: '', headers: {'foo': 'bar'}), | ||
Stream.empty(), | ||
null, | ||
); | ||
|
||
expect(mock.request?.headers, {'foo': 'bar'}); | ||
}); | ||
|
||
test('download stream', () async { | ||
final mock = ClientMock() | ||
..response = StreamedResponse( | ||
Stream.fromIterable(<Uint8List>[ | ||
Uint8List.fromList([10, 1]), | ||
Uint8List.fromList([1, 4]), | ||
Uint8List.fromList([5, 1]), | ||
Uint8List.fromList([1, 1]), | ||
Uint8List.fromList([2, 4]), | ||
]), | ||
200); | ||
final cla = ConversionLayerAdapter(mock); | ||
|
||
final resp = await cla.fetch( | ||
RequestOptions(path: ''), | ||
null, | ||
null, | ||
); | ||
|
||
expect(await resp.stream.length, 5); | ||
}); | ||
} |