Chromium Code Reviews| Index: pkg/shelf/test/request_test.dart |
| diff --git a/pkg/shelf/test/request_test.dart b/pkg/shelf/test/request_test.dart |
| index 72a87a6b32675f02ea1ae0b32923792a95691bf1..ce38594fd9b4f072b3a0e4e2563adf1a7db0638c 100644 |
| --- a/pkg/shelf/test/request_test.dart |
| +++ b/pkg/shelf/test/request_test.dart |
| @@ -147,10 +147,10 @@ void main() { |
| var request = _request({}, controller.stream); |
| expect(request.readAsString(), completion(equals("hello, world"))); |
| - controller.add([104, 101, 108, 108, 111, 44]); |
| + controller.add(_HELLO_BYTES); |
| return new Future(() { |
| controller |
| - ..add([32, 119, 111, 114, 108, 100]) |
| + ..add(_WORLD_BYTES) |
| ..close(); |
| }); |
| }); |
| @@ -166,16 +166,108 @@ void main() { |
| var controller = new StreamController(); |
| var request = _request({}, controller.stream); |
| expect(request.read().toList(), completion(equals([ |
| - [104, 101, 108, 108, 111, 44], |
| - [32, 119, 111, 114, 108, 100] |
| + _HELLO_BYTES, |
| + _WORLD_BYTES |
| ]))); |
| - controller.add([104, 101, 108, 108, 111, 44]); |
| + controller.add(_HELLO_BYTES); |
| return new Future(() { |
| controller |
| - ..add([32, 119, 111, 114, 108, 100]) |
| + ..add(_WORLD_BYTES) |
| ..close(); |
| }); |
| }); |
| }); |
| + |
| + group('copy', () { |
| + test('with no arguments returns identical instance', () { |
| + var controller = new StreamController(); |
| + |
| + var uri = Uri.parse('https://test.example.com/static/file.html'); |
| + |
| + var request = new Request('GET', uri, |
| + protocolVersion: '2.0', |
| + headers: {'header1': 'header value 1'}, |
| + url: Uri.parse('/file.html'), |
| + scriptName: '/static', |
| + body: controller.stream, |
| + context: {'context1': 'context value 1'}); |
| + |
| + var copy = request.copy(); |
| + |
| + expect(copy.method, request.method); |
| + expect(copy.requestedUri, request.requestedUri); |
| + expect(copy.protocolVersion, request.protocolVersion); |
| + expect(copy.headers, request.headers); |
| + expect(copy.url, request.url); |
| + expect(copy.scriptName, request.scriptName); |
| + expect(copy.context, request.context); |
| + expect(copy.readAsString(), completion('hello, world')); |
| + |
| + controller.add(_HELLO_BYTES); |
| + return new Future(() { |
| + controller |
| + ..add(_WORLD_BYTES) |
| + ..close(); |
| + }); |
| + }); |
| + |
| + test('with empty headers returns indentical instance', () { |
|
nweiz
2014/04/28 22:13:33
"indentical" -> "identical"
This also doesn't tes
kevmoo
2014/04/29 10:41:54
Done.
|
| + var request = new Request('GET', LOCALHOST_URI, |
| + headers: {'header1': 'header value 1'}); |
| + var copy = request.copy(headers: {}); |
| + |
| + expect(copy.headers, request.headers); |
| + }); |
| + |
| + test('with empty context returns identical instance', () { |
| + var request = new Request('GET', LOCALHOST_URI, |
| + context: {'context1': 'context value 1'}); |
| + var copy = request.copy(context: {}); |
| + |
| + expect(copy.context, request.context); |
| + }); |
| + |
| + test('new header values are added', () { |
| + var request = new Request('GET', LOCALHOST_URI, |
| + headers: {'test':'test value'}); |
| + |
| + var copy = request.copy(headers: {'test2': 'test2 value'}); |
| + |
| + expect(copy.headers, {'test':'test value', 'test2':'test2 value'}); |
| + }); |
| + |
| + test('existing header values are overwritten', () { |
| + var request = new Request('GET', LOCALHOST_URI, |
| + headers: {'test':'test value'}); |
| + |
| + var copy = request.copy(headers: {'test': 'new test value'}); |
| + |
| + expect(copy.headers, {'test':'new test value'}); |
| + }); |
| + |
| + test('new context values are added', () { |
| + var request = new Request('GET', LOCALHOST_URI, |
| + context: {'test':'test value'}); |
| + |
| + var copy = request.copy(context: {'test2': 'test2 value'}); |
| + |
| + expect(copy.context, {'test':'test value', 'test2':'test2 value'}); |
| + }); |
| + |
| + test('existing context values are overwritten', () { |
| + var request = new Request('GET', LOCALHOST_URI, |
| + context: {'test':'test value'}); |
| + |
| + var copy = request.copy(context: {'test': 'new test value'}); |
| + |
| + expect(copy.context, {'test':'new test value'}); |
| + }); |
| + }); |
| } |
| + |
| +// "hello," |
| +const _HELLO_BYTES = const [104, 101, 108, 108, 111, 44]; |
| + |
| +// " world" |
| +const _WORLD_BYTES = const [32, 119, 111, 114, 108, 100]; |
|
nweiz
2014/04/28 22:13:33
Constants go at the top of the file.
kevmoo
2014/04/29 10:41:54
Done.
|