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
|
# angel_test
|
||||||
[](https://pub.dartlang.org/packages/angel_test)
|
[](https://pub.dartlang.org/packages/angel_test)
|
||||||
[](https://travis-ci.org/angel-dart/test)
|
[](https://travis-ci.org/angel-dart/test)
|
||||||
|
|
||||||
Testing utility library for the Angel framework.
|
Testing utility library for the Angel framework.
|
||||||
|
|
|
@ -22,8 +22,10 @@ const Map<String, String> _writeHeaders = const {
|
||||||
final Uuid _uuid = new Uuid();
|
final Uuid _uuid = new Uuid();
|
||||||
|
|
||||||
/// Shorthand for bootstrapping a [TestClient].
|
/// Shorthand for bootstrapping a [TestClient].
|
||||||
Future<TestClient> connectTo(Angel app, {Map initialSession}) async =>
|
Future<TestClient> connectTo(Angel app,
|
||||||
new TestClient(app)..session.addAll(initialSession ?? {});
|
{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.
|
/// An `angel_client` that sends mock requests to a server, rather than actual HTTP transactions.
|
||||||
class TestClient extends client.BaseAngelClient {
|
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.
|
/// A list of cookies to be sent to and received from the server.
|
||||||
final List<Cookie> cookies = [];
|
final List<Cookie> cookies = [];
|
||||||
|
|
||||||
|
/// If `true` (default), the client will automatically decode GZIP response bodies.
|
||||||
|
final bool autoDecodeGzip;
|
||||||
|
|
||||||
/// The server instance to mock.
|
/// The server instance to mock.
|
||||||
final Angel server;
|
final Angel server;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String authToken;
|
String authToken;
|
||||||
|
|
||||||
TestClient(this.server) : super(null, '/');
|
TestClient(this.server, {this.autoDecodeGzip: true}) : super(null, '/');
|
||||||
|
|
||||||
Future close() async {
|
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
|
/// 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(',');
|
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,
|
contentLength: rs.contentLength,
|
||||||
isRedirect: rs.headers[HttpHeaders.LOCATION] != null,
|
isRedirect: rs.headers[HttpHeaders.LOCATION] != null,
|
||||||
headers: extractedHeaders,
|
headers: extractedHeaders,
|
||||||
persistentConnection:
|
persistentConnection:
|
||||||
rq.headers.value(HttpHeaders.CONNECTION)?.toLowerCase()?.trim() ==
|
rq.headers.value(HttpHeaders.CONNECTION)?.toLowerCase()?.trim() ==
|
||||||
'keep-alive',
|
'keep-alive' ||
|
||||||
|
rq.headers.persistentConnection == true,
|
||||||
reasonPhrase: rs.reasonPhrase);
|
reasonPhrase: rs.reasonPhrase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ author: "Tobe O <thosakwe@gmail.com>"
|
||||||
description: "Testing utility library for the Angel framework."
|
description: "Testing utility library for the Angel framework."
|
||||||
homepage: "https://github.com/angel-dart/test.git"
|
homepage: "https://github.com/angel-dart/test.git"
|
||||||
name: "angel_test"
|
name: "angel_test"
|
||||||
version: "1.0.4"
|
version: 1.0.5
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_client: "^1.0.0"
|
angel_client: "^1.0.0"
|
||||||
angel_framework: "^1.0.0-dev"
|
angel_framework: "^1.0.0-dev"
|
||||||
|
|
|
@ -30,6 +30,12 @@ main() {
|
||||||
..post('/hello', (req, res) async {
|
..post('/hello', (req, res) async {
|
||||||
return {'bar': req.body['foo']};
|
return {'bar': req.body['foo']};
|
||||||
})
|
})
|
||||||
|
..get('/gzip', (req, res) async {
|
||||||
|
res
|
||||||
|
..headers[HttpHeaders.CONTENT_ENCODING] = 'gzip'
|
||||||
|
..write(GZIP.encode('Poop'.codeUnits))
|
||||||
|
..end();
|
||||||
|
})
|
||||||
..use(
|
..use(
|
||||||
'/foo',
|
'/foo',
|
||||||
new AnonymousService(
|
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', () {
|
group('service', () {
|
||||||
test('index', () async {
|
test('index', () async {
|
||||||
var foo = client.service('foo');
|
var foo = client.service('foo');
|
||||||
var result = await foo.index();
|
var result = await foo.index();
|
||||||
expect(result, [{'michael': 'jackson'}]);
|
expect(result, [
|
||||||
|
{'michael': 'jackson'}
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('index', () async {
|
test('index', () async {
|
||||||
|
|
Loading…
Reference in a new issue