Skip to content

Commit 9700bb0

Browse files
authored
Add a conformance test package for http Clients (#706)
1 parent ae8a9a8 commit 9700bb0

15 files changed

+869
-18
lines changed

.github/workflows/dart.yml

Lines changed: 62 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
A composable, Future-based library for making HTTP requests.
2+
3+
[![Build Status](https://github.com/dart-lang/http/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/http/actions?query=workflow%3A"Dart+CI"+branch%3Amaster)
4+
5+
`package:http` contains a set of high-level functions and classes that make it
6+
easy to consume HTTP resources. It's multi-platform, and supports mobile, desktop,
7+
and the browser.
8+
9+
## Packages
10+
11+
| Package | Description | Version |
12+
|---|---|---|
13+
| [http](pkgs/http/) | A composable, Future-based library for making HTTP requests. | [![pub package](https://img.shields.io/pub/v/http.svg)](https://pub.dev/packages/http) |
14+
| [http_client_conformance_tests](pkgs/http_client_conformance_tests/) | Tests for `package:http` `Client` implementations. | [![pub package](https://img.shields.io/pub/v/http_client_conformance_tests.svg)](https://pub.dev/packages/http_client_conformance_tests) |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.0.1
2+
3+
- Initial version.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2014, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
A library that tests whether implementations of `package:http`
2+
[`Client`'](https://pub.dev/documentation/http/latest/http/Client-class.html)
3+
behave as expected.
4+
5+
This package is intended to be used in the tests of packages that implement
6+
`package:http`
7+
[`Client`'](https://pub.dev/documentation/http/latest/http/Client-class.html).
8+
9+
## Usage
10+
11+
`package:http_client_conformance_tests` is meant to be used in the tests suite
12+
of a `package:http`
13+
[`Client`'](https://pub.dev/documentation/http/latest/http/Client-class.html)
14+
like:
15+
16+
```dart
17+
import 'package:http/http.dart';
18+
import 'package:test/test.dart';
19+
20+
import 'package:http_client_conformance_tests/http_client_conformance_tests.dart';
21+
22+
class MyHttpClient extends BaseClient {
23+
@override
24+
Future<StreamedResponse> send(BaseRequest request) async {
25+
// Your implementation here.
26+
}
27+
}
28+
29+
void main() {
30+
group('client conformance tests', () {
31+
testAll(MyHttpClient());
32+
});
33+
}
34+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:http/http.dart';
2+
import 'package:http_client_conformance_tests/http_client_conformance_tests.dart';
3+
import 'package:test/test.dart';
4+
5+
class MyHttpClient extends BaseClient {
6+
@override
7+
Future<StreamedResponse> send(BaseRequest request) async {
8+
// Your implementation here.
9+
throw UnsupportedError('implement this method');
10+
}
11+
}
12+
13+
void main() {
14+
group('client conformance tests', () {
15+
testAll(MyHttpClient());
16+
});
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2022, 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+
import 'package:http/http.dart';
6+
7+
import 'src/redirect_tests.dart';
8+
import 'src/request_body_tests.dart';
9+
import 'src/request_headers_tests.dart';
10+
import 'src/response_body_tests.dart';
11+
import 'src/response_headers_tests.dart';
12+
13+
export 'src/redirect_tests.dart' show testRedirect;
14+
export 'src/request_body_tests.dart' show testRequestBody;
15+
export 'src/request_headers_tests.dart' show testRequestHeaders;
16+
export 'src/response_body_tests.dart' show testResponseBody;
17+
export 'src/response_headers_tests.dart' show testResponseHeaders;
18+
19+
/// Runs the entire test suite against the given [Client].
20+
///
21+
/// If [canStreamRequestBody] is `false` then tests that assume that the
22+
/// [Client] supports sending HTTP requests with unbounded body sizes will be
23+
/// skipped.
24+
//
25+
/// If [canStreamResponseBody] is `false` then tests that assume that the
26+
/// [Client] supports receiving HTTP responses with unbounded body sizes will
27+
/// be skipped
28+
void testAll(Client client,
29+
{bool canStreamRequestBody = true, bool canStreamResponseBody = true}) {
30+
testRequestBody(client, canStreamRequestBody: canStreamRequestBody);
31+
testResponseBody(client, canStreamResponseBody: canStreamResponseBody);
32+
testRequestHeaders(client);
33+
testResponseHeaders(client);
34+
testRedirect(client);
35+
}

0 commit comments

Comments
 (0)