2016-04-21 22:44:05 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
2018-11-13 21:25:17 +00:00
|
|
|
import 'package:angel_framework/http.dart';
|
2016-04-21 22:44:05 +00:00
|
|
|
import 'package:angel_static/angel_static.dart';
|
2017-09-23 21:57:54 +00:00
|
|
|
import 'package:file/file.dart';
|
|
|
|
import 'package:file/local.dart';
|
2016-04-21 22:44:05 +00:00
|
|
|
import 'package:http/http.dart' show Client;
|
2017-09-23 21:57:54 +00:00
|
|
|
import 'package:logging/logging.dart';
|
2016-04-21 22:44:05 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
main() {
|
2016-11-23 17:22:23 +00:00
|
|
|
Angel app;
|
2018-07-09 17:38:22 +00:00
|
|
|
AngelHttp http;
|
2017-09-23 21:57:54 +00:00
|
|
|
Directory testDir = const LocalFileSystem().directory('test');
|
2016-11-23 17:22:23 +00:00
|
|
|
String url;
|
|
|
|
Client client = new Client();
|
|
|
|
|
|
|
|
setUp(() async {
|
2017-08-16 00:01:31 +00:00
|
|
|
app = new Angel();
|
2018-07-09 17:38:22 +00:00
|
|
|
http = new AngelHttp(app);
|
2017-09-23 21:57:54 +00:00
|
|
|
app.logger = new Logger('angel')..onRecord.listen(print);
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2018-08-28 14:58:28 +00:00
|
|
|
app.fallback(
|
2017-09-23 21:57:54 +00:00
|
|
|
new VirtualDirectory(app, const LocalFileSystem(),
|
|
|
|
source: testDir,
|
|
|
|
publicPath: '/virtual',
|
|
|
|
indexFileNames: ['index.txt']).handleRequest,
|
|
|
|
);
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2018-08-28 14:58:28 +00:00
|
|
|
app.fallback(
|
2017-09-23 21:57:54 +00:00
|
|
|
new VirtualDirectory(app, const LocalFileSystem(),
|
|
|
|
source: testDir,
|
2018-08-28 14:58:28 +00:00
|
|
|
useBuffer: true,
|
2017-09-23 21:57:54 +00:00
|
|
|
indexFileNames: ['index.php', 'index.txt']).handleRequest,
|
|
|
|
);
|
2016-11-23 17:22:23 +00:00
|
|
|
|
2018-08-28 14:58:28 +00:00
|
|
|
app.fallback((req, res) => '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
|
|
|
|
2018-07-09 17:38:22 +00:00
|
|
|
var server = await http.startServer();
|
2017-09-23 21:57:54 +00:00
|
|
|
url = "http://${server.address.host}:${server.port}";
|
2016-11-23 17:22:23 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2018-11-13 21:25:17 +00:00
|
|
|
if (http.server != null) await http.server.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-09-23 21:57:54 +00:00
|
|
|
expect(response.headers['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"));
|
2017-09-23 21:57:54 +00:00
|
|
|
expect(response.headers['content-type'], contains("text/plain"));
|
2017-02-22 23:43:27 +00:00
|
|
|
});
|
|
|
|
|
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
|
|
|
});
|
2017-06-16 03:13:01 +00:00
|
|
|
|
|
|
|
test('chrome accept', () async {
|
|
|
|
var response = await client.get("$url/virtual", headers: {
|
2017-09-23 21:57:54 +00:00
|
|
|
'accept':
|
2017-06-16 03:13:01 +00:00
|
|
|
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
|
|
|
});
|
|
|
|
expect(response.body, equals("index!"));
|
|
|
|
});
|
2016-11-23 09:41:41 +00:00
|
|
|
}
|