2018-08-28 13:55:39 +00:00
|
|
|
import 'dart:convert';
|
2021-05-14 10:34:09 +00:00
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_framework/http.dart';
|
|
|
|
import 'package:angel3_mock_request/angel3_mock_request.dart';
|
2018-08-28 13:55:39 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2021-03-20 08:11:18 +00:00
|
|
|
late AngelHttp http;
|
2018-08-28 13:55:39 +00:00
|
|
|
|
|
|
|
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) {
|
2021-05-19 15:35:55 +00:00
|
|
|
var io = res.detach();
|
|
|
|
io.write('Hey!');
|
2019-04-17 19:42:24 +00:00
|
|
|
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!');
|
|
|
|
});
|
|
|
|
}
|