Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Unified Diff: pkg/http_server/test/utils.dart

Issue 120343005: pkg/http_server more virtual dir test cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: minimize delta Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/test/utils.dart
diff --git a/pkg/http_server/test/utils.dart b/pkg/http_server/test/utils.dart
index f1159c50acaba11cbdc3ee0b6702720637b4c8d0..76211a55d17448722c63bd5ab6df8fc8c665a465 100644
--- a/pkg/http_server/test/utils.dart
+++ b/pkg/http_server/test/utils.dart
@@ -7,6 +7,33 @@ library utils;
import 'dart:async';
import 'dart:convert';
import 'dart:io';
+import "package:unittest/unittest.dart";
+
+import 'package:http_server/http_server.dart';
+
+void testVirtualDir(String name, Future func(Directory dir)) {
+ test(name, () {
+ var dir = Directory.systemTemp.createTempSync('http_server_virtual_');
+
+ return func(dir)
+ .whenComplete(() {
+ return dir.delete(recursive: true);
+ });
+ });
+}
+
+Future<int> getStatusCodeForVirtDir(VirtualDirectory virtualDir,
+ String path,
Anders Johnsen 2014/01/07 07:42:10 Indentation
kevmoo 2014/01/07 19:36:52 Done.
+ {String host,
+ bool secure: false,
+ DateTime ifModifiedSince,
+ bool rawPath: false}) =>
+ _withServer((server) {
+
+ virtualDir.serve(server);
+ return getStatusCode(server.port, path, host: host, secure: secure,
+ ifModifiedSince: ifModifiedSince, rawPath: rawPath);
+ });
Future<int> getStatusCode(int port,
String path,
@@ -38,21 +65,35 @@ Future<int> getStatusCode(int port,
(_) => response.statusCode));
}
+Future<HttpHeaders> getHeaders(VirtualDirectory virDir, String path) =>
Anders Johnsen 2014/01/07 07:42:10 Please use { ... } for multiline body.
kevmoo 2014/01/07 19:36:52 Done.
+ _withServer((server) {
+ virDir.serve(server);
-Future<HttpHeaders> getHeaders(int port, String path) =>
- new HttpClient()
- .get('localhost', port, path)
- .then((request) => request.close())
- .then((response) => response.drain().then(
- (_) => response.headers));
+ return new HttpClient()
+ .get('localhost', server.port, path)
+ .then((request) => request.close())
+ .then((response) => response.drain().then((_) => response.headers));
+ });
+Future<String> getAsString(VirtualDirectory virtualDir, String path) =>
+ _withServer((server) {
+ virtualDir.serve(server);
+ return new HttpClient()
+ .get('localhost', server.port, path)
+ .then((request) => request.close())
+ .then((response) => UTF8.decodeStream(response));
+ });
-Future<String> getAsString(int port, String path) =>
- new HttpClient()
- .get('localhost', port, path)
- .then((request) => request.close())
- .then((response) => UTF8.decodeStream(response));
+Future _withServer(Future func(HttpServer server)) {
Anders Johnsen 2014/01/07 07:42:10 Consider: { return HttpServer.bind('localhost',
kevmoo 2014/01/07 19:36:52 I'll argue against this. If func throws an error
+ HttpServer server;
+ return HttpServer.bind('localhost', 0)
+ .then((value) {
+ server = value;
+ return func(server);
+ })
+ .whenComplete(() => server.close());
+}
const CERTIFICATE = "localhost_cert";
« no previous file with comments | « no previous file | pkg/http_server/test/virtual_directory_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698