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

Side by Side Diff: test/cascade_test.dart

Issue 837193005: pkg/shelf: formatted code (Closed) Base URL: https://github.com/dart-lang/shelf.git@master
Patch Set: nits Created 5 years, 11 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 unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | test/create_middleware_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library shelf.cascade_test; 5 library shelf.cascade_test;
6 6
7 import 'package:shelf/shelf.dart'; 7 import 'package:shelf/shelf.dart';
8 import 'package:shelf/src/util.dart'; 8 import 'package:shelf/src/util.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
(...skipping 27 matching lines...) Expand all
38 test('the first response should be returned if it matches', () { 38 test('the first response should be returned if it matches', () {
39 return makeSimpleRequest(handler).then((response) { 39 return makeSimpleRequest(handler).then((response) {
40 expect(response.statusCode, equals(200)); 40 expect(response.statusCode, equals(200));
41 expect(response.readAsString(), completion(equals('handler 1'))); 41 expect(response.readAsString(), completion(equals('handler 1')));
42 }); 42 });
43 }); 43 });
44 44
45 test("the second response should be returned if it matches and the first " 45 test("the second response should be returned if it matches and the first "
46 "doesn't", () { 46 "doesn't", () {
47 return syncFuture(() { 47 return syncFuture(() {
48 return handler(new Request('GET', LOCALHOST_URI, 48 return handler(
49 headers: {'one': 'false'})); 49 new Request('GET', LOCALHOST_URI, headers: {'one': 'false'}));
50 }).then((response) { 50 }).then((response) {
51 expect(response.statusCode, equals(200)); 51 expect(response.statusCode, equals(200));
52 expect(response.readAsString(), completion(equals('handler 2'))); 52 expect(response.readAsString(), completion(equals('handler 2')));
53 }); 53 });
54 }); 54 });
55 55
56 test("the third response should be returned if it matches and the first " 56 test("the third response should be returned if it matches and the first "
57 "two don't", () { 57 "two don't", () {
58 return syncFuture(() { 58 return syncFuture(() {
59 return handler(new Request('GET', LOCALHOST_URI, 59 return handler(new Request('GET', LOCALHOST_URI,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 .handler; 108 .handler;
109 109
110 return makeSimpleRequest(handler).then((response) { 110 return makeSimpleRequest(handler).then((response) {
111 expect(response.statusCode, equals(404)); 111 expect(response.statusCode, equals(404));
112 expect(response.readAsString(), completion(equals('handler 3'))); 112 expect(response.readAsString(), completion(equals('handler 3')));
113 }); 113 });
114 }); 114 });
115 115
116 test('[shouldCascade] controls which responses cause cascading', () { 116 test('[shouldCascade] controls which responses cause cascading', () {
117 var handler = new Cascade( 117 var handler = new Cascade(
118 shouldCascade: (response) => response.statusCode % 2 == 1) 118 shouldCascade: (response) => response.statusCode % 2 == 1)
119 .add((_) => new Response.movedPermanently('/')) 119 .add((_) => new Response.movedPermanently('/'))
120 .add((_) => new Response.forbidden('handler 2')) 120 .add((_) => new Response.forbidden('handler 2'))
121 .add((_) => new Response.notFound('handler 3')) 121 .add((_) => new Response.notFound('handler 3'))
122 .add((_) => new Response.ok('handler 4')) 122 .add((_) => new Response.ok('handler 4'))
123 .handler; 123 .handler;
124 124
125 return makeSimpleRequest(handler).then((response) { 125 return makeSimpleRequest(handler).then((response) {
126 expect(response.statusCode, equals(404)); 126 expect(response.statusCode, equals(404));
127 expect(response.readAsString(), completion(equals('handler 3'))); 127 expect(response.readAsString(), completion(equals('handler 3')));
128 }); 128 });
129 }); 129 });
130 130
131 group('errors', () { 131 group('errors', () {
132 test('getting the handler for an empty cascade fails', () { 132 test('getting the handler for an empty cascade fails', () {
133 expect(() => new Cascade().handler, throwsStateError); 133 expect(() => new Cascade().handler, throwsStateError);
134 }); 134 });
135 135
136 test('passing [statusCodes] and [shouldCascade] at the same time fails', 136 test('passing [statusCodes] and [shouldCascade] at the same time fails',
137 () { 137 () {
138 expect(() => new Cascade( 138 expect(() =>
139 statusCodes: [404, 405], shouldCascade: (_) => false), 139 new Cascade(statusCodes: [404, 405], shouldCascade: (_) => false),
140 throwsArgumentError); 140 throwsArgumentError);
141 }); 141 });
142 }); 142 });
143 } 143 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | test/create_middleware_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698