platform/packages/core/test/detach_test.dart

36 lines
880 B
Dart
Raw Permalink Normal View History

import 'dart:convert';
import 'package:platform_core/core.dart';
import 'package:platform_core/http.dart';
import 'package:platform_mocking/mocking.dart';
import 'package:test/test.dart';
void main() {
2024-09-28 23:14:48 +00:00
late PlatformHttp http;
setUp(() async {
2024-09-28 23:14:48 +00:00
var app = Application();
http = PlatformHttp(app);
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!');
});
}