OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS 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 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub | 5 /// Test infrastructure for testing pub. Unlike typical unit tests, most pub |
6 /// tests are integration tests that stage some stuff on the file system, run | 6 /// tests are integration tests that stage some stuff on the file system, run |
7 /// pub, and then validate the results. This library provides an API to build | 7 /// pub, and then validate the results. This library provides an API to build |
8 /// tests like that. | 8 /// tests like that. |
9 library test_pub; | 9 library test_pub; |
10 | 10 |
(...skipping 1429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 return new Future.immediate(server); | 1440 return new Future.immediate(server); |
1441 })); | 1441 })); |
1442 return scheduledServer; | 1442 return scheduledServer; |
1443 } | 1443 } |
1444 | 1444 |
1445 /// The port on which the server is listening. | 1445 /// The port on which the server is listening. |
1446 Future<int> get port => _server.then((s) => s.port); | 1446 Future<int> get port => _server.then((s) => s.port); |
1447 | 1447 |
1448 /// The base URL of the server, including its port. | 1448 /// The base URL of the server, including its port. |
1449 Future<Uri> get url => | 1449 Future<Uri> get url => |
1450 port.then((p) => new Uri.fromString("http://localhost:$p")); | 1450 port.then((p) => Uri.parse("http://localhost:$p")); |
1451 | 1451 |
1452 /// Assert that the next request has the given [method] and [path], and pass | 1452 /// Assert that the next request has the given [method] and [path], and pass |
1453 /// it to [handler] to handle. If [handler] returns a [Future], wait until | 1453 /// it to [handler] to handle. If [handler] returns a [Future], wait until |
1454 /// it's completed to continue the schedule. | 1454 /// it's completed to continue the schedule. |
1455 void handle(String method, String path, | 1455 void handle(String method, String path, |
1456 Future handler(HttpRequest request, HttpResponse response)) { | 1456 Future handler(HttpRequest request, HttpResponse response)) { |
1457 var handlerCompleter = new Completer<Function>(); | 1457 var handlerCompleter = new Completer<Function>(); |
1458 _scheduleValue((_) { | 1458 _scheduleValue((_) { |
1459 var requestCompleteCompleter = new Completer(); | 1459 var requestCompleteCompleter = new Completer(); |
1460 handlerCompleter.complete((request, response) { | 1460 handlerCompleter.complete((request, response) { |
1461 expect(request.method, equals(method)); | 1461 expect(request.method, equals(method)); |
1462 // TODO(nweiz): Use request.path once issue 7464 is fixed. | 1462 // TODO(nweiz): Use request.path once issue 7464 is fixed. |
1463 expect(new Uri.fromString(request.uri).path, equals(path)); | 1463 expect(Uri.parse(request.uri).path, equals(path)); |
1464 | 1464 |
1465 var future = handler(request, response); | 1465 var future = handler(request, response); |
1466 if (future == null) future = new Future.immediate(null); | 1466 if (future == null) future = new Future.immediate(null); |
1467 chainToCompleter(future, requestCompleteCompleter); | 1467 chainToCompleter(future, requestCompleteCompleter); |
1468 }); | 1468 }); |
1469 return timeout(requestCompleteCompleter.future, | 1469 return timeout(requestCompleteCompleter.future, |
1470 _SCHEDULE_TIMEOUT, "waiting for $method $path"); | 1470 _SCHEDULE_TIMEOUT, "waiting for $method $path"); |
1471 }); | 1471 }); |
1472 _handlers.add(handlerCompleter.future); | 1472 _handlers.add(handlerCompleter.future); |
1473 } | 1473 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1557 /// calling [completion] is unnecessary. | 1557 /// calling [completion] is unnecessary. |
1558 void expectLater(Future actual, matcher, {String reason, | 1558 void expectLater(Future actual, matcher, {String reason, |
1559 FailureHandler failureHandler, bool verbose: false}) { | 1559 FailureHandler failureHandler, bool verbose: false}) { |
1560 _schedule((_) { | 1560 _schedule((_) { |
1561 return actual.then((value) { | 1561 return actual.then((value) { |
1562 expect(value, matcher, reason: reason, failureHandler: failureHandler, | 1562 expect(value, matcher, reason: reason, failureHandler: failureHandler, |
1563 verbose: false); | 1563 verbose: false); |
1564 }); | 1564 }); |
1565 }); | 1565 }); |
1566 } | 1566 } |
OLD | NEW |