OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 @TestOn('vm') |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:io'; |
| 9 |
| 10 import 'package:http/http.dart' as http; |
| 11 import 'package:shelf/shelf_io.dart'; |
| 12 import 'package:test/test.dart'; |
| 13 |
| 14 import 'test_util.dart'; |
| 15 |
| 16 void main() { |
| 17 var server; |
| 18 setUp(() async { |
| 19 server = await IOServer.bind(InternetAddress.LOOPBACK_IP_V4, 0); |
| 20 }); |
| 21 |
| 22 tearDown(() => server.close()); |
| 23 |
| 24 test("serves HTTP requests with the mounted handler", () async { |
| 25 server.mount(syncHandler); |
| 26 expect(await http.read(server.url), equals('Hello from /')); |
| 27 }); |
| 28 |
| 29 test("delays HTTP requests until a handler is mounted", () async { |
| 30 expect(http.read(server.url), completion(equals('Hello from /'))); |
| 31 await new Future.delayed(Duration.ZERO); |
| 32 |
| 33 server.mount(asyncHandler); |
| 34 }); |
| 35 |
| 36 test("disallows more than one handler from being mounted", () async { |
| 37 server.mount((_) {}); |
| 38 expect(() => server.mount((_) {}), throwsStateError); |
| 39 expect(() => server.mount((_) {}), throwsStateError); |
| 40 }); |
| 41 } |
OLD | NEW |