platform/packages/framework/test/detach_test.dart

36 lines
886 B
Dart
Raw Normal View History

2018-08-28 13:55:39 +00:00
import 'dart:convert';
import 'package:angel_framework/angel_framework.dart';
2018-10-22 15:54:41 +00:00
import 'package:angel_framework/http.dart';
2018-08-28 13:55:39 +00:00
import 'package:mock_request/mock_request.dart';
import 'package:test/test.dart';
void main() {
AngelHttp http;
setUp(() async {
2019-05-02 22:48:31 +00:00
var app = Angel();
http = AngelHttp(app);
2018-08-28 13:55:39 +00:00
app.get('/detach', (req, res) async {
if (res is HttpResponseContext) {
var io = await res.detach();
2019-04-17 19:42:24 +00:00
io..write('Hey!');
await io.close();
2018-08-28 13:55:39 +00:00
} else {
2019-05-02 22:48:31 +00:00
throw StateError('This endpoint only supports HTTP/1.1.');
2018-08-28 13:55:39 +00:00
}
});
});
tearDown(() => http.close());
test('detach response', () async {
2019-05-02 22:48:31 +00:00
var rq = MockHttpRequest('GET', Uri.parse('/detach'));
2019-04-17 19:42:24 +00:00
await rq.close();
2018-08-28 13:55:39 +00:00
var rs = rq.response;
await http.handleRequest(rq);
var body = await rs.transform(utf8.decoder).join();
expect(body, 'Hey!');
});
}