2024-09-23 01:44:59 +00:00
|
|
|
import 'dart:convert';
|
2024-09-25 04:04:57 +00:00
|
|
|
import 'package:platform_core/core.dart';
|
|
|
|
import 'package:platform_core/http.dart';
|
|
|
|
import 'package:platform_mocking/mocking.dart';
|
2024-09-23 01:44:59 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2024-09-28 23:14:48 +00:00
|
|
|
late PlatformHttp http;
|
2024-09-23 01:44:59 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
2024-09-28 23:14:48 +00:00
|
|
|
var app = Application();
|
|
|
|
http = PlatformHttp(app);
|
2024-09-23 01:44:59 +00:00
|
|
|
|
|
|
|
app.get('/detach', (req, res) async {
|
|
|
|
if (res is HttpResponseContext) {
|
|
|
|
var io = res.detach();
|
|
|
|
io.write('Hey!');
|
|
|
|
await io.close();
|
|
|
|
} else {
|
|
|
|
throw StateError('This endpoint only supports HTTP/1.1.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() => http.close());
|
|
|
|
|
|
|
|
test('detach response', () async {
|
|
|
|
var rq = MockHttpRequest('GET', Uri.parse('/detach'));
|
|
|
|
await rq.close();
|
|
|
|
var rs = rq.response;
|
|
|
|
await http.handleRequest(rq);
|
|
|
|
var body = await rs.transform(utf8.decoder).join();
|
|
|
|
expect(body, 'Hey!');
|
|
|
|
});
|
|
|
|
}
|