Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, 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 | |
| 3 // BSD-style license that can be found in the LICENSE d.file. | |
| 4 | |
| 5 library pub_tests; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'dart:io'; | |
| 9 | |
| 10 import 'package:http/http.dart' as http; | |
| 11 import 'package:scheduled_test/scheduled_process.dart'; | |
| 12 import 'package:scheduled_test/scheduled_test.dart'; | |
| 13 | |
| 14 import '../descriptor.dart' as d; | |
| 15 import '../test_pub.dart'; | |
| 16 | |
| 17 /// The pub process running "pub serve". | |
| 18 ScheduledProcess _pubServer; | |
| 19 | |
| 20 /// The ephemeral port assigned to the running server. | |
| 21 int _port; | |
| 22 | |
| 23 /// Schedules starting the "pub serve" process. | |
| 24 void startPubServe() { | |
| 25 // Use port 0 to get an ephemeral port. | |
| 26 _pubServer = startPub(args: ["serve", "--port=0"]); | |
| 27 | |
| 28 schedule(() => _pubServer.nextLine().then((line) { | |
|
nweiz
2013/07/25 22:58:58
[ScheduledProcess.nextLine] is automatically sched
Bob Nystrom
2013/07/26 20:20:11
Done.
| |
| 29 var match = new RegExp(r"localhost:(\d+)\.").firstMatch(line); | |
| 30 assert(match != null); | |
| 31 _port = int.parse(match[1]); | |
| 32 }), "wait for pub server to start"); | |
| 33 } | |
| 34 | |
| 35 void endPubServe() { | |
| 36 _pubServer.kill(); | |
| 37 } | |
| 38 | |
| 39 /// Schedules an HTTP request to the running pub server with [urlPath] and | |
| 40 /// verifies that it responds with [expected]. | |
| 41 void requestShouldSucceed(String urlPath, String expected) { | |
| 42 schedule(() { | |
| 43 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | |
| 44 expect(response.body, equals(expected)); | |
| 45 }); | |
| 46 }, "request $urlPath"); | |
| 47 } | |
| 48 | |
| 49 /// Schedules an HTTP request to the running pub server with [urlPath] and | |
| 50 /// verifies that it responds with a 404. | |
| 51 void requestShould404(String urlPath) { | |
| 52 schedule(() { | |
| 53 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | |
| 54 expect(response.statusCode, equals(404)); | |
| 55 }); | |
| 56 }, "request $urlPath"); | |
| 57 } | |
| OLD | NEW |