Chromium Code Reviews| Index: pkg/http/test/http_test.dart |
| diff --git a/pkg/http/test/http_test.dart b/pkg/http/test/http_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6122b4a51e129b56050d3348e38b889895e15e91 |
| --- /dev/null |
| +++ b/pkg/http/test/http_test.dart |
| @@ -0,0 +1,173 @@ |
| +// Copyright (c) 2012, 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. |
| + |
| +library http_test; |
| + |
| +import 'dart:io'; |
| + |
| +import '../../unittest/unittest.dart'; |
| +import '../lib/http.dart' as http; |
| +import 'utils.dart'; |
| + |
| +main() { |
| + group('http.', () { |
|
Bob Nystrom
2012/10/31 01:17:44
These tests are great, but how about some failure
nweiz
2012/10/31 18:20:59
I've added some tests for the HttpException that w
|
| + setUp(startServer); |
| + tearDown(stopServer); |
| + |
| + test('head', () { |
| + expect(http.head(serverUrl).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, equals('')); |
| + }), completes); |
| + }); |
| + |
| + test('get', () { |
| + expect(http.get(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value' |
| + }).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, parse(equals({ |
| + 'method': 'GET', |
| + 'path': '/', |
| + 'headers': { |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + }, |
| + }))); |
| + }), completes); |
| + }); |
| + |
| + test('post', () { |
| + expect(http.post(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value' |
| + }, fields: { |
| + 'some-field': 'value', |
| + 'other-field': 'other value' |
| + }).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, parse(equals({ |
| + 'method': 'POST', |
| + 'path': '/', |
| + 'headers': { |
| + 'content-type': ['application/x-www-form-urlencoded; charset=UTF-8'], |
|
Bob Nystrom
2012/10/31 01:17:44
Long line.
nweiz
2012/10/31 18:20:59
Done.
|
| + 'content-length': ['42'], |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + }, |
| + 'body': 'some-field=value&other-field=other%20value' |
| + }))); |
| + }), completes); |
| + }); |
| + |
| + test('post without fields', () { |
| + expect(http.post(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value', |
| + 'Content-Type': 'text/plain' |
| + }).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, parse(equals({ |
| + 'method': 'POST', |
| + 'path': '/', |
| + 'headers': { |
| + 'content-type': ['text/plain'], |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + } |
| + }))); |
| + }), completes); |
| + }); |
| + |
| + test('put', () { |
| + expect(http.put(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value' |
| + }, fields: { |
| + 'some-field': 'value', |
| + 'other-field': 'other value' |
| + }).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, parse(equals({ |
| + 'method': 'PUT', |
| + 'path': '/', |
| + 'headers': { |
| + 'content-type': ['application/x-www-form-urlencoded; charset=UTF-8'], |
| + 'content-length': ['42'], |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + }, |
| + 'body': 'some-field=value&other-field=other%20value' |
| + }))); |
| + }), completes); |
| + }); |
| + |
| + test('put without fields', () { |
| + expect(http.put(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value', |
| + 'Content-Type': 'text/plain' |
| + }).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, parse(equals({ |
| + 'method': 'PUT', |
| + 'path': '/', |
| + 'headers': { |
| + 'content-type': ['text/plain'], |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + } |
| + }))); |
| + }), completes); |
| + }); |
| + |
| + test('delete', () { |
| + expect(http.delete(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value' |
| + }).transform((response) { |
| + expect(response.statusCode, equals(200)); |
| + expect(response.body, parse(equals({ |
| + 'method': 'DELETE', |
| + 'path': '/', |
| + 'headers': { |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + } |
| + }))); |
| + }), completes); |
| + }); |
| + |
| + test('read', () { |
| + expect(http.read(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value' |
| + }), completion(parse(equals({ |
| + 'method': 'GET', |
| + 'path': '/', |
| + 'headers': { |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + }, |
| + })))); |
| + }); |
| + |
| + test('readBytes', () { |
|
Bob Nystrom
2012/10/31 01:17:44
Add a test that this completes to an HttpException
nweiz
2012/10/31 18:20:59
Done.
|
| + var future = http.readBytes(serverUrl, headers: { |
| + 'X-Random-Header': 'Value', |
| + 'X-Other-Header': 'Other Value' |
| + }).transform((bytes) => new String.fromCharCodes(bytes)); |
| + |
| + expect(future, completion(parse(equals({ |
| + 'method': 'GET', |
| + 'path': '/', |
| + 'headers': { |
| + 'x-random-header': ['Value'], |
| + 'x-other-header': ['Other Value'] |
| + }, |
| + })))); |
| + }); |
| + }); |
| +} |