Chromium Code Reviews| 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 | 8 |
| 9 import 'package:http/http.dart' as http; | 9 import 'package:http/http.dart' as http; |
| 10 import 'package:scheduled_test/scheduled_process.dart'; | 10 import 'package:scheduled_test/scheduled_process.dart'; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 assert(match != null); | 114 assert(match != null); |
| 115 _port = int.parse(match[1]); | 115 _port = int.parse(match[1]); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void endPubServe() { | 118 void endPubServe() { |
| 119 _pubServer.kill(); | 119 _pubServer.kill(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 /// Schedules an HTTP request to the running pub server with [urlPath] and | 122 /// Schedules an HTTP request to the running pub server with [urlPath] and |
| 123 /// verifies that it responds with [expected]. | 123 /// verifies that it responds with [expected]. |
| 124 void requestShouldSucceed(String urlPath, String expected) { | 124 void requestShouldSucceed(String urlPath, Pattern expected) { |
| 125 // RegExps are matched, everything else must be equal. Note that we can't use | |
|
nweiz
2013/09/27 22:21:17
At this point, it's probably cleaner to make [expe
Bob Nystrom
2013/09/28 00:56:11
Most of the tests are testing for exact quality, a
nweiz
2013/09/30 17:33:34
Passing in a string will implicitly call [equals];
Bob Nystrom
2013/10/01 19:08:55
OK, done. I didn't do that before because I though
| |
| 126 // matches() for a String because we want a String to mean "is exactly that" | |
| 127 // where matches() implicitly converts it to a RegExp. | |
| 128 var expectation; | |
| 129 if (expected is RegExp) { | |
| 130 expectation = matches(expected); | |
| 131 } else { | |
| 132 expectation = equals(expected); | |
| 133 } | |
| 134 | |
| 125 schedule(() { | 135 schedule(() { |
| 126 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | 136 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { |
| 127 expect(response.body, equals(expected)); | 137 expect(response.body, expectation); |
| 128 }); | 138 }); |
| 129 }, "request $urlPath"); | 139 }, "request $urlPath"); |
| 130 } | 140 } |
| 131 | 141 |
| 132 /// Schedules an HTTP request to the running pub server with [urlPath] and | 142 /// Schedules an HTTP request to the running pub server with [urlPath] and |
| 133 /// verifies that it responds with a 404. | 143 /// verifies that it responds with a 404. |
| 134 void requestShould404(String urlPath) { | 144 void requestShould404(String urlPath) { |
| 135 schedule(() { | 145 schedule(() { |
| 136 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | 146 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { |
| 137 expect(response.statusCode, equals(404)); | 147 expect(response.statusCode, equals(404)); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 159 return _pubServer.nextLine().then((line) { | 169 return _pubServer.nextLine().then((line) { |
| 160 if (line.contains("successfully")) return; | 170 if (line.contains("successfully")) return; |
| 161 | 171 |
| 162 // This line wasn't it, so ignore it and keep trying. | 172 // This line wasn't it, so ignore it and keep trying. |
| 163 return nextLine(); | 173 return nextLine(); |
| 164 }); | 174 }); |
| 165 } | 175 } |
| 166 | 176 |
| 167 schedule(nextLine); | 177 schedule(nextLine); |
| 168 } | 178 } |
| OLD | NEW |