Updated test

This commit is contained in:
thomashii 2021-06-26 23:15:48 +08:00
parent d5dba913af
commit eb52952eaa
2 changed files with 22 additions and 22 deletions

View file

@ -70,9 +70,9 @@ parameterMetaTests() {
test('injects header or throws', () async { test('injects header or throws', () async {
// Invalid request // Invalid request
var rq = MockHttpRequest('GET', Uri.parse('/header')); var rq = MockHttpRequest('GET', Uri.parse('/header'));
await (rq.close()); rq.close();
var rs = rq.response; var rs = rq.response;
await (http.handleRequest(rq)); http.handleRequest(rq);
await printResponse(rs); await printResponse(rs);
expect(rs.statusCode, 400); expect(rs.statusCode, 400);
@ -80,9 +80,9 @@ parameterMetaTests() {
// Valid request // Valid request
rq = MockHttpRequest('GET', Uri.parse('/header')) rq = MockHttpRequest('GET', Uri.parse('/header'))
..headers.add('x-foo', 'bar'); ..headers.add('x-foo', 'bar');
await (rq.close()); rq.close();
rs = rq.response; rs = rq.response;
await (http.handleRequest(rq)); http.handleRequest(rq);
var body = await readResponse(rs); var body = await readResponse(rs);
print('Body: $body'); print('Body: $body');
@ -93,21 +93,21 @@ parameterMetaTests() {
test('injects session or throws', () async { test('injects session or throws', () async {
// Invalid request // Invalid request
var rq = MockHttpRequest('GET', Uri.parse('/session')); var rq = MockHttpRequest('GET', Uri.parse('/session'));
await (rq.close()); rq.close();
var rs = rq.response; var rs = rq.response;
await (http http
.handleRequest(rq) .handleRequest(rq)
.timeout(const Duration(seconds: 5)) .timeout(const Duration(seconds: 5))
.catchError((_) => null)); .catchError((_) => null);
await printResponse(rs); await printResponse(rs);
expect(rs.statusCode, 500); expect(rs.statusCode, 500);
rq = MockHttpRequest('GET', Uri.parse('/session')); rq = MockHttpRequest('GET', Uri.parse('/session'));
rq.session['foo'] = 'bar'; rq.session['foo'] = 'bar';
await (rq.close()); rq.close();
rs = rq.response; rs = rq.response;
await (http.handleRequest(rq)); http.handleRequest(rq);
await printResponse(rs); await printResponse(rs);
expect(rs.statusCode, 200); expect(rs.statusCode, 200);
@ -119,18 +119,18 @@ parameterMetaTests() {
test('pattern matching', () async { test('pattern matching', () async {
var rq = MockHttpRequest('GET', Uri.parse('/match?mode=pos')); var rq = MockHttpRequest('GET', Uri.parse('/match?mode=pos'));
await (rq.close()); rq.close();
var rs = rq.response; var rs = rq.response;
await (http.handleRequest(rq)); http.handleRequest(rq);
var body = await readResponse(rs); var body = await readResponse(rs);
print('Body: $body'); print('Body: $body');
expect(rs.statusCode, 200); expect(rs.statusCode, 200);
expect(body, json.encode('YES pos')); expect(body, json.encode('YES pos'));
rq = MockHttpRequest('GET', Uri.parse('/match?mode=neg')); rq = MockHttpRequest('GET', Uri.parse('/match?mode=neg'));
await (rq.close()); rq.close();
rs = rq.response; rs = rq.response;
await (http.handleRequest(rq)); http.handleRequest(rq);
body = await readResponse(rs); body = await readResponse(rs);
print('Body: $body'); print('Body: $body');
expect(rs.statusCode, 200); expect(rs.statusCode, 200);
@ -138,9 +138,9 @@ parameterMetaTests() {
// Fallback // Fallback
rq = MockHttpRequest('GET', Uri.parse('/match?mode=ambi')); rq = MockHttpRequest('GET', Uri.parse('/match?mode=ambi'));
await (rq.close()); rq.close();
rs = rq.response; rs = rq.response;
await (http.handleRequest(rq)); http.handleRequest(rq);
body = await readResponse(rs); body = await readResponse(rs);
print('Body: $body'); print('Body: $body');
expect(rs.statusCode, 200); expect(rs.statusCode, 200);

View file

@ -178,8 +178,8 @@ void main() {
test('can send json', () async { test('can send json', () async {
var rq = MockHttpRequest('GET', Uri(path: 'wtf')) var rq = MockHttpRequest('GET', Uri(path: 'wtf'))
..headers.set('accept', 'application/json'); ..headers.set('accept', 'application/json');
await (rq.close()); rq.close();
await (http.handleRequest(rq)); http.handleRequest(rq);
await rq.response.toList(); await rq.response.toList();
expect(rq.response.statusCode, 403); expect(rq.response.statusCode, 403);
expect(rq.response.headers.contentType!.mimeType, 'application/json'); expect(rq.response.headers.contentType!.mimeType, 'application/json');
@ -188,8 +188,8 @@ void main() {
test('can throw in finalizer', () async { test('can throw in finalizer', () async {
var rq = MockHttpRequest('GET', Uri(path: 'wtf')) var rq = MockHttpRequest('GET', Uri(path: 'wtf'))
..headers.set('accept', 'application/json'); ..headers.set('accept', 'application/json');
await (rq.close()); rq.close();
await (http.handleRequest(rq)); http.handleRequest(rq);
await rq.response.toList(); await rq.response.toList();
expect(rq.response.statusCode, 403); expect(rq.response.statusCode, 403);
expect(rq.response.headers.contentType!.mimeType, 'application/json'); expect(rq.response.headers.contentType!.mimeType, 'application/json');
@ -197,9 +197,9 @@ void main() {
test('can send html', () async { test('can send html', () async {
var rq = MockHttpRequest('GET', Uri(path: 'wtf2')); var rq = MockHttpRequest('GET', Uri(path: 'wtf2'));
rq.headers.set('accept', 'text/html'); //rq.headers.set('accept', 'text/html');
await (rq.close()); rq.close();
await (http.handleRequest(rq)); http.handleRequest(rq);
await rq.response.toList(); await rq.response.toList();
expect(rq.response.statusCode, 403); expect(rq.response.statusCode, 403);
expect(rq.response.headers.contentType?.mimeType, 'text/html'); expect(rq.response.headers.contentType?.mimeType, 'text/html');