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 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 _port = int.parse(match[1]); | 161 _port = int.parse(match[1]); |
162 } | 162 } |
163 | 163 |
164 void endPubServe() { | 164 void endPubServe() { |
165 _pubServer.kill(); | 165 _pubServer.kill(); |
166 } | 166 } |
167 | 167 |
168 /// Schedules an HTTP request to the running pub server with [urlPath] and | 168 /// Schedules an HTTP request to the running pub server with [urlPath] and |
169 /// verifies that it responds with a body that matches [expectation]. | 169 /// verifies that it responds with a body that matches [expectation]. |
170 /// | 170 /// |
171 /// [expectation] may either be a [Matcher] or a string to match an exact body. | 171 /// [expectation] may either be a [Matcher] or a string to match an exact body. |
Bob Nystrom
2014/02/11 19:11:14
Doc what types header can be.
nweiz
2014/02/11 21:45:48
Done.
| |
172 void requestShouldSucceed(String urlPath, expectation) { | 172 void requestShouldSucceed(String urlPath, expectation, {headers}) { |
173 schedule(() { | 173 schedule(() { |
174 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | 174 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { |
175 expect(response.body, expectation); | 175 if (expectation != null) expect(response.body, expectation); |
176 if (headers != null) expect(response.headers, headers); | |
176 }); | 177 }); |
177 }, "request $urlPath"); | 178 }, "request $urlPath"); |
178 } | 179 } |
179 | 180 |
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)); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 /// socket. It omitted, request is JSON encoded to a string first. | 241 /// socket. It omitted, request is JSON encoded to a string first. |
241 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { | 242 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { |
242 schedule(() => _ensureWebSocket().then((_) { | 243 schedule(() => _ensureWebSocket().then((_) { |
243 if (encodeRequest) request = JSON.encode(request); | 244 if (encodeRequest) request = JSON.encode(request); |
244 _webSocket.add(request); | 245 _webSocket.add(request); |
245 return _webSocketBroadcastStream.first.then((value) { | 246 return _webSocketBroadcastStream.first.then((value) { |
246 expect(JSON.decode(value), expectation); | 247 expect(JSON.decode(value), expectation); |
247 }); | 248 }); |
248 }), "send $request to web socket and expect reply that $expectation"); | 249 }), "send $request to web socket and expect reply that $expectation"); |
249 } | 250 } |
OLD | NEW |