2024-09-23 01:44:59 +00:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:platform_container/mirrors.dart';
|
2024-09-25 04:04:57 +00:00
|
|
|
import 'package:platform_core/core.dart';
|
|
|
|
import 'package:platform_core/http.dart';
|
2024-09-23 01:44:59 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import 'package:http_parser/http_parser.dart';
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2024-09-28 23:14:48 +00:00
|
|
|
late Application app;
|
2024-09-23 01:44:59 +00:00
|
|
|
late http.Client client;
|
|
|
|
late HttpServer server;
|
|
|
|
late String url;
|
|
|
|
|
|
|
|
setUp(() async {
|
2024-09-28 23:14:48 +00:00
|
|
|
app = Application(reflector: MirrorsReflector())
|
2024-09-23 01:44:59 +00:00
|
|
|
..get('/foo', ioc(() => {'hello': 'world'}))
|
|
|
|
..get('/bar', (req, res) async {
|
|
|
|
await res.serialize({'hello': 'world'},
|
|
|
|
contentType: MediaType('text', 'html'));
|
|
|
|
});
|
|
|
|
client = http.Client();
|
|
|
|
|
2024-09-28 23:14:48 +00:00
|
|
|
server = await PlatformHttp(app).startServer();
|
2024-09-23 01:44:59 +00:00
|
|
|
url = 'http://${server.address.host}:${server.port}';
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
client.close();
|
|
|
|
await server.close(force: true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('correct content-type', () async {
|
|
|
|
var response = await client.get(Uri.parse('$url/foo'));
|
|
|
|
print('Response: ${response.body}');
|
|
|
|
expect(response.headers['content-type'], contains('application/json'));
|
|
|
|
|
|
|
|
response = await client.get(Uri.parse('$url/bar'));
|
|
|
|
print('Response: ${response.body}');
|
|
|
|
expect(response.headers['content-type'], contains('text/html'));
|
|
|
|
});
|
|
|
|
}
|