-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* move some tests from http2/dio to shared test project * add some new tests for `validateStatus` * wrap `SocketException` in `DioExceptionType.connectionError` instead of `DioExceptionType.unknown` in the `Http2Adapter` -> this brings the behavior in line with the default adapters <!-- Write down your pull request descriptions. --> ### New Pull Request Checklist - [ ] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [ ] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [ ] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [ ] I have added the required tests to prove the fix/feature I'm adding - [ ] I have updated the documentation (if necessary) - [ ] I have run the tests without failures - [ ] I have updated the `CHANGELOG.md` in the corresponding package ### Additional context and info (if any) <!-- Provide more context and info about the PR. -->
- Loading branch information
Showing
18 changed files
with
510 additions
and
531 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
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
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
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
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,81 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:dio/dio.dart'; | ||
import 'package:dio_test/util.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void basicTests( | ||
Dio Function(String baseUrl) create, | ||
) { | ||
late Dio dio; | ||
|
||
setUp(() { | ||
dio = create(httpbunBaseUrl); | ||
}); | ||
|
||
group('basic request', () { | ||
test( | ||
'works with non-TLS requests', | ||
() async { | ||
await dio.get('http://flutter.cn/'); | ||
await dio.get('https://flutter.cn/non-exist-destination'); | ||
}, | ||
testOn: 'vm', | ||
); | ||
|
||
test('fails with an invalid HTTP URL', () { | ||
expectLater( | ||
dio.get('http://does.not.exist'), | ||
throwsDioException( | ||
DioExceptionType.connectionError, | ||
matcher: kIsWeb | ||
? null | ||
: isA<DioException>().having( | ||
(e) => e.error, | ||
'inner exception', | ||
isA<SocketException>(), | ||
), | ||
), | ||
); | ||
}); | ||
|
||
test('fails with an invalid HTTPS URL', () { | ||
expectLater( | ||
dio.get('https://does.not.exist'), | ||
throwsDioException( | ||
DioExceptionType.connectionError, | ||
matcher: kIsWeb | ||
? null | ||
: isA<DioException>().having( | ||
(e) => e.error, | ||
'inner exception', | ||
isA<SocketException>(), | ||
), | ||
), | ||
); | ||
}); | ||
|
||
test('throws DioException that can be caught', () async { | ||
try { | ||
await dio.get('https://does.not.exist'); | ||
fail('did not throw'); | ||
} on DioException catch (e) { | ||
expect(e, isNotNull); | ||
} | ||
}); | ||
|
||
test('POST string', () async { | ||
final response = await dio.post('/post', data: 'TEST'); | ||
expect(response.data['data'], 'TEST'); | ||
}); | ||
|
||
test('POST map', () async { | ||
final response = await dio.post( | ||
'/post', | ||
data: {'a': 1, 'b': 2, 'c': 3}, | ||
); | ||
expect(response.data['data'], '{"a":1,"b":2,"c":3}'); | ||
expect(response.statusCode, 200); | ||
}); | ||
}); | ||
} |
Oops, something went wrong.