| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. |
| 172 void requestShouldSucceed(String urlPath, expectation) { | 172 /// [headers] may be either a [Matcher] or a map to match an exact headers map. |
| 173 void requestShouldSucceed(String urlPath, expectation, {headers}) { |
| 173 schedule(() { | 174 schedule(() { |
| 174 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | 175 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { |
| 175 expect(response.body, expectation); | 176 if (expectation != null) expect(response.body, expectation); |
| 177 if (headers != null) expect(response.headers, headers); |
| 176 }); | 178 }); |
| 177 }, "request $urlPath"); | 179 }, "request $urlPath"); |
| 178 } | 180 } |
| 179 | 181 |
| 180 /// Schedules an HTTP request to the running pub server with [urlPath] and | 182 /// Schedules an HTTP request to the running pub server with [urlPath] and |
| 181 /// verifies that it responds with a 404. | 183 /// verifies that it responds with a 404. |
| 182 void requestShould404(String urlPath) { | 184 void requestShould404(String urlPath) { |
| 183 schedule(() { | 185 schedule(() { |
| 184 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { | 186 return http.get("http://127.0.0.1:$_port/$urlPath").then((response) { |
| 185 expect(response.statusCode, equals(404)); | 187 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. | 242 /// socket. It omitted, request is JSON encoded to a string first. |
| 241 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { | 243 void webSocketShouldReply(request, expectation, {bool encodeRequest: true}) { |
| 242 schedule(() => _ensureWebSocket().then((_) { | 244 schedule(() => _ensureWebSocket().then((_) { |
| 243 if (encodeRequest) request = JSON.encode(request); | 245 if (encodeRequest) request = JSON.encode(request); |
| 244 _webSocket.add(request); | 246 _webSocket.add(request); |
| 245 return _webSocketBroadcastStream.first.then((value) { | 247 return _webSocketBroadcastStream.first.then((value) { |
| 246 expect(JSON.decode(value), expectation); | 248 expect(JSON.decode(value), expectation); |
| 247 }); | 249 }); |
| 248 }), "send $request to web socket and expect reply that $expectation"); | 250 }), "send $request to web socket and expect reply that $expectation"); |
| 249 } | 251 } |
| OLD | NEW |