1.0.5
This commit is contained in:
parent
d173dd75fb
commit
0466346f2d
4 changed files with 35 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
# angel_test
|
||||
[![version 1.0.4](https://img.shields.io/badge/pub-1.0.4-brightgreen.svg)](https://pub.dartlang.org/packages/angel_test)
|
||||
[![version 1.0.5](https://img.shields.io/badge/pub-1.0.5-brightgreen.svg)](https://pub.dartlang.org/packages/angel_test)
|
||||
[![build status](https://travis-ci.org/angel-dart/test.svg)](https://travis-ci.org/angel-dart/test)
|
||||
|
||||
Testing utility library for the Angel framework.
|
||||
|
|
|
@ -22,8 +22,10 @@ const Map<String, String> _writeHeaders = const {
|
|||
final Uuid _uuid = new Uuid();
|
||||
|
||||
/// Shorthand for bootstrapping a [TestClient].
|
||||
Future<TestClient> connectTo(Angel app, {Map initialSession}) async =>
|
||||
new TestClient(app)..session.addAll(initialSession ?? {});
|
||||
Future<TestClient> connectTo(Angel app,
|
||||
{Map initialSession, bool autoDecodeGzip: true}) async =>
|
||||
new TestClient(app, autoDecodeGzip: autoDecodeGzip != false)
|
||||
..session.addAll(initialSession ?? {});
|
||||
|
||||
/// An `angel_client` that sends mock requests to a server, rather than actual HTTP transactions.
|
||||
class TestClient extends client.BaseAngelClient {
|
||||
|
@ -35,16 +37,19 @@ class TestClient extends client.BaseAngelClient {
|
|||
/// A list of cookies to be sent to and received from the server.
|
||||
final List<Cookie> cookies = [];
|
||||
|
||||
/// If `true` (default), the client will automatically decode GZIP response bodies.
|
||||
final bool autoDecodeGzip;
|
||||
|
||||
/// The server instance to mock.
|
||||
final Angel server;
|
||||
|
||||
@override
|
||||
String authToken;
|
||||
|
||||
TestClient(this.server) : super(null, '/');
|
||||
TestClient(this.server, {this.autoDecodeGzip: true}) : super(null, '/');
|
||||
|
||||
Future close() async {
|
||||
if (server.httpServer != null) await server.httpServer.close(force: true);
|
||||
await server.close();
|
||||
}
|
||||
|
||||
/// Opens a WebSockets connection to the server. This will automatically bind the server
|
||||
|
@ -114,13 +119,20 @@ class TestClient extends client.BaseAngelClient {
|
|||
extractedHeaders[k] = v.join(',');
|
||||
});
|
||||
|
||||
return new http.StreamedResponse(rs, rs.statusCode,
|
||||
Stream<List<int>> stream = rs;
|
||||
|
||||
if (autoDecodeGzip != false &&
|
||||
rs.headers[HttpHeaders.CONTENT_ENCODING]?.contains('gzip') == true)
|
||||
stream = stream.transform(GZIP.decoder);
|
||||
|
||||
return new http.StreamedResponse(stream, rs.statusCode,
|
||||
contentLength: rs.contentLength,
|
||||
isRedirect: rs.headers[HttpHeaders.LOCATION] != null,
|
||||
headers: extractedHeaders,
|
||||
persistentConnection:
|
||||
rq.headers.value(HttpHeaders.CONNECTION)?.toLowerCase()?.trim() ==
|
||||
'keep-alive',
|
||||
'keep-alive' ||
|
||||
rq.headers.persistentConnection == true,
|
||||
reasonPhrase: rs.reasonPhrase);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ author: "Tobe O <thosakwe@gmail.com>"
|
|||
description: "Testing utility library for the Angel framework."
|
||||
homepage: "https://github.com/angel-dart/test.git"
|
||||
name: "angel_test"
|
||||
version: "1.0.4"
|
||||
version: 1.0.5
|
||||
dependencies:
|
||||
angel_client: "^1.0.0"
|
||||
angel_framework: "^1.0.0-dev"
|
||||
|
|
|
@ -30,6 +30,12 @@ main() {
|
|||
..post('/hello', (req, res) async {
|
||||
return {'bar': req.body['foo']};
|
||||
})
|
||||
..get('/gzip', (req, res) async {
|
||||
res
|
||||
..headers[HttpHeaders.CONTENT_ENCODING] = 'gzip'
|
||||
..write(GZIP.encode('Poop'.codeUnits))
|
||||
..end();
|
||||
})
|
||||
..use(
|
||||
'/foo',
|
||||
new AnonymousService(
|
||||
|
@ -99,11 +105,19 @@ main() {
|
|||
})));
|
||||
});
|
||||
|
||||
test('gzip decode', () async {
|
||||
var res = await client.get('/gzip');
|
||||
expect(res, hasHeader(HttpHeaders.CONTENT_ENCODING, 'gzip'));
|
||||
expect(res, hasBody('Poop'));
|
||||
});
|
||||
|
||||
group('service', () {
|
||||
test('index', () async {
|
||||
var foo = client.service('foo');
|
||||
var result = await foo.index();
|
||||
expect(result, [{'michael': 'jackson'}]);
|
||||
expect(result, [
|
||||
{'michael': 'jackson'}
|
||||
]);
|
||||
});
|
||||
|
||||
test('index', () async {
|
||||
|
|
Loading…
Reference in a new issue