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.request_test; | 5 library shelf.request_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:shelf/shelf.dart'; | 9 import 'package:shelf/shelf.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 test("comes from the Last-Modified header", () { | 130 test("comes from the Last-Modified header", () { |
131 var request = _request({ | 131 var request = _request({ |
132 'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT' | 132 'if-modified-since': 'Sun, 06 Nov 1994 08:49:37 GMT' |
133 }); | 133 }); |
134 expect(request.ifModifiedSince, | 134 expect(request.ifModifiedSince, |
135 equals(DateTime.parse("1994-11-06 08:49:37z"))); | 135 equals(DateTime.parse("1994-11-06 08:49:37z"))); |
136 }); | 136 }); |
137 }); | 137 }); |
138 | 138 |
139 group("readAsString", () { | 139 group('change', () { |
140 test("supports a null body", () { | 140 test('with no arguments returns instance with equal values', () { |
141 var request = _request(); | 141 var controller = new StreamController(); |
142 expect(request.readAsString(), completion(equals(""))); | |
143 }); | |
144 | 142 |
145 test("supports a Stream<List<int>> body", () { | 143 var uri = Uri.parse('https://test.example.com/static/file.html'); |
146 var controller = new StreamController(); | |
147 var request = _request({}, controller.stream); | |
148 expect(request.readAsString(), completion(equals("hello, world"))); | |
149 | 144 |
150 controller.add([104, 101, 108, 108, 111, 44]); | 145 var request = new Request('GET', uri, |
| 146 protocolVersion: '2.0', |
| 147 headers: {'header1': 'header value 1'}, |
| 148 url: Uri.parse('/file.html'), |
| 149 scriptName: '/static', |
| 150 body: controller.stream, |
| 151 context: {'context1': 'context value 1'}); |
| 152 |
| 153 var copy = request.change(); |
| 154 |
| 155 expect(copy.method, request.method); |
| 156 expect(copy.requestedUri, request.requestedUri); |
| 157 expect(copy.protocolVersion, request.protocolVersion); |
| 158 expect(copy.headers, same(request.headers)); |
| 159 expect(copy.url, request.url); |
| 160 expect(copy.scriptName, request.scriptName); |
| 161 expect(copy.context, same(request.context)); |
| 162 expect(copy.readAsString(), completion('hello, world')); |
| 163 |
| 164 controller.add(HELLO_BYTES); |
151 return new Future(() { | 165 return new Future(() { |
152 controller | 166 controller |
153 ..add([32, 119, 111, 114, 108, 100]) | 167 ..add(WORLD_BYTES) |
154 ..close(); | 168 ..close(); |
155 }); | 169 }); |
156 }); | 170 }); |
157 }); | |
158 | |
159 group("read", () { | |
160 test("supports a null body", () { | |
161 var request = _request(); | |
162 expect(request.read().toList(), completion(isEmpty)); | |
163 }); | |
164 | |
165 test("supports a Stream<List<int>> body", () { | |
166 var controller = new StreamController(); | |
167 var request = _request({}, controller.stream); | |
168 expect(request.read().toList(), completion(equals([ | |
169 [104, 101, 108, 108, 111, 44], | |
170 [32, 119, 111, 114, 108, 100] | |
171 ]))); | |
172 | |
173 controller.add([104, 101, 108, 108, 111, 44]); | |
174 return new Future(() { | |
175 controller | |
176 ..add([32, 119, 111, 114, 108, 100]) | |
177 ..close(); | |
178 }); | |
179 }); | |
180 }); | 171 }); |
181 } | 172 } |
OLD | NEW |