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

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

Issue 17544005: First push of a new 'http_server' dart package. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Review changes. Created 7 years, 6 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 | « pkg/http_server/pubspec.yaml ('k') | utils/apidoc/apidoc.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http_server/test/virtual_directory_test.dart
diff --git a/pkg/http_server/test/virtual_directory_test.dart b/pkg/http_server/test/virtual_directory_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..e079de8c2a1d4fbdaee31ec4dc74453a29835938
--- /dev/null
+++ b/pkg/http_server/test/virtual_directory_test.dart
@@ -0,0 +1,132 @@
+// Copyright (c) 2013, 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.
+
+import 'dart:io';
+
+import "package:unittest/unittest.dart";
+import "package:http_server/http_server.dart";
+
+
+void main() {
+ group('serve-root', () {
+ test('dir-exists', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var virDir = new VirtualDirectory(dir.path);
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost', server.port, '/')
+ .then((request) => request.close())
+ .then((response) => response.statusCode)
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync();
+ });
+ }), completion(equals(HttpStatus.NOT_FOUND)));
+ });
+
+ test('dir-not-exists', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ dir.deleteSync();
+ var virDir = new VirtualDirectory(dir.path);
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost', server.port, '/')
+ .then((request) => request.close())
+ .then((response) => response.statusCode)
+ .whenComplete(() {
+ server.close();
+ });
+ }), completion(equals(HttpStatus.NOT_FOUND)));
+ });
+ });
+
+ group('serve-file', () {
+ group('top-level', () {
+ test('file-exists', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var file = new File('${dir.path}/file')..createSync();
+ var virDir = new VirtualDirectory(dir.path);
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost', server.port, '/file')
+ .then((request) => request.close())
+ .then((response) => response.statusCode)
+ .whenComplete(() {
+ server.close();
+ file.deleteSync();
+ dir.deleteSync();
+ });
+ }), completion(equals(HttpStatus.OK)));
+ });
+
+ test('file-not-exists', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var virDir = new VirtualDirectory(dir.path);
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost', server.port, '/file')
+ .then((request) => request.close())
+ .then((response) => response.statusCode)
+ .whenComplete(() {
+ server.close();
+ dir.deleteSync();
+ });
+ }), completion(equals(HttpStatus.NOT_FOUND)));
+ });
+ });
+
+ group('in-dir', () {
+ test('file-exists', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var dir2 = new Directory('${dir.path}/dir')..createSync();
+ var file = new File('${dir2.path}/file')..createSync();
+ var virDir = new VirtualDirectory(dir.path);
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost', server.port, '/dir/file')
+ .then((request) => request.close())
+ .then((response) => response.statusCode)
+ .whenComplete(() {
+ server.close();
+ file.deleteSync();
+ dir2.deleteSync();
+ dir.deleteSync();
+ });
+ }), completion(equals(HttpStatus.OK)));
+ });
+
+ test('file-not-exists', () {
+ expect(HttpServer.bind('localhost', 0).then((server) {
+ var dir = new Directory('').createTempSync();
+ var dir2 = new Directory('${dir.path}/dir')..createSync();
+ var file = new File('${dir.path}/file')..createSync();
+ var virDir = new VirtualDirectory(dir.path);
+
+ virDir.serve(server);
+
+ return new HttpClient().get('localhost', server.port, '/dir/file')
+ .then((request) => request.close())
+ .then((response) => response.statusCode)
+ .whenComplete(() {
+ server.close();
+ file.deleteSync();
+ dir2.deleteSync();
+ dir.deleteSync();
+ });
+ }), completion(equals(HttpStatus.NOT_FOUND)));
+ });
+ });
+ });
+}
+
« no previous file with comments | « pkg/http_server/pubspec.yaml ('k') | utils/apidoc/apidoc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698