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