From 00a9780146e4473a5f1922bebea48b729ce0380a Mon Sep 17 00:00:00 2001 From: Don Date: Fri, 23 Jun 2017 13:55:59 -0700 Subject: [PATCH 1/3] Remove old unittest tests --- test/html/client_test.dart | 35 --- test/html/streamed_request_test.dart | 36 --- test/html/utils.dart | 11 - test/io/client_test.dart | 98 ------ test/io/http_test.dart | 436 --------------------------- test/io/multipart_test.dart | 41 --- test/io/request_test.dart | 59 ---- test/io/streamed_request_test.dart | 56 ---- test/io/utils.dart | 149 --------- test/mock_client_test.dart | 61 ---- test/multipart_test.dart | 234 -------------- test/request_test.dart | 354 ---------------------- test/response_test.dart | 75 ----- test/streamed_request_test.dart | 28 -- 14 files changed, 1673 deletions(-) delete mode 100644 test/html/client_test.dart delete mode 100644 test/html/streamed_request_test.dart delete mode 100644 test/html/utils.dart delete mode 100644 test/io/client_test.dart delete mode 100644 test/io/http_test.dart delete mode 100644 test/io/multipart_test.dart delete mode 100644 test/io/request_test.dart delete mode 100644 test/io/streamed_request_test.dart delete mode 100644 test/io/utils.dart delete mode 100644 test/mock_client_test.dart delete mode 100644 test/multipart_test.dart delete mode 100644 test/request_test.dart delete mode 100644 test/response_test.dart delete mode 100644 test/streamed_request_test.dart diff --git a/test/html/client_test.dart b/test/html/client_test.dart deleted file mode 100644 index ab806546e5..0000000000 --- a/test/html/client_test.dart +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2014, 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 'package:http/http.dart' as http; -import 'package:http/browser_client.dart'; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - test('#send a StreamedRequest', () { - var client = new BrowserClient(); - var request = new http.StreamedRequest("POST", echoUrl); - - expect(client.send(request).then((response) { - return response.stream.bytesToString(); - }).whenComplete(client.close), completion(equals('{"hello": "world"}'))); - - request.sink.add('{"hello": "world"}'.codeUnits); - request.sink.close(); - }); - - test('#send with an invalid URL', () { - var client = new BrowserClient(); - var url = Uri.parse('http://http.invalid'); - var request = new http.StreamedRequest("POST", url); - - expect(client.send(request), - throwsClientException("XMLHttpRequest error.")); - - request.sink.add('{"hello": "world"}'.codeUnits); - request.sink.close(); - }); -} diff --git a/test/html/streamed_request_test.dart b/test/html/streamed_request_test.dart deleted file mode 100644 index 6496f4b023..0000000000 --- a/test/html/streamed_request_test.dart +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2014, 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 'package:http/http.dart' as http; -import 'package:http/browser_client.dart'; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - group('contentLength', () { - test("works when it's set", () { - var request = new http.StreamedRequest('POST', echoUrl); - request.contentLength = 10; - request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - request.sink.close(); - - return new BrowserClient().send(request).then((response) { - expect(response.stream.toBytes(), - completion(equals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))); - }); - }); - - test("works when it's not set", () { - var request = new http.StreamedRequest('POST', echoUrl); - request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - request.sink.close(); - - return new BrowserClient().send(request).then((response) { - expect(response.stream.toBytes(), - completion(equals([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]))); - }); - }); - }); -} diff --git a/test/html/utils.dart b/test/html/utils.dart deleted file mode 100644 index 5d67765610..0000000000 --- a/test/html/utils.dart +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2014, 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:html'; - -export '../utils.dart'; - -/// The test server's echo URL. -Uri get echoUrl => Uri.parse( - '${window.location.protocol}//${window.location.host}/echo'); diff --git a/test/io/client_test.dart b/test/io/client_test.dart deleted file mode 100644 index acfa584a3c..0000000000 --- a/test/io/client_test.dart +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) 2014, 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:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - tearDown(stopServer); - - test('#send a StreamedRequest', () { - expect(startServer().then((_) { - var client = new http.Client(); - var request = new http.StreamedRequest("POST", serverUrl); - request.headers[HttpHeaders.CONTENT_TYPE] = - 'application/json; charset=utf-8'; - request.headers[HttpHeaders.USER_AGENT] = 'Dart'; - - expect(client.send(request).then((response) { - expect(response.request, equals(request)); - expect(response.statusCode, equals(200)); - expect(response.headers['single'], equals('value')); - // dart:io internally normalizes outgoing headers so that they never - // have multiple headers with the same name, so there's no way to test - // whether we handle that case correctly. - - return response.stream.bytesToString(); - }).whenComplete(client.close), completion(parse(equals({ - 'method': 'POST', - 'path': '/', - 'headers': { - 'content-type': ['application/json; charset=utf-8'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'transfer-encoding': ['chunked'] - }, - 'body': '{"hello": "world"}' - })))); - - request.sink.add('{"hello": "world"}'.codeUnits); - request.sink.close(); - }), completes); - }); - - test('#send a StreamedRequest with a custom client', () { - expect(startServer().then((_) { - var ioClient = new HttpClient(); - var client = new http.IOClient(ioClient); - var request = new http.StreamedRequest("POST", serverUrl); - request.headers[HttpHeaders.CONTENT_TYPE] = - 'application/json; charset=utf-8'; - request.headers[HttpHeaders.USER_AGENT] = 'Dart'; - - expect(client.send(request).then((response) { - expect(response.request, equals(request)); - expect(response.statusCode, equals(200)); - expect(response.headers['single'], equals('value')); - // dart:io internally normalizes outgoing headers so that they never - // have multiple headers with the same name, so there's no way to test - // whether we handle that case correctly. - - return response.stream.bytesToString(); - }).whenComplete(client.close), completion(parse(equals({ - 'method': 'POST', - 'path': '/', - 'headers': { - 'content-type': ['application/json; charset=utf-8'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'transfer-encoding': ['chunked'] - }, - 'body': '{"hello": "world"}' - })))); - - request.sink.add('{"hello": "world"}'.codeUnits); - request.sink.close(); - }), completes); - }); - - test('#send with an invalid URL', () { - expect(startServer().then((_) { - var client = new http.Client(); - var url = Uri.parse('http://http.invalid'); - var request = new http.StreamedRequest("POST", url); - request.headers[HttpHeaders.CONTENT_TYPE] = - 'application/json; charset=utf-8'; - - expect(client.send(request), throwsSocketException); - - request.sink.add('{"hello": "world"}'.codeUnits); - request.sink.close(); - }), completes); - }); -} diff --git a/test/io/http_test.dart b/test/io/http_test.dart deleted file mode 100644 index 2419e198ef..0000000000 --- a/test/io/http_test.dart +++ /dev/null @@ -1,436 +0,0 @@ -// Copyright (c) 2014, 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 'package:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -main() { - group('http.', () { - tearDown(stopServer); - - test('head', () { - expect(startServer().then((_) { - expect(http.head(serverUrl).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, equals('')); - }), completes); - }), completes); - }); - - test('get', () { - expect(startServer().then((_) { - expect(http.get(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'GET', - 'path': '/', - 'headers': { - 'content-length': ['0'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - }))); - }), completes); - }), completes); - }); - - test('post', () { - expect(startServer().then((_) { - expect(http.post(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'Content-Type': 'text/plain', - 'User-Agent': 'Dart' - }).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'POST', - 'path': '/', - 'headers': { - 'accept-encoding': ['gzip'], - 'content-length': ['0'], - 'content-type': ['text/plain'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - } - }))); - }), completes); - }), completes); - }); - - test('post with string', () { - expect(startServer().then((_) { - expect(http.post(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: 'request body').then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'POST', - 'path': '/', - 'headers': { - 'content-type': ['text/plain; charset=utf-8'], - 'content-length': ['12'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': 'request body' - }))); - }), completes); - }), completes); - }); - - test('post with bytes', () { - expect(startServer().then((_) { - expect(http.post(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: [104, 101, 108, 108, 111]).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'POST', - 'path': '/', - 'headers': { - 'content-length': ['5'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': [104, 101, 108, 108, 111] - }))); - }), completes); - }), completes); - }); - - test('post with fields', () { - expect(startServer().then((_) { - expect(http.post(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: { - 'some-field': 'value', - 'other-field': 'other value' - }).then((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' - ], - 'content-length': ['40'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': 'some-field=value&other-field=other+value' - }))); - }), completes); - }), completes); - }); - - test('put', () { - expect(startServer().then((_) { - expect(http.put(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'Content-Type': 'text/plain', - 'User-Agent': 'Dart' - }).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PUT', - 'path': '/', - 'headers': { - 'accept-encoding': ['gzip'], - 'content-length': ['0'], - 'content-type': ['text/plain'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - } - }))); - }), completes); - }), completes); - }); - - test('put with string', () { - expect(startServer().then((_) { - expect(http.put(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: 'request body').then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PUT', - 'path': '/', - 'headers': { - 'content-type': ['text/plain; charset=utf-8'], - 'content-length': ['12'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': 'request body' - }))); - }), completes); - }), completes); - }); - - test('put with bytes', () { - expect(startServer().then((_) { - expect(http.put(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: [104, 101, 108, 108, 111]).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PUT', - 'path': '/', - 'headers': { - 'content-length': ['5'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': [104, 101, 108, 108, 111] - }))); - }), completes); - }), completes); - }); - - test('put with fields', () { - expect(startServer().then((_) { - expect(http.put(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: { - 'some-field': 'value', - 'other-field': 'other value' - }).then((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': ['40'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': 'some-field=value&other-field=other+value' - }))); - }), completes); - }), completes); - }); - - test('patch', () { - expect(startServer().then((_) { - expect(http.patch(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'Content-Type': 'text/plain', - 'User-Agent': 'Dart' - }).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PATCH', - 'path': '/', - 'headers': { - 'accept-encoding': ['gzip'], - 'content-length': ['0'], - 'content-type': ['text/plain'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - } - }))); - }), completes); - }), completes); - }); - - test('patch with string', () { - expect(startServer().then((_) { - expect(http.patch(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: 'request body').then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PATCH', - 'path': '/', - 'headers': { - 'content-type': ['text/plain; charset=utf-8'], - 'content-length': ['12'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': 'request body' - }))); - }), completes); - }), completes); - }); - - test('patch with bytes', () { - expect(startServer().then((_) { - expect(http.patch(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: [104, 101, 108, 108, 111]).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PATCH', - 'path': '/', - 'headers': { - 'content-length': ['5'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': [104, 101, 108, 108, 111] - }))); - }), completes); - }), completes); - }); - - test('patch with fields', () { - expect(startServer().then((_) { - expect(http.patch(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }, body: { - 'some-field': 'value', - 'other-field': 'other value' - }).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'PATCH', - 'path': '/', - 'headers': { - 'content-type': [ - 'application/x-www-form-urlencoded; charset=utf-8' - ], - 'content-length': ['40'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - 'body': 'some-field=value&other-field=other+value' - }))); - }), completes); - }), completes); - }); - - test('delete', () { - expect(startServer().then((_) { - expect(http.delete(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }).then((response) { - expect(response.statusCode, equals(200)); - expect(response.body, parse(equals({ - 'method': 'DELETE', - 'path': '/', - 'headers': { - 'content-length': ['0'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - } - }))); - }), completes); - }), completes); - }); - - test('read', () { - expect(startServer().then((_) { - expect(http.read(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }).then((val) => val), completion(parse(equals({ - 'method': 'GET', - 'path': '/', - 'headers': { - 'content-length': ['0'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - })))); - }), completes); - }); - - test('read throws an error for a 4** status code', () { - expect(startServer().then((_) { - expect(http.read(serverUrl.resolve('/error')), throwsClientException); - }), completes); - }); - - test('readBytes', () { - expect(startServer().then((_) { - var future = http.readBytes(serverUrl, headers: { - 'X-Random-Header': 'Value', - 'X-Other-Header': 'Other Value', - 'User-Agent': 'Dart' - }).then((bytes) => new String.fromCharCodes(bytes)); - - expect(future, completion(parse(equals({ - 'method': 'GET', - 'path': '/', - 'headers': { - 'content-length': ['0'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'x-random-header': ['Value'], - 'x-other-header': ['Other Value'] - }, - })))); - }), completes); - }); - - test('readBytes throws an error for a 4** status code', () { - expect(startServer().then((_) { - expect(http.readBytes(serverUrl.resolve('/error')), - throwsClientException); - }), completes); - }); - }); -} diff --git a/test/io/multipart_test.dart b/test/io/multipart_test.dart deleted file mode 100644 index 4071dae2eb..0000000000 --- a/test/io/multipart_test.dart +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright (c) 2014, 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:async'; -import 'dart:io'; - -import 'package:http/http.dart' as http; -import 'package:path/path.dart' as path; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - var tempDir; - setUp(() { - tempDir = Directory.systemTemp.createTempSync('http_test_'); - }); - - tearDown(() => tempDir.deleteSync(recursive: true)); - - test('with a file from disk', () { - expect(new Future.sync(() { - var filePath = path.join(tempDir.path, 'test-file'); - new File(filePath).writeAsStringSync('hello'); - return http.MultipartFile.fromPath('file', filePath); - }).then((file) { - var request = new http.MultipartRequest('POST', dummyUrl); - request.files.add(file); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: application/octet-stream - content-disposition: form-data; name="file"; filename="test-file" - - hello - --{{boundary}}-- - ''')); - }), completes); - }); -} diff --git a/test/io/request_test.dart b/test/io/request_test.dart deleted file mode 100644 index 5408ba8829..0000000000 --- a/test/io/request_test.dart +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2014, 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 'package:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - test('.send', () { - expect(startServer().then((_) { - - var request = new http.Request('POST', serverUrl); - request.body = "hello"; - request.headers['User-Agent'] = 'Dart'; - - expect(request.send().then((response) { - expect(response.statusCode, equals(200)); - return response.stream.bytesToString(); - }).whenComplete(stopServer), completion(parse(equals({ - 'method': 'POST', - 'path': '/', - 'headers': { - 'content-type': ['text/plain; charset=utf-8'], - 'accept-encoding': ['gzip'], - 'user-agent': ['Dart'], - 'content-length': ['5'] - }, - 'body': 'hello' - })))); - }), completes); - }); - - test('#followRedirects', () { - expect(startServer().then((_) { - var request = new http.Request('POST', serverUrl.resolve('/redirect')) - ..followRedirects = false; - var future = request.send().then((response) { - expect(response.statusCode, equals(302)); - }); - expect(future.catchError((_) {}).then((_) => stopServer()), completes); - expect(future, completes); - }), completes); - }); - - test('#maxRedirects', () { - expect(startServer().then((_) { - var request = new http.Request('POST', serverUrl.resolve('/loop?1')) - ..maxRedirects = 2; - var future = request.send().catchError((error) { - expect(error, isRedirectLimitExceededException); - expect(error.redirects.length, equals(2)); - }); - expect(future.catchError((_) {}).then((_) => stopServer()), completes); - expect(future, completes); - }), completes); - }); -} diff --git a/test/io/streamed_request_test.dart b/test/io/streamed_request_test.dart deleted file mode 100644 index cc05bbb0f5..0000000000 --- a/test/io/streamed_request_test.dart +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) 2014, 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:convert'; - -import 'package:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - group('contentLength', () { - test('controls the Content-Length header', () { - return startServer().then((_) { - var request = new http.StreamedRequest('POST', serverUrl); - request.contentLength = 10; - request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - request.sink.close(); - - return request.send(); - }).then((response) { - expect(UTF8.decodeStream(response.stream), - completion(parse(containsPair('headers', - containsPair('content-length', ['10']))))); - }).whenComplete(stopServer); - }); - - test('defaults to sending no Content-Length', () { - return startServer().then((_) { - var request = new http.StreamedRequest('POST', serverUrl); - request.sink.add([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); - request.sink.close(); - - return request.send(); - }).then((response) { - expect(UTF8.decodeStream(response.stream), - completion(parse(containsPair('headers', - isNot(contains('content-length')))))); - }).whenComplete(stopServer); - }); - }); - - // Regression test. - test('.send() with a response with no content length', () { - return startServer().then((_) { - var request = new http.StreamedRequest( - 'GET', serverUrl.resolve('/no-content-length')); - request.sink.close(); - return request.send(); - }).then((response) { - expect(UTF8.decodeStream(response.stream), completion(equals('body'))); - }).whenComplete(stopServer); - }); - -} diff --git a/test/io/utils.dart b/test/io/utils.dart deleted file mode 100644 index a97f04fe9c..0000000000 --- a/test/io/utils.dart +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright (c) 2014, 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:async'; -import 'dart:convert'; -import 'dart:io'; - -import 'package:http/http.dart'; -import 'package:http/src/utils.dart'; -import 'package:unittest/unittest.dart'; - -export '../utils.dart'; - -/// The current server instance. -HttpServer _server; - -/// The URL for the current server instance. -Uri get serverUrl => Uri.parse('http://localhost:${_server.port}'); - -/// Starts a new HTTP server. -Future startServer() { - return HttpServer.bind("localhost", 0).then((s) { - _server = s; - s.listen((request) { - var path = request.uri.path; - var response = request.response; - - if (path == '/error') { - response.statusCode = 400; - response.contentLength = 0; - response.close(); - return; - } - - if (path == '/loop') { - var n = int.parse(request.uri.query); - response.statusCode = 302; - response.headers.set('location', - serverUrl.resolve('/loop?${n + 1}').toString()); - response.contentLength = 0; - response.close(); - return; - } - - if (path == '/redirect') { - response.statusCode = 302; - response.headers.set('location', serverUrl.resolve('/').toString()); - response.contentLength = 0; - response.close(); - return; - } - - if (path == '/no-content-length') { - response.statusCode = 200; - response.contentLength = -1; - response.write('body'); - response.close(); - return; - } - - new ByteStream(request).toBytes().then((requestBodyBytes) { - var outputEncoding; - var encodingName = request.uri.queryParameters['response-encoding']; - if (encodingName != null) { - outputEncoding = requiredEncodingForCharset(encodingName); - } else { - outputEncoding = ASCII; - } - - response.headers.contentType = - new ContentType( - "application", "json", charset: outputEncoding.name); - response.headers.set('single', 'value'); - - var requestBody; - if (requestBodyBytes.isEmpty) { - requestBody = null; - } else if (request.headers.contentType != null && - request.headers.contentType.charset != null) { - var encoding = requiredEncodingForCharset( - request.headers.contentType.charset); - requestBody = encoding.decode(requestBodyBytes); - } else { - requestBody = requestBodyBytes; - } - - var content = { - 'method': request.method, - 'path': request.uri.path, - 'headers': {} - }; - if (requestBody != null) content['body'] = requestBody; - request.headers.forEach((name, values) { - // These headers are automatically generated by dart:io, so we don't - // want to test them here. - if (name == 'cookie' || name == 'host') return; - - (content['headers'] as Map)[name] = values; - }); - - var body = JSON.encode(content); - response.contentLength = body.length; - response.write(body); - response.close(); - }); - }); - }); -} - -/// Stops the current HTTP server. -void stopServer() { - if (_server != null) { - _server.close(); - _server = null; - } -} - -/// A matcher for functions that throw HttpException. -Matcher get throwsClientException => - throwsA(new isInstanceOf()); - -/// A matcher for RedirectLimitExceededExceptions. -const isRedirectLimitExceededException = - const _RedirectLimitExceededException(); - -/// A matcher for functions that throw RedirectLimitExceededException. -const Matcher throwsRedirectLimitExceededException = - const Throws(isRedirectLimitExceededException); - -class _RedirectLimitExceededException extends TypeMatcher { - const _RedirectLimitExceededException() : - super("RedirectLimitExceededException"); - - bool matches(item, Map matchState) => - item is RedirectException && item.message == "Redirect limit exceeded"; -} - -/// A matcher for SocketExceptions. -const isSocketException = const _SocketException(); - -/// A matcher for functions that throw SocketException. -const Matcher throwsSocketException = - const Throws(isSocketException); - -class _SocketException extends TypeMatcher { - const _SocketException() : super("SocketException"); - bool matches(item, Map matchState) => item is SocketException; -} diff --git a/test/mock_client_test.dart b/test/mock_client_test.dart deleted file mode 100644 index 48e635fee3..0000000000 --- a/test/mock_client_test.dart +++ /dev/null @@ -1,61 +0,0 @@ -// 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. - -import 'dart:async'; -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:http/testing.dart'; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - test('handles a request', () { - var client = new MockClient((request) { - return new Future.value(new http.Response( - JSON.encode(request.bodyFields), 200, - request: request, headers: {'content-type': 'application/json'})); - }); - - expect(client.post("http://example.com/foo", body: { - 'field1': 'value1', - 'field2': 'value2' - }).then((response) => response.body), completion(parse(equals({ - 'field1': 'value1', - 'field2': 'value2' - })))); - }); - - test('handles a streamed request', () { - var client = new MockClient.streaming((request, bodyStream) { - return bodyStream.bytesToString().then((bodyString) { - var controller = new StreamController>(sync: true); - new Future.sync(() { - controller.add('Request body was "$bodyString"'.codeUnits); - controller.close(); - }); - - return new http.StreamedResponse(controller.stream, 200); - }); - }); - - var uri = Uri.parse("http://example.com/foo"); - var request = new http.Request("POST", uri); - request.body = "hello, world"; - var future = client.send(request) - .then(http.Response.fromStream) - .then((response) => response.body); - expect(future, completion(equals('Request body was "hello, world"'))); - }); - - test('handles a request with no body', () { - var client = new MockClient((request) { - return new Future.value(new http.Response('you did it', 200)); - }); - - expect(client.read("http://example.com/foo"), - completion(equals('you did it'))); - }); -} diff --git a/test/multipart_test.dart b/test/multipart_test.dart deleted file mode 100644 index 64586db2d8..0000000000 --- a/test/multipart_test.dart +++ /dev/null @@ -1,234 +0,0 @@ -// 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:async'; - -import 'package:http/http.dart' as http; -import 'package:http_parser/http_parser.dart'; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - test('empty', () { - var request = new http.MultipartRequest('POST', dummyUrl); - expect(request, bodyMatches(''' - --{{boundary}}-- - ''')); - }); - - test('with fields and files', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.fields['field1'] = 'value1'; - request.fields['field2'] = 'value2'; - request.files.add(new http.MultipartFile.fromString("file1", "contents1", - filename: "filename1.txt")); - request.files.add(new http.MultipartFile.fromString("file2", "contents2")); - - expect(request, bodyMatches(''' - --{{boundary}} - content-disposition: form-data; name="field1" - - value1 - --{{boundary}} - content-disposition: form-data; name="field2" - - value2 - --{{boundary}} - content-type: text/plain; charset=utf-8 - content-disposition: form-data; name="file1"; filename="filename1.txt" - - contents1 - --{{boundary}} - content-type: text/plain; charset=utf-8 - content-disposition: form-data; name="file2" - - contents2 - --{{boundary}}-- - ''')); - }); - - test('with a unicode field name', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.fields['fïēld'] = 'value'; - - expect(request, bodyMatches(''' - --{{boundary}} - content-disposition: form-data; name="fïēld" - - value - --{{boundary}}-- - ''')); - }); - - test('with a field name with newlines', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.fields['foo\nbar\rbaz\r\nbang'] = 'value'; - - expect(request, bodyMatches(''' - --{{boundary}} - content-disposition: form-data; name="foo%0D%0Abar%0D%0Abaz%0D%0Abang" - - value - --{{boundary}}-- - ''')); - }); - - test('with a field name with a quote', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.fields['foo"bar'] = 'value'; - - expect(request, bodyMatches(''' - --{{boundary}} - content-disposition: form-data; name="foo%22bar" - - value - --{{boundary}}-- - ''')); - }); - - test('with a unicode field value', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.fields['field'] = 'vⱥlūe'; - - expect(request, bodyMatches(''' - --{{boundary}} - content-disposition: form-data; name="field" - content-type: text/plain; charset=utf-8 - content-transfer-encoding: binary - - vⱥlūe - --{{boundary}}-- - ''')); - }); - - test('with a unicode filename', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.files.add(new http.MultipartFile.fromString('file', 'contents', - filename: 'fïlēname.txt')); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: text/plain; charset=utf-8 - content-disposition: form-data; name="file"; filename="fïlēname.txt" - - contents - --{{boundary}}-- - ''')); - }); - - test('with a filename with newlines', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.files.add(new http.MultipartFile.fromString('file', 'contents', - filename: 'foo\nbar\rbaz\r\nbang')); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: text/plain; charset=utf-8 - content-disposition: form-data; name="file"; filename="foo%0D%0Abar%0D%0Abaz%0D%0Abang" - - contents - --{{boundary}}-- - ''')); - }); - - test('with a filename with a quote', () { - var request = new http.MultipartRequest('POST', dummyUrl); - request.files.add(new http.MultipartFile.fromString('file', 'contents', - filename: 'foo"bar')); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: text/plain; charset=utf-8 - content-disposition: form-data; name="file"; filename="foo%22bar" - - contents - --{{boundary}}-- - ''')); - }); - - test('with a string file with a content-type but no charset', () { - var request = new http.MultipartRequest('POST', dummyUrl); - var file = new http.MultipartFile.fromString('file', '{"hello": "world"}', - contentType: new MediaType('application', 'json')); - request.files.add(file); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: application/json; charset=utf-8 - content-disposition: form-data; name="file" - - {"hello": "world"} - --{{boundary}}-- - ''')); - }); - - test('with a file with a iso-8859-1 body', () { - var request = new http.MultipartRequest('POST', dummyUrl); - // "Ã¥" encoded as ISO-8859-1 and then read as UTF-8 results in "å". - var file = new http.MultipartFile.fromString('file', 'non-ascii: "Ã¥"', - contentType: new MediaType('text', 'plain', {'charset': 'iso-8859-1'})); - request.files.add(file); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: text/plain; charset=iso-8859-1 - content-disposition: form-data; name="file" - - non-ascii: "å" - --{{boundary}}-- - ''')); - }); - - test('with a stream file', () { - var request = new http.MultipartRequest('POST', dummyUrl); - var controller = new StreamController>(sync: true); - request.files.add(new http.MultipartFile('file', controller.stream, 5)); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: application/octet-stream - content-disposition: form-data; name="file" - - hello - --{{boundary}}-- - ''')); - - controller.add([104, 101, 108, 108, 111]); - controller.close(); - }); - - test('with an empty stream file', () { - var request = new http.MultipartRequest('POST', dummyUrl); - var controller = new StreamController>(sync: true); - request.files.add(new http.MultipartFile('file', controller.stream, 0)); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: application/octet-stream - content-disposition: form-data; name="file" - - - --{{boundary}}-- - ''')); - - controller.close(); - }); - - test('with a byte file', () { - var request = new http.MultipartRequest('POST', dummyUrl); - var file = new http.MultipartFile.fromBytes( - 'file', [104, 101, 108, 108, 111]); - request.files.add(file); - - expect(request, bodyMatches(''' - --{{boundary}} - content-type: application/octet-stream - content-disposition: form-data; name="file" - - hello - --{{boundary}}-- - ''')); - }); -} diff --git a/test/request_test.dart b/test/request_test.dart deleted file mode 100644 index f2f4c133d9..0000000000 --- a/test/request_test.dart +++ /dev/null @@ -1,354 +0,0 @@ -// 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. - -import 'dart:convert'; - -import 'package:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - group('#contentLength', () { - test('is computed from bodyBytes', () { - var request = new http.Request('POST', dummyUrl); - request.bodyBytes = [1, 2, 3, 4, 5]; - expect(request.contentLength, equals(5)); - request.bodyBytes = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; - expect(request.contentLength, equals(10)); - }); - - test('is computed from body', () { - var request = new http.Request('POST', dummyUrl); - request.body = "hello"; - expect(request.contentLength, equals(5)); - request.body = "hello, world"; - expect(request.contentLength, equals(12)); - }); - - test('is not directly mutable', () { - var request = new http.Request('POST', dummyUrl); - expect(() => request.contentLength = 50, throwsUnsupportedError); - }); - }); - - group('#encoding', () { - test('defaults to utf-8', () { - var request = new http.Request('POST', dummyUrl); - expect(request.encoding.name, equals(UTF8.name)); - }); - - test('can be set', () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - expect(request.encoding.name, equals(LATIN1.name)); - }); - - test('is based on the content-type charset if it exists', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = 'text/plain; charset=iso-8859-1'; - expect(request.encoding.name, equals(LATIN1.name)); - }); - - test('remains the default if the content-type charset is set and unset', - () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - request.headers['Content-Type'] = 'text/plain; charset=utf-8'; - expect(request.encoding.name, equals(UTF8.name)); - - request.headers.remove('Content-Type'); - expect(request.encoding.name, equals(LATIN1.name)); - }); - - test('throws an error if the content-type charset is unknown', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'text/plain; charset=not-a-real-charset'; - expect(() => request.encoding, throwsFormatException); - }); - }); - - group('#bodyBytes', () { - test('defaults to empty', () { - var request = new http.Request('POST', dummyUrl); - expect(request.bodyBytes, isEmpty); - }); - - test('can be set', () { - var request = new http.Request('POST', dummyUrl); - request.bodyBytes = [104, 101, 108, 108, 111]; - expect(request.bodyBytes, equals([104, 101, 108, 108, 111])); - }); - - test('changes when body changes', () { - var request = new http.Request('POST', dummyUrl); - request.body = "hello"; - expect(request.bodyBytes, equals([104, 101, 108, 108, 111])); - }); - }); - - group('#body', () { - test('defaults to empty', () { - var request = new http.Request('POST', dummyUrl); - expect(request.body, isEmpty); - }); - - test('can be set', () { - var request = new http.Request('POST', dummyUrl); - request.body = "hello"; - expect(request.body, equals("hello")); - }); - - test('changes when bodyBytes changes', () { - var request = new http.Request('POST', dummyUrl); - request.bodyBytes = [104, 101, 108, 108, 111]; - expect(request.body, equals("hello")); - }); - - test('is encoded according to the given encoding', () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - request.body = "föøbãr"; - expect(request.bodyBytes, equals([102, 246, 248, 98, 227, 114])); - }); - - test('is decoded according to the given encoding', () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - request.bodyBytes = [102, 246, 248, 98, 227, 114]; - expect(request.body, equals("föøbãr")); - }); - }); - - group('#bodyFields', () { - test("can't be read without setting the content-type", () { - var request = new http.Request('POST', dummyUrl); - expect(() => request.bodyFields, throwsStateError); - }); - - test("can't be read with the wrong content-type", () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = 'text/plain'; - expect(() => request.bodyFields, throwsStateError); - }); - - test("can't be set with the wrong content-type", () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = 'text/plain'; - expect(() => request.bodyFields = {}, throwsStateError); - }); - - test('defaults to empty', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/x-www-form-urlencoded'; - expect(request.bodyFields, isEmpty); - }); - - test('can be set with no content-type', () { - var request = new http.Request('POST', dummyUrl); - request.bodyFields = {'hello': 'world'}; - expect(request.bodyFields, equals({'hello': 'world'})); - }); - - test('changes when body changes', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/x-www-form-urlencoded'; - request.body = 'key%201=value&key+2=other%2bvalue'; - expect(request.bodyFields, - equals({'key 1': 'value', 'key 2': 'other+value'})); - }); - - test('is encoded according to the given encoding', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/x-www-form-urlencoded'; - request.encoding = LATIN1; - request.bodyFields = {"föø": "bãr"}; - expect(request.body, equals('f%F6%F8=b%E3r')); - }); - - test('is decoded according to the given encoding', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/x-www-form-urlencoded'; - request.encoding = LATIN1; - request.body = 'f%F6%F8=b%E3r'; - expect(request.bodyFields, equals({"föø": "bãr"})); - }); - }); - - group('content-type header', () { - test('defaults to empty', () { - var request = new http.Request('POST', dummyUrl); - expect(request.headers['Content-Type'], isNull); - }); - - test('defaults to empty if only encoding is set', () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - expect(request.headers['Content-Type'], isNull); - }); - - test('name is case insensitive', () { - var request = new http.Request('POST', dummyUrl); - request.headers['CoNtEnT-tYpE'] = 'application/json'; - expect(request.headers, - containsPair('content-type', 'application/json')); - }); - - test('is set to application/x-www-form-urlencoded with charset utf-8 if ' - 'bodyFields is set', () { - var request = new http.Request('POST', dummyUrl); - request.bodyFields = {'hello': 'world'}; - expect(request.headers['Content-Type'], - equals('application/x-www-form-urlencoded; charset=utf-8')); - }); - - test('is set to application/x-www-form-urlencoded with the given charset ' - 'if bodyFields and encoding are set', () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - request.bodyFields = {'hello': 'world'}; - expect(request.headers['Content-Type'], - equals('application/x-www-form-urlencoded; charset=iso-8859-1')); - }); - - test('is set to text/plain and the given encoding if body and encoding are ' - 'both set', () { - var request = new http.Request('POST', dummyUrl); - request.encoding = LATIN1; - request.body = 'hello, world'; - expect(request.headers['Content-Type'], - equals('text/plain; charset=iso-8859-1')); - }); - - test('is modified to include utf-8 if body is set', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = 'application/json'; - request.body = '{"hello": "world"}'; - expect(request.headers['Content-Type'], - equals('application/json; charset=utf-8')); - }); - - test('is modified to include the given encoding if encoding is set', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = 'application/json'; - request.encoding = LATIN1; - expect(request.headers['Content-Type'], - equals('application/json; charset=iso-8859-1')); - }); - - test('has its charset overridden by an explicit encoding', () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/json; charset=utf-8'; - request.encoding = LATIN1; - expect(request.headers['Content-Type'], - equals('application/json; charset=iso-8859-1')); - }); - - test("doen't have its charset overridden by setting bodyFields", () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/x-www-form-urlencoded; charset=iso-8859-1'; - request.bodyFields = {'hello': 'world'}; - expect(request.headers['Content-Type'], - equals('application/x-www-form-urlencoded; charset=iso-8859-1')); - }); - - test("doen't have its charset overridden by setting body", () { - var request = new http.Request('POST', dummyUrl); - request.headers['Content-Type'] = - 'application/json; charset=iso-8859-1'; - request.body = '{"hello": "world"}'; - expect(request.headers['Content-Type'], - equals('application/json; charset=iso-8859-1')); - }); - }); - - group('#finalize', () { - test('returns a stream that emits the request body', () { - var request = new http.Request('POST', dummyUrl); - request.body = "Hello, world!"; - expect(request.finalize().bytesToString(), - completion(equals("Hello, world!"))); - }); - - test('freezes #persistentConnection', () { - var request = new http.Request('POST', dummyUrl); - request.finalize(); - - expect(request.persistentConnection, isTrue); - expect(() => request.persistentConnection = false, throwsStateError); - }); - - test('freezes #followRedirects', () { - var request = new http.Request('POST', dummyUrl); - request.finalize(); - - expect(request.followRedirects, isTrue); - expect(() => request.followRedirects = false, throwsStateError); - }); - - test('freezes #maxRedirects', () { - var request = new http.Request('POST', dummyUrl); - request.finalize(); - - expect(request.maxRedirects, equals(5)); - expect(() => request.maxRedirects = 10, throwsStateError); - }); - - test('freezes #encoding', () { - var request = new http.Request('POST', dummyUrl); - request.finalize(); - - expect(request.encoding.name, equals(UTF8.name)); - expect(() => request.encoding = ASCII, throwsStateError); - }); - - test('freezes #bodyBytes', () { - var request = new http.Request('POST', dummyUrl); - request.bodyBytes = [1, 2, 3]; - request.finalize(); - - expect(request.bodyBytes, equals([1, 2, 3])); - expect(() => request.bodyBytes = [4, 5, 6], throwsStateError); - }); - - test('freezes #body', () { - var request = new http.Request('POST', dummyUrl); - request.body = "hello"; - request.finalize(); - - expect(request.body, equals("hello")); - expect(() => request.body = "goodbye", throwsStateError); - }); - - test('freezes #bodyFields', () { - var request = new http.Request('POST', dummyUrl); - request.bodyFields = {"hello": "world"}; - request.finalize(); - - expect(request.bodyFields, equals({"hello": "world"})); - expect(() => request.bodyFields = {}, throwsStateError); - }); - - test("can't be called twice", () { - var request = new http.Request('POST', dummyUrl); - request.finalize(); - expect(request.finalize, throwsStateError); - }); - }); - - group('#toString()', () { - test('includes the method and URL', () { - var request = new http.Request('POST', dummyUrl); - expect(request.toString(), 'POST $dummyUrl'); - }); - }); -} - diff --git a/test/response_test.dart b/test/response_test.dart deleted file mode 100644 index 0b33f908df..0000000000 --- a/test/response_test.dart +++ /dev/null @@ -1,75 +0,0 @@ -// 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. - -import 'dart:async'; - -import 'package:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -void main() { - group('()', () { - test('sets body', () { - var response = new http.Response("Hello, world!", 200); - expect(response.body, equals("Hello, world!")); - }); - - test('sets bodyBytes', () { - var response = new http.Response("Hello, world!", 200); - expect(response.bodyBytes, equals( - [72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33])); - }); - - test('respects the inferred encoding', () { - var response = new http.Response("föøbãr", 200, - headers: {'content-type': 'text/plain; charset=iso-8859-1'}); - expect(response.bodyBytes, equals( - [102, 246, 248, 98, 227, 114])); - }); - }); - - group('.bytes()', () { - test('sets body', () { - var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); - expect(response.body, equals("hello")); - }); - - test('sets bodyBytes', () { - var response = new http.Response.bytes([104, 101, 108, 108, 111], 200); - expect(response.bodyBytes, equals([104, 101, 108, 108, 111])); - }); - - test('respects the inferred encoding', () { - var response = new http.Response.bytes([102, 246, 248, 98, 227, 114], 200, - headers: {'content-type': 'text/plain; charset=iso-8859-1'}); - expect(response.body, equals("föøbãr")); - }); - }); - - group('.fromStream()', () { - test('sets body', () { - var controller = new StreamController>(sync: true); - var streamResponse = new http.StreamedResponse( - controller.stream, 200, contentLength: 13); - var future = http.Response.fromStream(streamResponse) - .then((response) => response.body); - expect(future, completion(equals("Hello, world!"))); - - controller.add([72, 101, 108, 108, 111, 44, 32]); - controller.add([119, 111, 114, 108, 100, 33]); - controller.close(); - }); - - test('sets bodyBytes', () { - var controller = new StreamController>(sync: true); - var streamResponse = new http.StreamedResponse( - controller.stream, 200, contentLength: 5); - var future = http.Response.fromStream(streamResponse) - .then((response) => response.bodyBytes); - expect(future, completion(equals([104, 101, 108, 108, 111]))); - - controller.add([104, 101, 108, 108, 111]); - controller.close(); - }); - }); -} diff --git a/test/streamed_request_test.dart b/test/streamed_request_test.dart deleted file mode 100644 index c7e56e2c64..0000000000 --- a/test/streamed_request_test.dart +++ /dev/null @@ -1,28 +0,0 @@ -// 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. - -import 'package:http/http.dart' as http; -import 'package:unittest/unittest.dart'; - -import 'utils.dart'; - -void main() { - group('contentLength', () { - test('defaults to null', () { - var request = new http.StreamedRequest('POST', dummyUrl); - expect(request.contentLength, isNull); - }); - - test('disallows negative values', () { - var request = new http.StreamedRequest('POST', dummyUrl); - expect(() => request.contentLength = -1, throwsArgumentError); - }); - - test('is frozen by finalize()', () { - var request = new http.StreamedRequest('POST', dummyUrl); - request.finalize(); - expect(() => request.contentLength = 10, throwsStateError); - }); - }); -} From 51410521cc2fb9f85116569252baa8a64e63c03e Mon Sep 17 00:00:00 2001 From: Don Date: Fri, 23 Jun 2017 13:56:33 -0700 Subject: [PATCH 2/3] Fix accidental character --- lib/src/pipeline.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/pipeline.dart b/lib/src/pipeline.dart index d7fe1e4d70..fc100ba0de 100644 --- a/lib/src/pipeline.dart +++ b/lib/src/pipeline.dart @@ -1,4 +1,4 @@ -k// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2017, 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. From 2841cd75e2a98cae217449bf5d8cbbbad8a1a374 Mon Sep 17 00:00:00 2001 From: Don Date: Fri, 23 Jun 2017 13:56:44 -0700 Subject: [PATCH 3/3] Expose pipeline and handler --- lib/http.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/http.dart b/lib/http.dart index 6b80d7f1eb..2728e1994b 100644 --- a/lib/http.dart +++ b/lib/http.dart @@ -13,8 +13,10 @@ import 'src/response.dart'; export 'src/base_client.dart'; export 'src/client.dart'; export 'src/exception.dart'; +export 'src/handler.dart'; export 'src/io_client.dart'; export 'src/middleware.dart'; +export 'src/pipeline.dart'; export 'src/request.dart'; export 'src/response.dart';