Skip to content

Commit 43494cb

Browse files
authored
Migrate from pkg/scheduled_test and enable travis (#5)
* Stop using pkg/scheduled_test * Add analysis_options, enable travis
1 parent 26d8ab4 commit 43494cb

4 files changed

Lines changed: 101 additions & 113 deletions

File tree

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
language: dart
2+
3+
dart:
4+
- dev
5+
- stable
6+
- 1.23.0
7+
8+
dart_task:
9+
- test
10+
11+
matrix:
12+
include:
13+
- dart: dev
14+
dart_task: dartfmt
15+
- dart: dev
16+
dart_task: dartanalyzer
17+
18+
# Only building master means that we don't run two builds for each pull request.
19+
branches:
20+
only: [master]
21+
22+
cache:
23+
directories:
24+
- $HOME/.pub-cache

analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
analyzer:
2+
strong-mode: true

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ version: 0.1.1-dev
33
author: Dart Team <misc@dartlang.org>
44
description: A shelf handler for proxying requests to another server.
55
homepage: https://github.com/dart-lang/shelf_proxy
6+
environment:
7+
sdk: '>=1.23.0 <2.0.0'
68
dependencies:
79
http: '>=0.9.0 <0.12.0'
810
path: '>=1.0.0 <2.0.0'
911
shelf: '>=0.5.2 <0.8.0'
1012
dev_dependencies:
1113
browser: '>=0.10.0 <0.11.0'
12-
scheduled_test: '>=0.12.0 <0.13.0'
1314
test: '>=0.12.0 <0.13.0'

test/shelf_proxy_test.dart

Lines changed: 73 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:async';
66

77
import 'package:http/http.dart' as http;
88
import 'package:http/testing.dart';
9-
import 'package:scheduled_test/scheduled_test.dart';
9+
import 'package:test/test.dart';
1010
import 'package:shelf/shelf.dart' as shelf;
1111
import 'package:shelf/shelf_io.dart' as shelf_io;
1212
import 'package:shelf_proxy/shelf_proxy.dart';
@@ -19,173 +19,138 @@ Uri proxyUri;
1919

2020
void main() {
2121
group("forwarding", () {
22-
test("forwards request method", () {
23-
createProxy((request) {
22+
test("forwards request method", () async {
23+
await createProxy((request) {
2424
expect(request.method, equals('DELETE'));
2525
return new shelf.Response.ok(':)');
2626
});
2727

28-
schedule(() => http.delete(proxyUri));
28+
await http.delete(proxyUri);
2929
});
3030

31-
test("forwards request headers", () {
32-
createProxy((request) {
31+
test("forwards request headers", () async {
32+
await createProxy((request) {
3333
expect(request.headers, containsPair('foo', 'bar'));
3434
expect(request.headers, containsPair('accept', '*/*'));
3535
return new shelf.Response.ok(':)');
3636
});
3737

38-
get(headers: {'foo': 'bar', 'accept': '*/*'});
38+
await get(headers: {'foo': 'bar', 'accept': '*/*'});
3939
});
4040

41-
test("forwards request body", () {
42-
createProxy((request) {
41+
test("forwards request body", () async {
42+
await createProxy((request) {
4343
expect(request.readAsString(), completion(equals('hello, server')));
4444
return new shelf.Response.ok(':)');
4545
});
4646

47-
schedule(() => http.post(proxyUri, body: 'hello, server'));
47+
await http.post(proxyUri, body: 'hello, server');
4848
});
4949

50-
test("forwards response status", () {
51-
createProxy((request) {
50+
test("forwards response status", () async {
51+
await createProxy((request) {
5252
return new shelf.Response(567);
5353
});
5454

55-
expect(
56-
get().then((response) {
57-
expect(response.statusCode, equals(567));
58-
}),
59-
completes);
55+
var response = await get();
56+
expect(response.statusCode, equals(567));
6057
});
6158

62-
test("forwards response headers", () {
63-
createProxy((request) {
59+
test("forwards response headers", () async {
60+
await createProxy((request) {
6461
return new shelf.Response.ok(':)',
6562
headers: {'foo': 'bar', 'accept': '*/*'});
6663
});
6764

68-
expect(
69-
get().then((response) {
70-
expect(response.headers, containsPair('foo', 'bar'));
71-
expect(response.headers, containsPair('accept', '*/*'));
72-
}),
73-
completes);
65+
var response = await get();
66+
67+
expect(response.headers, containsPair('foo', 'bar'));
68+
expect(response.headers, containsPair('accept', '*/*'));
7469
});
7570

76-
test("forwards response body", () {
77-
createProxy((request) {
71+
test("forwards response body", () async {
72+
await createProxy((request) {
7873
return new shelf.Response.ok('hello, client');
7974
});
8075

81-
expect(schedule(() => http.read(proxyUri)),
82-
completion(equals('hello, client')));
76+
expect(await http.read(proxyUri), equals('hello, client'));
8377
});
8478

85-
test("adjusts the Host header for the target server", () {
86-
createProxy((request) {
79+
test("adjusts the Host header for the target server", () async {
80+
await createProxy((request) {
8781
expect(request.headers, containsPair('host', targetUri.authority));
8882
return new shelf.Response.ok(':)');
8983
});
9084

91-
get();
85+
await get();
9286
});
9387
});
9488

9589
group("via", () {
96-
test("adds a Via header to the request", () {
97-
createProxy((request) {
90+
test("adds a Via header to the request", () async {
91+
await createProxy((request) {
9892
expect(request.headers, containsPair('via', '1.1 shelf_proxy'));
9993
return new shelf.Response.ok(':)');
10094
});
10195

102-
get();
96+
await get();
10397
});
10498

105-
test("adds to a request's existing Via header", () {
106-
createProxy((request) {
99+
test("adds to a request's existing Via header", () async {
100+
await createProxy((request) {
107101
expect(request.headers,
108102
containsPair('via', '1.0 something, 1.1 shelf_proxy'));
109103
return new shelf.Response.ok(':)');
110104
});
111105

112-
get(headers: {'via': '1.0 something'});
106+
await get(headers: {'via': '1.0 something'});
113107
});
114108

115-
test("adds a Via header to the response", () {
116-
createProxy((request) => new shelf.Response.ok(':)'));
109+
test("adds a Via header to the response", () async {
110+
await createProxy((request) => new shelf.Response.ok(':)'));
117111

118-
expect(
119-
get().then((response) {
120-
expect(response.headers, containsPair('via', '1.1 shelf_proxy'));
121-
}),
122-
completes);
112+
var response = await get();
113+
expect(response.headers, containsPair('via', '1.1 shelf_proxy'));
123114
});
124115

125-
test("adds to a response's existing Via header", () {
126-
createProxy((request) {
116+
test("adds to a response's existing Via header", () async {
117+
await createProxy((request) {
127118
return new shelf.Response.ok(':)', headers: {'via': '1.0 something'});
128119
});
129120

130-
expect(
131-
get().then((response) {
132-
expect(response.headers,
133-
containsPair('via', '1.0 something, 1.1 shelf_proxy'));
134-
}),
135-
completes);
136-
});
137-
138-
test("adds to a response's existing Via header", () {
139-
createProxy((request) {
140-
return new shelf.Response.ok(':)', headers: {'via': '1.0 something'});
141-
});
142-
143-
expect(
144-
get().then((response) {
145-
expect(response.headers,
146-
containsPair('via', '1.0 something, 1.1 shelf_proxy'));
147-
}),
148-
completes);
121+
var response = await get();
122+
expect(response.headers,
123+
containsPair('via', '1.0 something, 1.1 shelf_proxy'));
149124
});
150125
});
151126

152127
group("redirects", () {
153-
test("doesn't modify a Location for a foreign server", () {
154-
createProxy((request) {
128+
test("doesn't modify a Location for a foreign server", () async {
129+
await createProxy((request) {
155130
return new shelf.Response.found('http://dartlang.org');
156131
});
157132

158-
expect(
159-
get().then((response) {
160-
expect(response.headers,
161-
containsPair('location', 'http://dartlang.org'));
162-
}),
163-
completes);
133+
var response = await get();
134+
expect(response.headers, containsPair('location', 'http://dartlang.org'));
164135
});
165136

166-
test("relativizes a reachable root-relative Location", () {
167-
createProxy((request) {
137+
test("relativizes a reachable root-relative Location", () async {
138+
await createProxy((request) {
168139
return new shelf.Response.found('/foo/bar');
169140
}, targetPath: '/foo');
170141

171-
expect(
172-
get().then((response) {
173-
expect(response.headers, containsPair('location', '/bar'));
174-
}),
175-
completes);
142+
var response = await get();
143+
expect(response.headers, containsPair('location', '/bar'));
176144
});
177145

178-
test("absolutizes an unreachable root-relative Location", () {
179-
createProxy((request) {
146+
test("absolutizes an unreachable root-relative Location", () async {
147+
await createProxy((request) {
180148
return new shelf.Response.found('/baz');
181149
}, targetPath: '/foo');
182150

183-
expect(
184-
get().then((response) {
185-
expect(response.headers,
186-
containsPair('location', targetUri.resolve('/baz').toString()));
187-
}),
188-
completes);
151+
var response = await get();
152+
expect(response.headers,
153+
containsPair('location', targetUri.resolve('/baz').toString()));
189154
});
190155
});
191156

@@ -222,23 +187,21 @@ void main() {
222187
///
223188
/// [targetPath] is the root-relative path on the target server to proxy to. It
224189
/// defaults to `/`.
225-
void createProxy(shelf.Handler handler, {String targetPath}) {
190+
Future createProxy(shelf.Handler handler, {String targetPath}) async {
226191
handler = expectAsync1(handler, reason: 'target server handler');
227-
schedule(() async {
228-
var targetServer = await shelf_io.serve(handler, 'localhost', 0);
229-
targetUri = Uri.parse('http://localhost:${targetServer.port}');
230-
if (targetPath != null) targetUri = targetUri.resolve(targetPath);
231-
var proxyServerHandler =
232-
expectAsync1(proxyHandler(targetUri), reason: 'proxy server handler');
233-
234-
var proxyServer = await shelf_io.serve(proxyServerHandler, 'localhost', 0);
235-
proxyUri = Uri.parse('http://localhost:${proxyServer.port}');
236-
237-
currentSchedule.onComplete.schedule(() {
238-
proxyServer.close(force: true);
239-
targetServer.close(force: true);
240-
}, 'tear down servers');
241-
}, 'spin up servers');
192+
var targetServer = await shelf_io.serve(handler, 'localhost', 0);
193+
targetUri = Uri.parse('http://localhost:${targetServer.port}');
194+
if (targetPath != null) targetUri = targetUri.resolve(targetPath);
195+
var proxyServerHandler =
196+
expectAsync1(proxyHandler(targetUri), reason: 'proxy server handler');
197+
198+
var proxyServer = await shelf_io.serve(proxyServerHandler, 'localhost', 0);
199+
proxyUri = Uri.parse('http://localhost:${proxyServer.port}');
200+
201+
addTearDown(() {
202+
proxyServer.close(force: true);
203+
targetServer.close(force: true);
204+
});
242205
}
243206

244207
/// Creates a [shelf.Handler] that's backed by a [MockClient] running
@@ -251,11 +214,9 @@ shelf.Handler mockHandler(
251214

252215
/// Schedules a GET request with [headers] to the proxy server.
253216
Future<http.Response> get({Map<String, String> headers}) {
254-
return schedule(() {
255-
var uri = proxyUri;
256-
var request = new http.Request('GET', uri);
257-
if (headers != null) request.headers.addAll(headers);
258-
request.followRedirects = false;
259-
return request.send().then(http.Response.fromStream);
260-
}, 'GET proxy server');
217+
var uri = proxyUri;
218+
var request = new http.Request('GET', uri);
219+
if (headers != null) request.headers.addAll(headers);
220+
request.followRedirects = false;
221+
return request.send().then(http.Response.fromStream);
261222
}

0 commit comments

Comments
 (0)