2016-04-21 22:44:05 +00:00
|
|
|
import 'dart:io';
|
2017-06-16 02:05:06 +00:00
|
|
|
import 'package:angel_diagnostics/angel_diagnostics.dart';
|
2016-04-21 22:44:05 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
import 'package:angel_static/angel_static.dart';
|
|
|
|
import 'package:http/http.dart' show Client;
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
main() {
|
2016-11-23 17:22:23 +00:00
|
|
|
Angel app;
|
|
|
|
Directory testDir = new Directory('test');
|
|
|
|
String url;
|
|
|
|
Client client = new Client();
|
|
|
|
|
|
|
|
setUp(() async {
|
2016-11-23 20:14:05 +00:00
|
|
|
app = new Angel(debug: true);
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2016-11-23 20:14:05 +00:00
|
|
|
await app.configure(new VirtualDirectory(
|
|
|
|
debug: true,
|
|
|
|
source: testDir,
|
|
|
|
publicPath: '/virtual',
|
|
|
|
indexFileNames: ['index.txt']));
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2016-11-23 20:14:05 +00:00
|
|
|
await app.configure(new VirtualDirectory(
|
|
|
|
debug: true,
|
|
|
|
source: testDir,
|
|
|
|
indexFileNames: ['index.php', 'index.txt']));
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2017-06-16 02:05:06 +00:00
|
|
|
app.after.add('Fallback');
|
2016-11-23 20:14:05 +00:00
|
|
|
|
2016-11-28 00:51:47 +00:00
|
|
|
app.dumpTree(showMatchers: true);
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2017-06-16 02:05:06 +00:00
|
|
|
await app.configure(logRequests());
|
2016-11-23 17:22:23 +00:00
|
|
|
await app.startServer(InternetAddress.LOOPBACK_IP_V4, 0);
|
|
|
|
url = "http://${app.httpServer.address.host}:${app.httpServer.port}";
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2016-11-23 20:14:05 +00:00
|
|
|
if (app.httpServer != null) await app.httpServer.close(force: true);
|
2016-11-23 17:22:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
test('can serve files, with correct Content-Type', () async {
|
|
|
|
var response = await client.get("$url/sample.txt");
|
|
|
|
expect(response.body, equals("Hello world"));
|
2017-01-28 03:48:55 +00:00
|
|
|
expect(response.headers[HttpHeaders.CONTENT_TYPE], contains("text/plain"));
|
2016-11-23 17:22:23 +00:00
|
|
|
});
|
|
|
|
|
2017-02-22 23:43:27 +00:00
|
|
|
test('can serve child directories', () async {
|
|
|
|
var response = await client.get("$url/nested");
|
|
|
|
expect(response.body, equals("Bird"));
|
|
|
|
expect(response.headers[HttpHeaders.CONTENT_TYPE], contains("text/plain"));
|
|
|
|
});
|
|
|
|
|
2016-11-23 17:22:23 +00:00
|
|
|
test('non-existent files are skipped', () async {
|
|
|
|
var response = await client.get("$url/nonexist.ent");
|
|
|
|
expect(response.body, equals('"Fallback"'));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('can match index files', () async {
|
|
|
|
var response = await client.get(url);
|
|
|
|
expect(response.body, equals("index!"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test('virtualRoots can match index', () async {
|
|
|
|
var response = await client.get("$url/virtual");
|
|
|
|
expect(response.body, equals("index!"));
|
2016-04-21 22:44:05 +00:00
|
|
|
});
|
2016-11-23 09:41:41 +00:00
|
|
|
}
|