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

View file

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