apply pkg:pedantic lints
This commit is contained in:
parent
3a9bd27d6d
commit
1c07aa5243
13 changed files with 78 additions and 59 deletions
|
@ -2,8 +2,6 @@ include: package:pedantic/analysis_options.yaml
|
|||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
errors:
|
||||
unawaited_futures: ignore
|
||||
linter:
|
||||
rules:
|
||||
- avoid_slow_async_io
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'dart:io';
|
|||
import 'package:angel_framework/angel_framework.dart' hide Header;
|
||||
import 'package:http2/transport.dart';
|
||||
import 'package:mock_request/mock_request.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'http2_request_context.dart';
|
||||
import 'http2_response_context.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
@ -148,7 +149,7 @@ class _FakeServerSocket extends Stream<Socket> implements ServerSocket {
|
|||
|
||||
@override
|
||||
Future<ServerSocket> close() async {
|
||||
_ctrl.close();
|
||||
unawaited(_ctrl.close());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -202,9 +203,9 @@ class _AngelHttp2ServerSocket extends Stream<SecureSocket>
|
|||
int get port => socket.port;
|
||||
|
||||
Future<SecureServerSocket> close() async {
|
||||
_sub?.cancel();
|
||||
_fake.close();
|
||||
_ctrl.close();
|
||||
unawaited(_sub?.cancel());
|
||||
unawaited(_fake.close());
|
||||
unawaited(_ctrl.close());
|
||||
return await socket.close();
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ dependencies:
|
|||
mime: ^0.9.3
|
||||
mock_request: ^1.0.0
|
||||
path: ^1.0.0
|
||||
pedantic: ^1.0.0
|
||||
quiver_hashcode: ^2.0.0
|
||||
stack_trace: ^1.0.0
|
||||
tuple: ^1.0.0
|
||||
|
@ -30,5 +31,4 @@ dependencies:
|
|||
dev_dependencies:
|
||||
http: ^0.11.3
|
||||
io: ^0.3.0
|
||||
pedantic: ^1.0.0
|
||||
test: ^1.0.0
|
||||
|
|
|
@ -14,9 +14,8 @@ void main() {
|
|||
app.get('/detach', (req, res) async {
|
||||
if (res is HttpResponseContext) {
|
||||
var io = await res.detach();
|
||||
io
|
||||
..write('Hey!')
|
||||
..close();
|
||||
io..write('Hey!');
|
||||
await io.close();
|
||||
} else {
|
||||
throw new StateError('This endpoint only supports HTTP/1.1.');
|
||||
}
|
||||
|
@ -26,7 +25,8 @@ void main() {
|
|||
tearDown(() => http.close());
|
||||
|
||||
test('detach response', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/detach'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/detach'));
|
||||
await rq.close();
|
||||
var rs = rq.response;
|
||||
await http.handleRequest(rq);
|
||||
var body = await rs.transform(utf8.decoder).join();
|
||||
|
|
|
@ -62,7 +62,8 @@ main() {
|
|||
return app.runContained((Todo t) => t.text, req, res, c);
|
||||
});
|
||||
|
||||
var rq = new MockHttpRequest('GET', new Uri(path: '/'))..close();
|
||||
var rq = new MockHttpRequest('GET', new Uri(path: '/'));
|
||||
await rq.close();
|
||||
var rs = rq.response;
|
||||
await new AngelHttp(app).handleRequest(rq);
|
||||
var text = await rs.transform(utf8.decoder).join();
|
||||
|
|
|
@ -51,7 +51,8 @@ void encodingTests(Angel getApp()) {
|
|||
});
|
||||
|
||||
test('sends plaintext if no accept-encoding', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'));
|
||||
await rq.close();
|
||||
var rs = rq.response;
|
||||
await http.handleRequest(rq);
|
||||
|
||||
|
@ -61,8 +62,8 @@ void encodingTests(Angel getApp()) {
|
|||
|
||||
test('encodes if wildcard', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
|
||||
..headers.set('accept-encoding', '*')
|
||||
..close();
|
||||
..headers.set('accept-encoding', '*');
|
||||
await rq.close();
|
||||
var rs = rq.response;
|
||||
await http.handleRequest(rq);
|
||||
|
||||
|
@ -74,8 +75,8 @@ void encodingTests(Angel getApp()) {
|
|||
|
||||
test('encodes if wildcard + multiple', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/hello'))
|
||||
..headers.set('accept-encoding', ['foo', 'bar', '*'])
|
||||
..close();
|
||||
..headers.set('accept-encoding', ['foo', 'bar', '*']);
|
||||
await rq.close();
|
||||
var rs = rq.response;
|
||||
await http.handleRequest(rq);
|
||||
|
||||
|
|
|
@ -76,13 +76,11 @@ void main() {
|
|||
res.write('ok');
|
||||
|
||||
if (res is Http2ResponseContext && res.canPush) {
|
||||
res.push('a')
|
||||
..write('a')
|
||||
..close();
|
||||
var a = res.push('a')..write('a');
|
||||
await a.close();
|
||||
|
||||
res.push('b')
|
||||
..write('b')
|
||||
..close();
|
||||
var b = res.push('b')..write('b');
|
||||
await b.close();
|
||||
}
|
||||
|
||||
await res.close();
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'dart:convert';
|
|||
import 'dart:io';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http2/transport.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
|
||||
/// Simple HTTP/2 client
|
||||
class Http2Client extends BaseClient {
|
||||
|
@ -46,7 +47,7 @@ class Http2Client extends BaseClient {
|
|||
if (body.isNotEmpty) {
|
||||
stream.sendData(body, endStream: true);
|
||||
} else {
|
||||
stream.outgoingMessages.close();
|
||||
unawaited(stream.outgoingMessages.close());
|
||||
}
|
||||
|
||||
return stream;
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:angel_container/mirrors.dart';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/http.dart';
|
||||
import 'package:mock_request/mock_request.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Future<String> readResponse(MockHttpResponse rs) {
|
||||
|
@ -68,19 +69,20 @@ parameterMetaTests() {
|
|||
|
||||
test('injects header or throws', () async {
|
||||
// Invalid request
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/header'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/header'));
|
||||
unawaited(rq.close());
|
||||
var rs = rq.response;
|
||||
http.handleRequest(rq);
|
||||
unawaited(http.handleRequest(rq));
|
||||
|
||||
await printResponse(rs);
|
||||
expect(rs.statusCode, 400);
|
||||
|
||||
// Valid request
|
||||
rq = new MockHttpRequest('GET', Uri.parse('/header'))
|
||||
..headers.add('x-foo', 'bar')
|
||||
..close();
|
||||
..headers.add('x-foo', 'bar');
|
||||
unawaited(rq.close());
|
||||
rs = rq.response;
|
||||
await http.handleRequest(rq);
|
||||
await unawaited(http.handleRequest(rq));
|
||||
|
||||
var body = await readResponse(rs);
|
||||
print('Body: $body');
|
||||
|
@ -90,21 +92,22 @@ parameterMetaTests() {
|
|||
|
||||
test('injects session or throws', () async {
|
||||
// Invalid request
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/session'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/session'));
|
||||
unawaited(rq.close());
|
||||
var rs = rq.response;
|
||||
http
|
||||
unawaited(http
|
||||
.handleRequest(rq)
|
||||
.timeout(const Duration(seconds: 5))
|
||||
.catchError((_) => null);
|
||||
.catchError((_) => null));
|
||||
|
||||
await printResponse(rs);
|
||||
expect(rs.statusCode, 500);
|
||||
|
||||
rq = new MockHttpRequest('GET', Uri.parse('/session'));
|
||||
rq.session['foo'] = 'bar';
|
||||
rq.close();
|
||||
unawaited(rq.close());
|
||||
rs = rq.response;
|
||||
http.handleRequest(rq);
|
||||
unawaited(http.handleRequest(rq));
|
||||
|
||||
await printResponse(rs);
|
||||
expect(rs.statusCode, 200);
|
||||
|
@ -115,26 +118,29 @@ parameterMetaTests() {
|
|||
// they will all function the same way.
|
||||
|
||||
test('pattern matching', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/match?mode=pos'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/match?mode=pos'));
|
||||
unawaited(rq.close());
|
||||
var rs = rq.response;
|
||||
http.handleRequest(rq);
|
||||
unawaited(http.handleRequest(rq));
|
||||
var body = await readResponse(rs);
|
||||
print('Body: $body');
|
||||
expect(rs.statusCode, 200);
|
||||
expect(body, json.encode('YES pos'));
|
||||
|
||||
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=neg'))..close();
|
||||
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=neg'));
|
||||
unawaited(rq.close());
|
||||
rs = rq.response;
|
||||
http.handleRequest(rq);
|
||||
unawaited(http.handleRequest(rq));
|
||||
body = await readResponse(rs);
|
||||
print('Body: $body');
|
||||
expect(rs.statusCode, 200);
|
||||
expect(body, json.encode('NO neg'));
|
||||
|
||||
// Fallback
|
||||
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=ambi'))..close();
|
||||
rq = new MockHttpRequest('GET', Uri.parse('/match?mode=ambi'));
|
||||
unawaited(rq.close());
|
||||
rs = rq.response;
|
||||
http.handleRequest(rq);
|
||||
unawaited(http.handleRequest(rq));
|
||||
body = await readResponse(rs);
|
||||
print('Body: $body');
|
||||
expect(rs.statusCode, 200);
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:angel_container/mirrors.dart';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/http.dart';
|
||||
import 'package:mock_request/mock_request.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
|
@ -16,7 +17,7 @@ main() {
|
|||
expect(app.preContained.keys, contains(echoAppFoo));
|
||||
|
||||
var rq = new MockHttpRequest('GET', new Uri(path: '/foo'));
|
||||
rq.close();
|
||||
unawaited(rq.close());
|
||||
await new AngelHttp(app).handleRequest(rq);
|
||||
var rs = rq.response;
|
||||
var body = await rs.transform(utf8.decoder).join();
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:angel_container/mirrors.dart';
|
|||
import 'package:angel_framework/angel_framework.dart';
|
||||
import 'package:angel_framework/http.dart';
|
||||
import 'package:mock_request/mock_request.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
main() {
|
||||
|
@ -38,21 +39,24 @@ main() {
|
|||
tearDown(() => app.close());
|
||||
|
||||
test('String type annotation', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/string/hello'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/string/hello'));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var rs = await rq.response.transform(utf8.decoder).join();
|
||||
expect(rs, json.encode('hello'));
|
||||
});
|
||||
|
||||
test('Primitive after parsed param injection', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/parsed/24'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/parsed/24'));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var rs = await rq.response.transform(utf8.decoder).join();
|
||||
expect(rs, json.encode(24));
|
||||
});
|
||||
|
||||
test('globally-injected primitive', () async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/global'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/global'));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var rs = await rq.response.transform(utf8.decoder).join();
|
||||
expect(rs, json.encode(305));
|
||||
|
@ -60,8 +64,8 @@ main() {
|
|||
|
||||
test('unparsed primitive throws error', () async {
|
||||
try {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/unparsed/32'))
|
||||
..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/num/unparsed/32'));
|
||||
unawaited(rq.close());
|
||||
var req = await http.createRequestContext(rq, rq.response);
|
||||
var res = await http.createResponseContext(rq, rq.response, req);
|
||||
await app.runContained((num unparsed) => unparsed, req, res);
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:angel_framework/angel_framework.dart';
|
|||
import 'package:angel_framework/http.dart';
|
||||
import 'package:matcher/matcher.dart';
|
||||
import 'package:mock_request/mock_request.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
final Uri $foo = Uri.parse('http://localhost:3000/foo');
|
||||
|
@ -42,7 +43,7 @@ main() {
|
|||
var app = new Angel(reflector: MirrorsReflector());
|
||||
var http = new AngelHttp(app);
|
||||
var rq = new MockHttpRequest('GET', $foo);
|
||||
rq.close();
|
||||
unawaited(rq.close());
|
||||
var rs = rq.response;
|
||||
var req = await http.createRequestContext(rq, rs);
|
||||
var res = await http.createResponseContext(rq, rs);
|
||||
|
@ -94,7 +95,8 @@ main() {
|
|||
..configuration['a'] = 'b';
|
||||
var http = new AngelHttp(app);
|
||||
app.get('/', ioc((String a) => a));
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/'));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var body = await rq.response.transform(utf8.decoder).join();
|
||||
expect(body, json.encode('b'));
|
||||
|
@ -104,7 +106,8 @@ main() {
|
|||
var app = new Angel(reflector: MirrorsReflector())..serializer = (_) => 'x';
|
||||
var http = new AngelHttp(app);
|
||||
app.get($foo.path, (req, ResponseContext res) => res.serialize(null));
|
||||
var rq = new MockHttpRequest('GET', $foo)..close();
|
||||
var rq = new MockHttpRequest('GET', $foo);
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var body = await rq.response.transform(utf8.decoder).join();
|
||||
expect(body, 'x');
|
||||
|
@ -119,7 +122,8 @@ main() {
|
|||
ResponseContext res;
|
||||
|
||||
setUp(() async {
|
||||
var rq = new MockHttpRequest('GET', $foo)..close();
|
||||
var rq = new MockHttpRequest('GET', $foo);
|
||||
unawaited(rq.close());
|
||||
req = await http.createRequestContext(rq, rq.response);
|
||||
res = await http.createResponseContext(rq, rq.response);
|
||||
});
|
||||
|
@ -176,8 +180,8 @@ main() {
|
|||
test('can send json', () async {
|
||||
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
|
||||
..headers.set('accept', 'application/json');
|
||||
rq.close();
|
||||
http.handleRequest(rq);
|
||||
unawaited(rq.close());
|
||||
unawaited(http.handleRequest(rq));
|
||||
await rq.response.toList();
|
||||
expect(rq.response.statusCode, 403);
|
||||
expect(rq.response.headers.contentType.mimeType, 'application/json');
|
||||
|
@ -186,8 +190,8 @@ main() {
|
|||
test('can throw in finalizer', () async {
|
||||
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf'))
|
||||
..headers.set('accept', 'application/json');
|
||||
rq.close();
|
||||
http.handleRequest(rq);
|
||||
unawaited(rq.close());
|
||||
unawaited(http.handleRequest(rq));
|
||||
await rq.response.toList();
|
||||
expect(rq.response.statusCode, 403);
|
||||
expect(rq.response.headers.contentType.mimeType, 'application/json');
|
||||
|
@ -196,8 +200,8 @@ main() {
|
|||
test('can send html', () async {
|
||||
var rq = new MockHttpRequest('GET', new Uri(path: 'wtf2'));
|
||||
rq.headers.set('accept', 'text/html');
|
||||
rq.close();
|
||||
http.handleRequest(rq);
|
||||
unawaited(rq.close());
|
||||
unawaited(http.handleRequest(rq));
|
||||
await rq.response.toList();
|
||||
expect(rq.response.statusCode, 403);
|
||||
expect(rq.response.headers.contentType?.mimeType, 'text/html');
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:angel_framework/angel_framework.dart';
|
|||
import 'package:angel_framework/http.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:mock_request/mock_request.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'encoders_buffer_test.dart' show encodingTests;
|
||||
|
@ -76,7 +77,8 @@ main() {
|
|||
tearDown(() => http.close());
|
||||
|
||||
_expectHelloBye(String path) async {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse(path))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse(path));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var body = await rq.response.transform(utf8.decoder).join();
|
||||
expect(body, 'Hello, world!bye');
|
||||
|
@ -88,7 +90,8 @@ main() {
|
|||
|
||||
test('cannot write after close', () async {
|
||||
try {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/overwrite'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/overwrite'));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var body = await rq.response.transform(utf8.decoder).join();
|
||||
|
||||
|
@ -101,7 +104,8 @@ main() {
|
|||
|
||||
test('res => addError', () async {
|
||||
try {
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/error'))..close();
|
||||
var rq = new MockHttpRequest('GET', Uri.parse('/error'));
|
||||
unawaited(rq.close());
|
||||
await http.handleRequest(rq);
|
||||
var body = await rq.response.transform(utf8.decoder).join();
|
||||
throw 'addError should throw error; response: $body';
|
||||
|
|
Loading…
Reference in a new issue