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

Side by Side Diff: utils/tests/pub/pub_lish_test.dart

Issue 11830017: Fix ALL the pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 pub_lish_test; 5 library pub_lish_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:json'; 8 import 'dart:json' as json;
9 9
10 import 'test_pub.dart'; 10 import 'test_pub.dart';
11 import '../../../pkg/unittest/lib/unittest.dart'; 11 import '../../../pkg/unittest/lib/unittest.dart';
12 import '../../pub/io.dart'; 12 import '../../pub/io.dart';
13 13
14 void handleUploadForm(ScheduledServer server, [Map body]) { 14 void handleUploadForm(ScheduledServer server, [Map body]) {
15 server.handle('GET', '/packages/versions/new.json', (request, response) { 15 server.handle('GET', '/packages/versions/new.json', (request, response) {
16 return server.url.then((url) { 16 return server.url.then((url) {
17 expect(request.headers.value('authorization'), 17 expect(request.headers.value('authorization'),
18 equals('Bearer access token')); 18 equals('Bearer access token'));
19 19
20 if (body == null) { 20 if (body == null) {
21 body = { 21 body = {
22 'url': url.resolve('/upload').toString(), 22 'url': url.resolve('/upload').toString(),
23 'fields': { 23 'fields': {
24 'field1': 'value1', 24 'field1': 'value1',
25 'field2': 'value2' 25 'field2': 'value2'
26 } 26 }
27 }; 27 };
28 } 28 }
29 29
30 response.headers.contentType = new ContentType("application", "json"); 30 response.headers.contentType = new ContentType("application", "json");
31 response.outputStream.writeString(JSON.stringify(body)); 31 response.outputStream.writeString(json.stringify(body));
32 response.outputStream.close(); 32 response.outputStream.close();
33 }); 33 });
34 }); 34 });
35 } 35 }
36 36
37 void handleUpload(ScheduledServer server) { 37 void handleUpload(ScheduledServer server) {
38 server.handle('POST', '/upload', (request, response) { 38 server.handle('POST', '/upload', (request, response) {
39 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate 39 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate
40 // that the request body is correctly formatted. See issue 6952. 40 // that the request body is correctly formatted. See issue 6952.
41 return server.url.then((url) { 41 return server.url.then((url) {
(...skipping 10 matching lines...) Expand all
52 test('archives and uploads a package', () { 52 test('archives and uploads a package', () {
53 var server = new ScheduledServer(); 53 var server = new ScheduledServer();
54 credentialsFile(server, 'access token').scheduleCreate(); 54 credentialsFile(server, 'access token').scheduleCreate();
55 var pub = startPubLish(server); 55 var pub = startPubLish(server);
56 56
57 confirmPublish(pub); 57 confirmPublish(pub);
58 handleUploadForm(server); 58 handleUploadForm(server);
59 handleUpload(server); 59 handleUpload(server);
60 60
61 server.handle('GET', '/create', (request, response) { 61 server.handle('GET', '/create', (request, response) {
62 response.outputStream.writeString(JSON.stringify({ 62 response.outputStream.writeString(json.stringify({
63 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 63 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
64 })); 64 }));
65 response.outputStream.close(); 65 response.outputStream.close();
66 }); 66 });
67 67
68 // TODO(rnystrom): The confirm line is run together with this one because 68 // TODO(rnystrom): The confirm line is run together with this one because
69 // in normal usage, the user will have entered a newline on stdin which 69 // in normal usage, the user will have entered a newline on stdin which
70 // gets echoed to the terminal. Do something better here? 70 // gets echoed to the terminal. Do something better here?
71 expectLater(pub.nextLine(), equals( 71 expectLater(pub.nextLine(), equals(
72 'Looks great! Are you ready to upload your package (y/n)?' 72 'Looks great! Are you ready to upload your package (y/n)?'
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 dir(appPath, [pubspec(package)]).scheduleCreate(); 116 dir(appPath, [pubspec(package)]).scheduleCreate();
117 117
118 var server = new ScheduledServer(); 118 var server = new ScheduledServer();
119 credentialsFile(server, 'access token').scheduleCreate(); 119 credentialsFile(server, 'access token').scheduleCreate();
120 var pub = startPubLish(server); 120 var pub = startPubLish(server);
121 pub.writeLine("y"); 121 pub.writeLine("y");
122 handleUploadForm(server); 122 handleUploadForm(server);
123 handleUpload(server); 123 handleUpload(server);
124 124
125 server.handle('GET', '/create', (request, response) { 125 server.handle('GET', '/create', (request, response) {
126 response.outputStream.writeString(JSON.stringify({ 126 response.outputStream.writeString(json.stringify({
127 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 127 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
128 })); 128 }));
129 response.outputStream.close(); 129 response.outputStream.close();
130 }); 130 });
131 131
132 pub.shouldExit(0); 132 pub.shouldExit(0);
133 expectLater(pub.remainingStdout(), 133 expectLater(pub.remainingStdout(),
134 contains('Package test_pkg 1.0.0 uploaded!')); 134 contains('Package test_pkg 1.0.0 uploaded!'));
135 135
136 run(); 136 run();
137 }); 137 });
138 138
139 test('upload form provides an error', () { 139 test('upload form provides an error', () {
140 var server = new ScheduledServer(); 140 var server = new ScheduledServer();
141 credentialsFile(server, 'access token').scheduleCreate(); 141 credentialsFile(server, 'access token').scheduleCreate();
142 var pub = startPubLish(server); 142 var pub = startPubLish(server);
143 143
144 confirmPublish(pub); 144 confirmPublish(pub);
145 145
146 server.handle('GET', '/packages/versions/new.json', (request, response) { 146 server.handle('GET', '/packages/versions/new.json', (request, response) {
147 response.statusCode = 400; 147 response.statusCode = 400;
148 response.outputStream.writeString(JSON.stringify({ 148 response.outputStream.writeString(json.stringify({
149 'error': {'message': 'your request sucked'} 149 'error': {'message': 'your request sucked'}
150 })); 150 }));
151 response.outputStream.close(); 151 response.outputStream.close();
152 }); 152 });
153 153
154 expectLater(pub.nextErrLine(), equals('your request sucked')); 154 expectLater(pub.nextErrLine(), equals('your request sucked'));
155 pub.shouldExit(1); 155 pub.shouldExit(1);
156 156
157 run(); 157 run();
158 }); 158 });
(...skipping 26 matching lines...) Expand all
185 185
186 var body = { 186 var body = {
187 'fields': { 187 'fields': {
188 'field1': 'value1', 188 'field1': 'value1',
189 'field2': 'value2' 189 'field2': 'value2'
190 } 190 }
191 }; 191 };
192 192
193 handleUploadForm(server, body); 193 handleUploadForm(server, body);
194 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 194 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
195 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 195 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
196 pub.shouldExit(1); 196 pub.shouldExit(1);
197 197
198 run(); 198 run();
199 }); 199 });
200 200
201 test('upload form url is not a string', () { 201 test('upload form url is not a string', () {
202 var server = new ScheduledServer(); 202 var server = new ScheduledServer();
203 credentialsFile(server, 'access token').scheduleCreate(); 203 credentialsFile(server, 'access token').scheduleCreate();
204 var pub = startPubLish(server); 204 var pub = startPubLish(server);
205 205
206 confirmPublish(pub); 206 confirmPublish(pub);
207 207
208 var body = { 208 var body = {
209 'url': 12, 209 'url': 12,
210 'fields': { 210 'fields': {
211 'field1': 'value1', 211 'field1': 'value1',
212 'field2': 'value2' 212 'field2': 'value2'
213 } 213 }
214 }; 214 };
215 215
216 handleUploadForm(server, body); 216 handleUploadForm(server, body);
217 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 217 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
218 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 218 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
219 pub.shouldExit(1); 219 pub.shouldExit(1);
220 220
221 run(); 221 run();
222 }); 222 });
223 223
224 test('upload form is missing fields', () { 224 test('upload form is missing fields', () {
225 var server = new ScheduledServer(); 225 var server = new ScheduledServer();
226 credentialsFile(server, 'access token').scheduleCreate(); 226 credentialsFile(server, 'access token').scheduleCreate();
227 var pub = startPubLish(server); 227 var pub = startPubLish(server);
228 228
229 confirmPublish(pub); 229 confirmPublish(pub);
230 230
231 var body = {'url': 'http://example.com/upload'}; 231 var body = {'url': 'http://example.com/upload'};
232 handleUploadForm(server, body); 232 handleUploadForm(server, body);
233 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 233 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
234 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 234 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
235 pub.shouldExit(1); 235 pub.shouldExit(1);
236 236
237 run(); 237 run();
238 }); 238 });
239 239
240 test('upload form fields is not a map', () { 240 test('upload form fields is not a map', () {
241 var server = new ScheduledServer(); 241 var server = new ScheduledServer();
242 credentialsFile(server, 'access token').scheduleCreate(); 242 credentialsFile(server, 'access token').scheduleCreate();
243 var pub = startPubLish(server); 243 var pub = startPubLish(server);
244 244
245 confirmPublish(pub); 245 confirmPublish(pub);
246 246
247 var body = {'url': 'http://example.com/upload', 'fields': 12}; 247 var body = {'url': 'http://example.com/upload', 'fields': 12};
248 handleUploadForm(server, body); 248 handleUploadForm(server, body);
249 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 249 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
250 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 250 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
251 pub.shouldExit(1); 251 pub.shouldExit(1);
252 252
253 run(); 253 run();
254 }); 254 });
255 255
256 test('upload form fields has a non-string value', () { 256 test('upload form fields has a non-string value', () {
257 var server = new ScheduledServer(); 257 var server = new ScheduledServer();
258 credentialsFile(server, 'access token').scheduleCreate(); 258 credentialsFile(server, 'access token').scheduleCreate();
259 var pub = startPubLish(server); 259 var pub = startPubLish(server);
260 260
261 confirmPublish(pub); 261 confirmPublish(pub);
262 262
263 var body = { 263 var body = {
264 'url': 'http://example.com/upload', 264 'url': 'http://example.com/upload',
265 'fields': {'field': 12} 265 'fields': {'field': 12}
266 }; 266 };
267 handleUploadForm(server, body); 267 handleUploadForm(server, body);
268 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 268 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
269 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 269 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
270 pub.shouldExit(1); 270 pub.shouldExit(1);
271 271
272 run(); 272 run();
273 }); 273 });
274 274
275 test('cloud storage upload provides an error', () { 275 test('cloud storage upload provides an error', () {
276 var server = new ScheduledServer(); 276 var server = new ScheduledServer();
277 credentialsFile(server, 'access token').scheduleCreate(); 277 credentialsFile(server, 'access token').scheduleCreate();
278 var pub = startPubLish(server); 278 var pub = startPubLish(server);
279 279
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 var server = new ScheduledServer(); 319 var server = new ScheduledServer();
320 credentialsFile(server, 'access token').scheduleCreate(); 320 credentialsFile(server, 'access token').scheduleCreate();
321 var pub = startPubLish(server); 321 var pub = startPubLish(server);
322 322
323 confirmPublish(pub); 323 confirmPublish(pub);
324 handleUploadForm(server); 324 handleUploadForm(server);
325 handleUpload(server); 325 handleUpload(server);
326 326
327 server.handle('GET', '/create', (request, response) { 327 server.handle('GET', '/create', (request, response) {
328 response.statusCode = 400; 328 response.statusCode = 400;
329 response.outputStream.writeString(JSON.stringify({ 329 response.outputStream.writeString(json.stringify({
330 'error': {'message': 'Your package was too boring.'} 330 'error': {'message': 'Your package was too boring.'}
331 })); 331 }));
332 response.outputStream.close(); 332 response.outputStream.close();
333 }); 333 });
334 334
335 expectLater(pub.nextErrLine(), equals('Your package was too boring.')); 335 expectLater(pub.nextErrLine(), equals('Your package was too boring.'));
336 pub.shouldExit(1); 336 pub.shouldExit(1);
337 337
338 run(); 338 run();
339 }); 339 });
(...skipping 24 matching lines...) Expand all
364 credentialsFile(server, 'access token').scheduleCreate(); 364 credentialsFile(server, 'access token').scheduleCreate();
365 var pub = startPubLish(server); 365 var pub = startPubLish(server);
366 366
367 confirmPublish(pub); 367 confirmPublish(pub);
368 handleUploadForm(server); 368 handleUploadForm(server);
369 handleUpload(server); 369 handleUpload(server);
370 370
371 var body = {'error': 'Your package was too boring.'}; 371 var body = {'error': 'Your package was too boring.'};
372 server.handle('GET', '/create', (request, response) { 372 server.handle('GET', '/create', (request, response) {
373 response.statusCode = 400; 373 response.statusCode = 400;
374 response.outputStream.writeString(JSON.stringify(body)); 374 response.outputStream.writeString(json.stringify(body));
375 response.outputStream.close(); 375 response.outputStream.close();
376 }); 376 });
377 377
378 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 378 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
379 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 379 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
380 pub.shouldExit(1); 380 pub.shouldExit(1);
381 381
382 run(); 382 run();
383 }); 383 });
384 384
385 test('package creation provides a malformed success', () { 385 test('package creation provides a malformed success', () {
386 var server = new ScheduledServer(); 386 var server = new ScheduledServer();
387 credentialsFile(server, 'access token').scheduleCreate(); 387 credentialsFile(server, 'access token').scheduleCreate();
388 var pub = startPubLish(server); 388 var pub = startPubLish(server);
389 389
390 confirmPublish(pub); 390 confirmPublish(pub);
391 handleUploadForm(server); 391 handleUploadForm(server);
392 handleUpload(server); 392 handleUpload(server);
393 393
394 var body = {'success': 'Your package was awesome.'}; 394 var body = {'success': 'Your package was awesome.'};
395 server.handle('GET', '/create', (request, response) { 395 server.handle('GET', '/create', (request, response) {
396 response.outputStream.writeString(JSON.stringify(body)); 396 response.outputStream.writeString(json.stringify(body));
397 response.outputStream.close(); 397 response.outputStream.close();
398 }); 398 });
399 399
400 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 400 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
401 expectLater(pub.nextErrLine(), equals(JSON.stringify(body))); 401 expectLater(pub.nextErrLine(), equals(json.stringify(body)));
402 pub.shouldExit(1); 402 pub.shouldExit(1);
403 403
404 run(); 404 run();
405 }); 405 });
406 } 406 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698