| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library shelf.message_change_test; | 5 library shelf.message_change_test; |
| 6 | 6 |
| 7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
| 8 | 8 |
| 9 import 'package:shelf/shelf.dart'; | 9 import 'package:shelf/shelf.dart'; |
| 10 import 'package:shelf/src/message.dart'; | 10 import 'package:shelf/src/message.dart'; |
| 11 | 11 |
| 12 import 'test_util.dart'; | 12 import 'test_util.dart'; |
| 13 | 13 |
| 14 void main() { | 14 void main() { |
| 15 group('Request', () { | 15 group('Request', () { |
| 16 _testChange(({headers, context}) { | 16 _testChange(({headers, context}) { |
| 17 return new Request('GET', LOCALHOST_URI, headers: headers, | 17 return new Request('GET', LOCALHOST_URI, |
| 18 context: context); | 18 headers: headers, context: context); |
| 19 }); | 19 }); |
| 20 }); | 20 }); |
| 21 | 21 |
| 22 group('Response', () { | 22 group('Response', () { |
| 23 _testChange(({headers, context}) { | 23 _testChange(({headers, context}) { |
| 24 return new Response.ok(null, headers: headers, | 24 return new Response.ok(null, headers: headers, context: context); |
| 25 context: context); | |
| 26 }); | 25 }); |
| 27 }); | 26 }); |
| 28 } | 27 } |
| 29 | 28 |
| 30 /// Shared test method used by [Request] and [Response] tests to validate | 29 /// Shared test method used by [Request] and [Response] tests to validate |
| 31 /// the behavior of `change` with different `headers` and `context` values. | 30 /// the behavior of `change` with different `headers` and `context` values. |
| 32 void _testChange(Message factory({Map<String, String> headers, | 31 void _testChange(Message factory( |
| 33 Map<String, Object> context})) { | 32 {Map<String, String> headers, Map<String, Object> context})) { |
| 34 test('with empty headers returns indentical instance', () { | 33 test('with empty headers returns indentical instance', () { |
| 35 var request = factory(headers: {'header1': 'header value 1'}); | 34 var request = factory(headers: {'header1': 'header value 1'}); |
| 36 var copy = request.change(headers: {}); | 35 var copy = request.change(headers: {}); |
| 37 | 36 |
| 38 expect(copy.headers, same(request.headers)); | 37 expect(copy.headers, same(request.headers)); |
| 39 }); | 38 }); |
| 40 | 39 |
| 41 test('with empty context returns identical instance', () { | 40 test('with empty context returns identical instance', () { |
| 42 var request = factory(context: {'context1': 'context value 1'}); | 41 var request = factory(context: {'context1': 'context value 1'}); |
| 43 var copy = request.change(context: {}); | 42 var copy = request.change(context: {}); |
| 44 | 43 |
| 45 expect(copy.context, same(request.context)); | 44 expect(copy.context, same(request.context)); |
| 46 }); | 45 }); |
| 47 | 46 |
| 48 test('new header values are added', () { | 47 test('new header values are added', () { |
| 49 var request = factory(headers: {'test':'test value'}); | 48 var request = factory(headers: {'test': 'test value'}); |
| 50 var copy = request.change(headers: {'test2': 'test2 value'}); | 49 var copy = request.change(headers: {'test2': 'test2 value'}); |
| 51 | 50 |
| 52 expect(copy.headers, {'test':'test value', 'test2':'test2 value'}); | 51 expect(copy.headers, {'test': 'test value', 'test2': 'test2 value'}); |
| 53 }); | 52 }); |
| 54 | 53 |
| 55 test('existing header values are overwritten', () { | 54 test('existing header values are overwritten', () { |
| 56 var request = factory(headers: {'test':'test value'}); | 55 var request = factory(headers: {'test': 'test value'}); |
| 57 var copy = request.change(headers: {'test': 'new test value'}); | 56 var copy = request.change(headers: {'test': 'new test value'}); |
| 58 | 57 |
| 59 expect(copy.headers, {'test':'new test value'}); | 58 expect(copy.headers, {'test': 'new test value'}); |
| 60 }); | 59 }); |
| 61 | 60 |
| 62 test('new context values are added', () { | 61 test('new context values are added', () { |
| 63 var request = factory(context: {'test':'test value'}); | 62 var request = factory(context: {'test': 'test value'}); |
| 64 var copy = request.change(context: {'test2': 'test2 value'}); | 63 var copy = request.change(context: {'test2': 'test2 value'}); |
| 65 | 64 |
| 66 expect(copy.context, {'test':'test value', 'test2':'test2 value'}); | 65 expect(copy.context, {'test': 'test value', 'test2': 'test2 value'}); |
| 67 }); | 66 }); |
| 68 | 67 |
| 69 test('existing context values are overwritten', () { | 68 test('existing context values are overwritten', () { |
| 70 var request = factory(context: {'test':'test value'}); | 69 var request = factory(context: {'test': 'test value'}); |
| 71 var copy = request.change(context: {'test': 'new test value'}); | 70 var copy = request.change(context: {'test': 'new test value'}); |
| 72 | 71 |
| 73 expect(copy.context, {'test':'new test value'}); | 72 expect(copy.context, {'test': 'new test value'}); |
| 74 }); | 73 }); |
| 75 } | 74 } |
| OLD | NEW |