Updated shelf

This commit is contained in:
thomashii@dukefirehawk.com 2023-10-28 00:01:21 +08:00
parent 6506a3e0de
commit 3afc91edfa
2 changed files with 14 additions and 14 deletions

View file

@ -16,12 +16,12 @@ dependencies:
logging: ^1.2.0
charcode: ^1.3.0
http: ^1.0.0
# dev_dependencies:
# angel3_test: ^8.0.0
# belatuk_pretty_logging: ^6.0.0
# shelf_static: ^1.1.0
# test: ^1.24.0
# lints: ^2.1.0
dev_dependencies:
angel3_test: ^8.0.0
belatuk_pretty_logging: ^6.0.0
shelf_static: ^1.1.0
test: ^1.24.0
lints: ^2.1.0
# dependency_overrides:
# angel3_test:
# path: ../test

View file

@ -16,7 +16,7 @@ void main() {
late http.Client client;
late HttpServer server;
Uri _path(String p) {
Uri path(String p) {
return Uri(
scheme: 'http',
host: server.address.address,
@ -65,25 +65,25 @@ void main() {
});
test('expose angel side', () async {
var response = await client.get(_path('/angel'));
var response = await client.get(path('/angel'));
expect(json.decode(response.body), equals('Angel'));
});
test('expose shelf side', () async {
var response = await client.get(_path('/foo'));
var response = await client.get(path('/foo'));
expect(response, hasStatus(200));
expect(response.body, equals('Request for "foo"'));
});
test('shelf can return arbitrary values', () async {
var response = await client.get(_path('/two'));
var response = await client.get(path('/two'));
expect(response, isJson(2));
});
test('shelf can hijack', () async {
try {
var client = HttpClient();
var rq = await client.openUrl('GET', _path('/hijack'));
var rq = await client.openUrl('GET', path('/hijack'));
var rs = await rq.close();
var body = await rs.cast<List<int>>().transform(utf8.decoder).join();
print('Response: $body');
@ -96,17 +96,17 @@ void main() {
});
test('shelf can set status code', () async {
var response = await client.get(_path('/status'));
var response = await client.get(path('/status'));
expect(response, allOf(hasStatus(304), hasHeader('foo', 'bar')));
});
test('shelf can throw error', () async {
var response = await client.get(_path('/error'));
var response = await client.get(path('/error'));
expect(response, hasStatus(404));
});
test('throw on null', () async {
var response = await client.get(_path('/throw'));
var response = await client.get(path('/throw'));
expect(response, hasStatus(500));
});
}