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

Unified Diff: test/io_server_test.dart

Issue 1411553006: Add a Server interface. (Closed) Base URL: git@github.com:dart-lang/shelf@master
Patch Set: Created 5 years, 2 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
Index: test/io_server_test.dart
diff --git a/test/io_server_test.dart b/test/io_server_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7ead481458895ab9e2d284338ead88e7e797d76f
--- /dev/null
+++ b/test/io_server_test.dart
@@ -0,0 +1,42 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+@TestOn('vm')
+
+import 'dart:async';
+import 'dart:io';
+
+import 'package:http/http.dart' as http;
+import 'package:shelf/shelf.dart';
kevmoo 2015/10/22 00:44:26 unused import
nweiz 2015/10/26 21:32:44 Done.
+import 'package:shelf/shelf_io.dart';
+import 'package:test/test.dart';
+
+import 'test_util.dart';
+
+void main() {
+ var server;
kevmoo 2015/10/22 00:44:26 type things when there is no way for inference to
nweiz 2015/10/26 21:32:44 This is a test—if there are bugs the tests will fa
+ setUp(() async {
+ server = await IOServer.bind(InternetAddress.LOOPBACK_IP_V4, 0);
+ });
+
+ tearDown(() => server.close());
+
+ test("serves HTTP requests with the mounted handler", () async {
+ server.mount(syncHandler);
+ expect(await http.read(server.url), equals('Hello from /'));
+ });
+
+ test("delays HTTP requests until a handler is mounted", () async {
+ expect(http.read(server.url), completion(equals('Hello from /')));
+ await new Future.delayed(Duration.ZERO);
+
+ server.mount(asyncHandler);
+ });
+
+ test("disallows more than one handler from being mounted", () async {
+ server.mount((_) {});
+ expect(() => server.mount((_) {}), throwsStateError);
kevmoo 2015/10/22 00:44:26 actually check for your StateError message – since
nweiz 2015/10/26 21:32:44 Checking for specific messages in tests is general
+ expect(() => server.mount((_) {}), throwsStateError);
+ });
+}
« lib/src/server_handler.dart ('K') | « pubspec.yaml ('k') | test/server_handler_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698