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

Side by Side Diff: pkg/shelf/test/pipeline_test.dart

Issue 238813003: pkg/shelf: rename Stack to Pipeline (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: nit Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « pkg/shelf/test/log_middleware_test.dart ('k') | pkg/shelf/test/stack_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.shelf_stack_test; 5 library shelf.pipeline_test;
6 6
7 import 'package:shelf/shelf.dart'; 7 import 'package:shelf/shelf.dart';
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'test_util.dart'; 10 import 'test_util.dart';
11 11
12 void main() { 12 void main() {
13 test('compose middleware with Stack', () { 13 test('compose middleware with Pipeline', () {
14 int accessLocation = 0; 14 int accessLocation = 0;
15 15
16 var middlewareA = createMiddleware(requestHandler: (request) { 16 var middlewareA = createMiddleware(requestHandler: (request) {
17 expect(accessLocation, 0); 17 expect(accessLocation, 0);
18 accessLocation = 1; 18 accessLocation = 1;
19 return null; 19 return null;
20 }, responseHandler: (response) { 20 }, responseHandler: (response) {
21 expect(accessLocation, 4); 21 expect(accessLocation, 4);
22 accessLocation = 5; 22 accessLocation = 5;
23 return response; 23 return response;
24 }); 24 });
25 25
26 var middlewareB = createMiddleware(requestHandler: (request) { 26 var middlewareB = createMiddleware(requestHandler: (request) {
27 expect(accessLocation, 1); 27 expect(accessLocation, 1);
28 accessLocation = 2; 28 accessLocation = 2;
29 return null; 29 return null;
30 }, responseHandler: (response) { 30 }, responseHandler: (response) {
31 expect(accessLocation, 3); 31 expect(accessLocation, 3);
32 accessLocation = 4; 32 accessLocation = 4;
33 return response; 33 return response;
34 }); 34 });
35 35
36 var handler = const Stack() 36 var handler = const Pipeline()
37 .addMiddleware(middlewareA) 37 .addMiddleware(middlewareA)
38 .addMiddleware(middlewareB) 38 .addMiddleware(middlewareB)
39 .addHandler((request) { 39 .addHandler((request) {
40 expect(accessLocation, 2); 40 expect(accessLocation, 2);
41 accessLocation = 3; 41 accessLocation = 3;
42 return syncHandler(request); 42 return syncHandler(request);
43 }); 43 });
44 44
45 return makeSimpleRequest(handler).then((response) { 45 return makeSimpleRequest(handler).then((response) {
46 expect(response, isNotNull); 46 expect(response, isNotNull);
47 expect(accessLocation, 5); 47 expect(accessLocation, 5);
48 }); 48 });
49 }); 49 });
50 50
51 test('Stack can be used as middleware', () { 51 test('Pipeline can be used as middleware', () {
52 int accessLocation = 0; 52 int accessLocation = 0;
53 53
54 var middlewareA = createMiddleware(requestHandler: (request) { 54 var middlewareA = createMiddleware(requestHandler: (request) {
55 expect(accessLocation, 0); 55 expect(accessLocation, 0);
56 accessLocation = 1; 56 accessLocation = 1;
57 return null; 57 return null;
58 }, responseHandler: (response) { 58 }, responseHandler: (response) {
59 expect(accessLocation, 4); 59 expect(accessLocation, 4);
60 accessLocation = 5; 60 accessLocation = 5;
61 return response; 61 return response;
62 }); 62 });
63 63
64 var middlewareB = createMiddleware(requestHandler: (request) { 64 var middlewareB = createMiddleware(requestHandler: (request) {
65 expect(accessLocation, 1); 65 expect(accessLocation, 1);
66 accessLocation = 2; 66 accessLocation = 2;
67 return null; 67 return null;
68 }, responseHandler: (response) { 68 }, responseHandler: (response) {
69 expect(accessLocation, 3); 69 expect(accessLocation, 3);
70 accessLocation = 4; 70 accessLocation = 4;
71 return response; 71 return response;
72 }); 72 });
73 73
74 var innerStack = const Stack() 74 var innerPipeline = const Pipeline()
75 .addMiddleware(middlewareA) 75 .addMiddleware(middlewareA)
76 .addMiddleware(middlewareB); 76 .addMiddleware(middlewareB);
77 77
78 var handler = const Stack() 78 var handler = const Pipeline()
79 .addMiddleware(innerStack.middleware) 79 .addMiddleware(innerPipeline.middleware)
80 .addHandler((request) { 80 .addHandler((request) {
81 expect(accessLocation, 2); 81 expect(accessLocation, 2);
82 accessLocation = 3; 82 accessLocation = 3;
83 return syncHandler(request); 83 return syncHandler(request);
84 }); 84 });
85 85
86 return makeSimpleRequest(handler).then((response) { 86 return makeSimpleRequest(handler).then((response) {
87 expect(response, isNotNull); 87 expect(response, isNotNull);
88 expect(accessLocation, 5); 88 expect(accessLocation, 5);
89 }); 89 });
90 }); 90 });
91 } 91 }
OLDNEW
« no previous file with comments | « pkg/shelf/test/log_middleware_test.dart ('k') | pkg/shelf/test/stack_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698