platform/test/basic_test.dart

73 lines
2 KiB
Dart
Raw Normal View History

2017-04-02 02:06:27 +00:00
import 'dart:convert';
2016-11-23 22:03:06 +00:00
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_proxy/angel_proxy.dart';
2017-04-22 18:46:00 +00:00
import 'package:angel_test/angel_test.dart';
2016-11-23 22:03:06 +00:00
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
import 'common.dart';
main() {
Angel app;
http.Client client = new http.Client();
HttpServer server, testServer;
String url;
setUp(() async {
2017-04-02 02:06:27 +00:00
app = new Angel()..storeOriginalBuffer = true;
2016-11-23 22:03:06 +00:00
testServer = await testApp().startServer();
2017-01-12 00:19:15 +00:00
2017-01-12 00:12:23 +00:00
await app.configure(new ProxyLayer(
testServer.address.address, testServer.port,
2017-01-12 00:19:15 +00:00
publicPath: '/proxy'));
2017-01-12 00:12:23 +00:00
await app.configure(new ProxyLayer(
testServer.address.address, testServer.port,
mapTo: '/foo'));
2016-11-23 22:03:06 +00:00
2017-04-22 18:46:00 +00:00
app.after.add((req, res) async => res.write('intercept empty'));
2016-11-23 22:03:06 +00:00
server = await app.startServer();
url = 'http://${server.address.address}:${server.port}';
});
tearDown(() async {
await testServer.close(force: true);
await server.close(force: true);
app = null;
url = null;
});
test('publicPath', () async {
final response = await client.get('$url/proxy/hello');
print('Response: ${response.body}');
expect(response.body, equals('"world"'));
});
2017-04-22 18:46:00 +00:00
test('empty', () async {
var response = await client.get('$url/proxy/empty');
print('Response: ${response.body}');
// Shouldn't say it is gzipped...
expect(response, isNot(hasHeader('content-encoding')));
// Should have gzipped body
expect(response.body, 'intercept empty');
});
2016-11-23 22:03:06 +00:00
test('mapTo', () async {
final response = await client.get('$url/bar');
print('Response: ${response.body}');
expect(response.body, equals('"baz"'));
});
2017-04-02 02:06:27 +00:00
test('original buffer', () async {
var response = await client.post('$url/proxy/body',
body: {'foo': 'bar'},
headers: {'content-type': 'application/x-www-form-urlencoded'});
print('Response: ${response.body}');
expect(response.body, isNotEmpty);
expect(JSON.decode(response.body), {'foo': 'bar'});
});
2017-01-12 00:12:23 +00:00
}