OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS d.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 pub_tests; | 5 library pub_tests; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 | 10 |
11 import 'package:http/http.dart' as http; | 11 import 'package:http/http.dart' as http; |
12 import 'package:path/path.dart' as p; | |
12 import 'package:scheduled_test/scheduled_process.dart'; | 13 import 'package:scheduled_test/scheduled_process.dart'; |
13 import 'package:scheduled_test/scheduled_test.dart'; | 14 import 'package:scheduled_test/scheduled_test.dart'; |
14 | 15 |
15 import '../test_pub.dart'; | 16 import '../test_pub.dart'; |
16 | 17 |
17 /// The pub process running "pub serve". | 18 /// The pub process running "pub serve". |
18 ScheduledProcess _pubServer; | 19 ScheduledProcess _pubServer; |
19 | 20 |
20 /// The ephemeral port assigned to the running server. | 21 /// The ephemeral port assigned to the running server. |
21 int _port; | 22 int _port; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
180 /// Schedules an HTTP request to the running pub server with [urlPath] and | 181 /// Schedules an HTTP request to the running pub server with [urlPath] and |
181 /// verifies that it responds with a 404. | 182 /// verifies that it responds with a 404. |
182 void requestShould404(String urlPath) { | 183 void requestShould404(String urlPath) { |
183 schedule(() { | 184 schedule(() { |
184 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | 185 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { |
185 expect(response.statusCode, equals(404)); | 186 expect(response.statusCode, equals(404)); |
186 }); | 187 }); |
187 }, "request $urlPath"); | 188 }, "request $urlPath"); |
188 } | 189 } |
189 | 190 |
191 /// Schedules an HTTP request to the running pub server with [urlPath] and | |
192 /// verifies that it responds with a redirect to the given [redirectTarget]. | |
193 /// | |
194 /// [redirectTarget] may be either a [Matcher] or a string to match an exact | |
195 /// URL. | |
196 void requestShouldRedirect(String urlPath, redirectTarget) { | |
197 schedule(() { | |
198 var request = new http.Request("GET", | |
199 Uri.parse("http://127.0.0.1:$_port/$urlPath")); | |
200 request.followRedirects = false; | |
201 return request.send().then((response) { | |
202 expect((response.statusCode / 100).floor(), equals(3)); | |
Bob Nystrom
2014/02/11 19:18:17
Why not test for the specific status code?
If you
nweiz
2014/02/11 22:13:41
Because any 30* code is a valid redirect. I didn't
| |
203 | |
204 expect(response.headers, containsPair('location', redirectTarget)); | |
205 }); | |
206 }, "request $urlPath"); | |
207 } | |
208 | |
190 /// Schedules an HTTP POST to the running pub server with [urlPath] and verifies | 209 /// Schedules an HTTP POST to the running pub server with [urlPath] and verifies |
191 /// that it responds with a 405. | 210 /// that it responds with a 405. |
192 void postShould405(String urlPath) { | 211 void postShould405(String urlPath) { |
193 schedule(() { | 212 schedule(() { |
194 return http.post("http://127.0.0.1:$_port/$urlPath").then((response) { | 213 return http.post("http://127.0.0.1:$_port/$urlPath").then((response) { |
195 expect(response.statusCode, equals(405)); | 214 expect(response.statusCode, equals(405)); |
196 }); | 215 }); |
197 }, "request $urlPath"); | 216 }, "request $urlPath"); |
198 } | 217 } |
199 | 218 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 /// socket. It omitted, request is JSON encoded to a string first. | 259 /// socket. It omitted, request is JSON encoded to a string first. |
241 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { | 260 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { |
242 schedule(() => _ensureWebSocket().then((_) { | 261 schedule(() => _ensureWebSocket().then((_) { |
243 if (encodeRequest) request = JSON.encode(request); | 262 if (encodeRequest) request = JSON.encode(request); |
244 _webSocket.add(request); | 263 _webSocket.add(request); |
245 return _webSocketBroadcastStream.first.then((value) { | 264 return _webSocketBroadcastStream.first.then((value) { |
246 expect(JSON.decode(value), expectation); | 265 expect(JSON.decode(value), expectation); |
247 }); | 266 }); |
248 }), "send $request to web socket and expect reply that $expectation"); | 267 }), "send $request to web socket and expect reply that $expectation"); |
249 } | 268 } |
OLD | NEW |