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

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

Issue 12794007: Use scheduled_test for Pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 9 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 | « utils/tests/pub/pub_cache_test.dart ('k') | utils/tests/pub/pub_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) 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' as json; 8 import 'dart:json' as json;
9 9
10 import 'test_pub.dart'; 10 import '../../../pkg/scheduled_test/lib/scheduled_test.dart';
11 import '../../../pkg/unittest/lib/unittest.dart'; 11 import '../../../pkg/scheduled_test/lib/scheduled_server.dart';
12
12 import '../../pub/exit_codes.dart' as exit_codes; 13 import '../../pub/exit_codes.dart' as exit_codes;
13 import '../../pub/io.dart'; 14 import '../../pub/io.dart';
15 import 'descriptor.dart' as d;
16 import 'test_pub.dart';
14 17
15 void handleUploadForm(ScheduledServer server, [Map body]) { 18 void handleUploadForm(ScheduledServer server, [Map body]) {
16 server.handle('GET', '/packages/versions/new.json', (request, response) { 19 server.handle('GET', '/packages/versions/new.json', (request) {
17 return server.url.then((url) { 20 return server.url.then((url) {
18 expect(request.headers.value('authorization'), 21 expect(request.headers.value('authorization'),
19 equals('Bearer access token')); 22 equals('Bearer access token'));
20 23
21 if (body == null) { 24 if (body == null) {
22 body = { 25 body = {
23 'url': url.resolve('/upload').toString(), 26 'url': url.resolve('/upload').toString(),
24 'fields': { 27 'fields': {
25 'field1': 'value1', 28 'field1': 'value1',
26 'field2': 'value2' 29 'field2': 'value2'
27 } 30 }
28 }; 31 };
29 } 32 }
30 33
31 response.headers.contentType = new ContentType("application", "json"); 34 request.response.headers.contentType =
32 response.write(json.stringify(body)); 35 new ContentType("application", "json");
33 response.close(); 36 request.response.write(json.stringify(body));
37 request.response.close();
34 }); 38 });
35 }); 39 });
36 } 40 }
37 41
38 void handleUpload(ScheduledServer server) { 42 void handleUpload(ScheduledServer server) {
39 server.handle('POST', '/upload', (request, response) { 43 server.handle('POST', '/upload', (request) {
40 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate 44 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate
41 // that the request body is correctly formatted. See issue 6952. 45 // that the request body is correctly formatted. See issue 6952.
42 return drainStream(request).then((_) { 46 return drainStream(request).then((_) {
43 return server.url; 47 return server.url;
44 }).then((url) { 48 }).then((url) {
45 response.statusCode = 302; 49 request.response.statusCode = 302;
46 response.headers.set('location', url.resolve('/create').toString()); 50 request.response.headers.set(
47 response.close(); 51 'location', url.resolve('/create').toString());
52 request.response.close();
48 }); 53 });
49 }); 54 });
50 } 55 }
51 56
52 main() { 57 main() {
53 initConfig(); 58 initConfig();
54 setUp(() => normalPackage.scheduleCreate()); 59 setUp(() => d.validPackage.create());
55 60
56 integration('archives and uploads a package', () { 61 integration('archives and uploads a package', () {
57 var server = new ScheduledServer(); 62 var server = new ScheduledServer();
58 credentialsFile(server, 'access token').scheduleCreate(); 63 d.credentialsFile(server, 'access token').create();
59 var pub = startPubLish(server); 64 var pub = startPublish(server);
60 65
61 confirmPublish(pub); 66 confirmPublish(pub);
62 handleUploadForm(server); 67 handleUploadForm(server);
63 handleUpload(server); 68 handleUpload(server);
64 69
65 server.handle('GET', '/create', (request, response) { 70 server.handle('GET', '/create', (request) {
66 response.write(json.stringify({ 71 request.response.write(json.stringify({
67 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 72 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
68 })); 73 }));
69 response.close(); 74 request.response.close();
70 }); 75 });
71 76
72 // TODO(rnystrom): The confirm line is run together with this one because 77 // TODO(rnystrom): The confirm line is run together with this one because
73 // in normal usage, the user will have entered a newline on stdin which 78 // in normal usage, the user will have entered a newline on stdin which
74 // gets echoed to the terminal. Do something better here? 79 // gets echoed to the terminal. Do something better here?
75 expectLater(pub.nextLine(), equals( 80 expect(pub.nextLine(), completion(equals(
76 'Looks great! Are you ready to upload your package (y/n)?' 81 'Looks great! Are you ready to upload your package (y/n)?'
77 ' Package test_pkg 1.0.0 uploaded!')); 82 ' Package test_pkg 1.0.0 uploaded!')));
78 pub.shouldExit(0); 83 pub.shouldExit(0);
79 }); 84 });
80 85
81 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, we should 86 // TODO(nweiz): Once a multipart/form-data parser in Dart exists, we should
82 // test that "pub lish" chooses the correct files to publish. 87 // test that "pub lish" chooses the correct files to publish.
83 88
84 integration('package validation has an error', () { 89 integration('package validation has an error', () {
85 var pkg = package("test_pkg", "1.0.0"); 90 var pkg = packageMap("test_pkg", "1.0.0");
86 pkg.remove("homepage"); 91 pkg.remove("homepage");
87 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 92 d.dir(appPath, [d.pubspec(pkg)]).create();
88 93
89 var server = new ScheduledServer(); 94 var server = new ScheduledServer();
90 var pub = startPubLish(server); 95 var pub = startPublish(server);
91 96
92 pub.shouldExit(0); 97 pub.shouldExit(0);
93 expectLater(pub.remainingStderr(), 98 expect(pub.remainingStderr(), completion(contains(
94 contains("Sorry, your package is missing a requirement and can't be " 99 "Sorry, your package is missing a requirement and can't be published "
95 "published yet.")); 100 "yet.")));
96 }); 101 });
97 102
98 integration('preview package validation has a warning', () { 103 integration('preview package validation has a warning', () {
99 var pkg = package("test_pkg", "1.0.0"); 104 var pkg = packageMap("test_pkg", "1.0.0");
100 pkg["author"] = "Nathan Weizenbaum"; 105 pkg["author"] = "Nathan Weizenbaum";
101 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 106 d.dir(appPath, [d.pubspec(pkg)]).create();
102 107
103 var server = new ScheduledServer(); 108 var server = new ScheduledServer();
104 var pub = startPubLish(server, args: ['--dry-run']); 109 var pub = startPublish(server, args: ['--dry-run']);
105 110
106 pub.shouldExit(0); 111 pub.shouldExit(0);
107 expectLater(pub.remainingStderr(), 112 expect(pub.remainingStderr(), completion(contains(
108 contains('Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml' 113 'Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml should '
109 ' should have an email address\n' 114 'have an email address\n'
110 ' (e.g. "name <email>").\n\n' 115 ' (e.g. "name <email>").\n\n'
111 'Package has 1 warning.')); 116 'Package has 1 warning.')));
112 }); 117 });
113 118
114 integration('preview package validation has no warnings', () { 119 integration('preview package validation has no warnings', () {
115 var pkg = package("test_pkg", "1.0.0"); 120 var pkg = packageMap("test_pkg", "1.0.0");
116 pkg["author"] = "Nathan Weizenbaum <nweiz@google.com>"; 121 pkg["author"] = "Nathan Weizenbaum <nweiz@google.com>";
117 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 122 d.dir(appPath, [d.pubspec(pkg)]).create();
118 123
119 var server = new ScheduledServer(); 124 var server = new ScheduledServer();
120 var pub = startPubLish(server, args: ['--dry-run']); 125 var pub = startPublish(server, args: ['--dry-run']);
121 126
122 pub.shouldExit(0); 127 pub.shouldExit(0);
123 expectLater(pub.remainingStderr(), 128 expect(pub.remainingStderr(),
124 contains('Package has 0 warnings.')); 129 completion(contains('Package has 0 warnings.')));
125 }); 130 });
126 131
127 integration('package validation has a warning and is canceled', () { 132 integration('package validation has a warning and is canceled', () {
128 var pkg = package("test_pkg", "1.0.0"); 133 var pkg = packageMap("test_pkg", "1.0.0");
129 pkg["author"] = "Nathan Weizenbaum"; 134 pkg["author"] = "Nathan Weizenbaum";
130 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 135 d.dir(appPath, [d.pubspec(pkg)]).create();
131 136
132 var server = new ScheduledServer(); 137 var server = new ScheduledServer();
133 var pub = startPubLish(server); 138 var pub = startPublish(server);
134 139
135 pub.writeLine("n"); 140 pub.writeLine("n");
136 pub.shouldExit(0); 141 pub.shouldExit(0);
137 expectLater(pub.remainingStderr(), contains("Package upload canceled.")); 142 expect(pub.remainingStderr(),
143 completion(contains("Package upload canceled.")));
138 }); 144 });
139 145
140 integration('package validation has a warning and continues', () { 146 integration('package validation has a warning and continues', () {
141 var pkg = package("test_pkg", "1.0.0"); 147 var pkg = packageMap("test_pkg", "1.0.0");
142 pkg["author"] = "Nathan Weizenbaum"; 148 pkg["author"] = "Nathan Weizenbaum";
143 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 149 d.dir(appPath, [d.pubspec(pkg)]).create();
144 150
145 var server = new ScheduledServer(); 151 var server = new ScheduledServer();
146 credentialsFile(server, 'access token').scheduleCreate(); 152 d.credentialsFile(server, 'access token').create();
147 var pub = startPubLish(server); 153 var pub = startPublish(server);
148 pub.writeLine("y"); 154 pub.writeLine("y");
149 handleUploadForm(server); 155 handleUploadForm(server);
150 handleUpload(server); 156 handleUpload(server);
151 157
152 server.handle('GET', '/create', (request, response) { 158 server.handle('GET', '/create', (request) {
153 response.write(json.stringify({ 159 request.response.write(json.stringify({
154 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 160 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
155 })); 161 }));
156 response.close(); 162 request.response.close();
157 }); 163 });
158 164
159 pub.shouldExit(0); 165 pub.shouldExit(0);
160 expectLater(pub.remainingStdout(), 166 expect(pub.remainingStdout(),
161 contains('Package test_pkg 1.0.0 uploaded!')); 167 completion(contains('Package test_pkg 1.0.0 uploaded!')));
162 }); 168 });
163 169
164 integration('upload form provides an error', () { 170 integration('upload form provides an error', () {
165 var server = new ScheduledServer(); 171 var server = new ScheduledServer();
166 credentialsFile(server, 'access token').scheduleCreate(); 172 d.credentialsFile(server, 'access token').create();
167 var pub = startPubLish(server); 173 var pub = startPublish(server);
168 174
169 confirmPublish(pub); 175 confirmPublish(pub);
170 176
171 server.handle('GET', '/packages/versions/new.json', (request, response) { 177 server.handle('GET', '/packages/versions/new.json', (request) {
172 response.statusCode = 400; 178 request.response.statusCode = 400;
173 response.write(json.stringify({ 179 request.response.write(json.stringify({
174 'error': {'message': 'your request sucked'} 180 'error': {'message': 'your request sucked'}
175 })); 181 }));
176 response.close(); 182 request.response.close();
177 }); 183 });
178 184
179 expectLater(pub.nextErrLine(), equals('your request sucked')); 185 expect(pub.nextErrLine(), completion(equals('your request sucked')));
180 pub.shouldExit(1); 186 pub.shouldExit(1);
181 }); 187 });
182 188
183 integration('upload form provides invalid JSON', () { 189 integration('upload form provides invalid JSON', () {
184 var server = new ScheduledServer(); 190 var server = new ScheduledServer();
185 credentialsFile(server, 'access token').scheduleCreate(); 191 d.credentialsFile(server, 'access token').create();
186 var pub = startPubLish(server); 192 var pub = startPublish(server);
187 193
188 confirmPublish(pub); 194 confirmPublish(pub);
189 195
190 server.handle('GET', '/packages/versions/new.json', (request, response) { 196 server.handle('GET', '/packages/versions/new.json', (request) {
191 response.write('{not json'); 197 request.response.write('{not json');
192 response.close(); 198 request.response.close();
193 }); 199 });
194 200
195 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 201 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
196 expectLater(pub.nextErrLine(), equals('{not json')); 202 expect(pub.nextErrLine(), completion(equals('{not json')));
197 pub.shouldExit(1); 203 pub.shouldExit(1);
198 }); 204 });
199 205
200 integration('upload form is missing url', () { 206 integration('upload form is missing url', () {
201 var server = new ScheduledServer(); 207 var server = new ScheduledServer();
202 credentialsFile(server, 'access token').scheduleCreate(); 208 d.credentialsFile(server, 'access token').create();
203 var pub = startPubLish(server); 209 var pub = startPublish(server);
204 210
205 confirmPublish(pub); 211 confirmPublish(pub);
206 212
207 var body = { 213 var body = {
208 'fields': { 214 'fields': {
209 'field1': 'value1', 215 'field1': 'value1',
210 'field2': 'value2' 216 'field2': 'value2'
211 } 217 }
212 }; 218 };
213 219
214 handleUploadForm(server, body); 220 handleUploadForm(server, body);
215 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 221 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
216 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 222 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
217 pub.shouldExit(1); 223 pub.shouldExit(1);
218 }); 224 });
219 225
220 integration('upload form url is not a string', () { 226 integration('upload form url is not a string', () {
221 var server = new ScheduledServer(); 227 var server = new ScheduledServer();
222 credentialsFile(server, 'access token').scheduleCreate(); 228 d.credentialsFile(server, 'access token').create();
223 var pub = startPubLish(server); 229 var pub = startPublish(server);
224 230
225 confirmPublish(pub); 231 confirmPublish(pub);
226 232
227 var body = { 233 var body = {
228 'url': 12, 234 'url': 12,
229 'fields': { 235 'fields': {
230 'field1': 'value1', 236 'field1': 'value1',
231 'field2': 'value2' 237 'field2': 'value2'
232 } 238 }
233 }; 239 };
234 240
235 handleUploadForm(server, body); 241 handleUploadForm(server, body);
236 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 242 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
237 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 243 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
238 pub.shouldExit(1); 244 pub.shouldExit(1);
239 }); 245 });
240 246
241 integration('upload form is missing fields', () { 247 integration('upload form is missing fields', () {
242 var server = new ScheduledServer(); 248 var server = new ScheduledServer();
243 credentialsFile(server, 'access token').scheduleCreate(); 249 d.credentialsFile(server, 'access token').create();
244 var pub = startPubLish(server); 250 var pub = startPublish(server);
245 251
246 confirmPublish(pub); 252 confirmPublish(pub);
247 253
248 var body = {'url': 'http://example.com/upload'}; 254 var body = {'url': 'http://example.com/upload'};
249 handleUploadForm(server, body); 255 handleUploadForm(server, body);
250 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 256 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
251 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 257 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
252 pub.shouldExit(1); 258 pub.shouldExit(1);
253 }); 259 });
254 260
255 integration('upload form fields is not a map', () { 261 integration('upload form fields is not a map', () {
256 var server = new ScheduledServer(); 262 var server = new ScheduledServer();
257 credentialsFile(server, 'access token').scheduleCreate(); 263 d.credentialsFile(server, 'access token').create();
258 var pub = startPubLish(server); 264 var pub = startPublish(server);
259 265
260 confirmPublish(pub); 266 confirmPublish(pub);
261 267
262 var body = {'url': 'http://example.com/upload', 'fields': 12}; 268 var body = {'url': 'http://example.com/upload', 'fields': 12};
263 handleUploadForm(server, body); 269 handleUploadForm(server, body);
264 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 270 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
265 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 271 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
266 pub.shouldExit(1); 272 pub.shouldExit(1);
267 }); 273 });
268 274
269 integration('upload form fields has a non-string value', () { 275 integration('upload form fields has a non-string value', () {
270 var server = new ScheduledServer(); 276 var server = new ScheduledServer();
271 credentialsFile(server, 'access token').scheduleCreate(); 277 d.credentialsFile(server, 'access token').create();
272 var pub = startPubLish(server); 278 var pub = startPublish(server);
273 279
274 confirmPublish(pub); 280 confirmPublish(pub);
275 281
276 var body = { 282 var body = {
277 'url': 'http://example.com/upload', 283 'url': 'http://example.com/upload',
278 'fields': {'field': 12} 284 'fields': {'field': 12}
279 }; 285 };
280 handleUploadForm(server, body); 286 handleUploadForm(server, body);
281 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 287 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
282 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 288 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
283 pub.shouldExit(1); 289 pub.shouldExit(1);
284 }); 290 });
285 291
286 integration('cloud storage upload provides an error', () { 292 integration('cloud storage upload provides an error', () {
287 var server = new ScheduledServer(); 293 var server = new ScheduledServer();
288 credentialsFile(server, 'access token').scheduleCreate(); 294 d.credentialsFile(server, 'access token').create();
289 var pub = startPubLish(server); 295 var pub = startPublish(server);
290 296
291 confirmPublish(pub); 297 confirmPublish(pub);
292 handleUploadForm(server); 298 handleUploadForm(server);
293 299
294 server.handle('POST', '/upload', (request, response) { 300 server.handle('POST', '/upload', (request) {
295 return drainStream(request).then((_) { 301 return drainStream(request).then((_) {
296 response.statusCode = 400; 302 request.response.statusCode = 400;
297 response.headers.contentType = new ContentType('application', 'xml'); 303 request.response.headers.contentType =
298 response.write('<Error><Message>Your request sucked.' 304 new ContentType('application', 'xml');
305 request.response.write('<Error><Message>Your request sucked.'
299 '</Message></Error>'); 306 '</Message></Error>');
300 response.close(); 307 request.response.close();
301 }); 308 });
302 }); 309 });
303 310
304 // TODO(nweiz): This should use the server's error message once the client 311 // TODO(nweiz): This should use the server's error message once the client
305 // can parse the XML. 312 // can parse the XML.
306 expectLater(pub.nextErrLine(), equals('Failed to upload the package.')); 313 expect(pub.nextErrLine(),
314 completion(equals('Failed to upload the package.')));
307 pub.shouldExit(1); 315 pub.shouldExit(1);
308 }); 316 });
309 317
310 integration("cloud storage upload doesn't redirect", () { 318 integration("cloud storage upload doesn't redirect", () {
311 var server = new ScheduledServer(); 319 var server = new ScheduledServer();
312 credentialsFile(server, 'access token').scheduleCreate(); 320 d.credentialsFile(server, 'access token').create();
313 var pub = startPubLish(server); 321 var pub = startPublish(server);
314 322
315 confirmPublish(pub); 323 confirmPublish(pub);
316 handleUploadForm(server); 324 handleUploadForm(server);
317 325
318 server.handle('POST', '/upload', (request, response) { 326 server.handle('POST', '/upload', (request) {
319 return drainStream(request).then((_) { 327 return drainStream(request).then((_) {
320 // Don't set the location header. 328 // Don't set the location header.
321 response.close(); 329 request.response.close();
322 }); 330 });
323 }); 331 });
324 332
325 expectLater(pub.nextErrLine(), equals('Failed to upload the package.')); 333 expect(pub.nextErrLine(),
334 completion(equals('Failed to upload the package.')));
326 pub.shouldExit(1); 335 pub.shouldExit(1);
327 }); 336 });
328 337
329 integration('package creation provides an error', () { 338 integration('package creation provides an error', () {
330 var server = new ScheduledServer(); 339 var server = new ScheduledServer();
331 credentialsFile(server, 'access token').scheduleCreate(); 340 d.credentialsFile(server, 'access token').create();
332 var pub = startPubLish(server); 341 var pub = startPublish(server);
333 342
334 confirmPublish(pub); 343 confirmPublish(pub);
335 handleUploadForm(server); 344 handleUploadForm(server);
336 handleUpload(server); 345 handleUpload(server);
337 346
338 server.handle('GET', '/create', (request, response) { 347 server.handle('GET', '/create', (request) {
339 response.statusCode = 400; 348 request.response.statusCode = 400;
340 response.write(json.stringify({ 349 request.response.write(json.stringify({
341 'error': {'message': 'Your package was too boring.'} 350 'error': {'message': 'Your package was too boring.'}
342 })); 351 }));
343 response.close(); 352 request.response.close();
344 }); 353 });
345 354
346 expectLater(pub.nextErrLine(), equals('Your package was too boring.')); 355 expect(pub.nextErrLine(),
356 completion(equals('Your package was too boring.')));
347 pub.shouldExit(1); 357 pub.shouldExit(1);
348 }); 358 });
349 359
350 integration('package creation provides invalid JSON', () { 360 integration('package creation provides invalid JSON', () {
351 var server = new ScheduledServer(); 361 var server = new ScheduledServer();
352 credentialsFile(server, 'access token').scheduleCreate(); 362 d.credentialsFile(server, 'access token').create();
353 var pub = startPubLish(server); 363 var pub = startPublish(server);
354 364
355 confirmPublish(pub); 365 confirmPublish(pub);
356 handleUploadForm(server); 366 handleUploadForm(server);
357 handleUpload(server); 367 handleUpload(server);
358 368
359 server.handle('GET', '/create', (request, response) { 369 server.handle('GET', '/create', (request) {
360 response.write('{not json'); 370 request.response.write('{not json');
361 response.close(); 371 request.response.close();
362 }); 372 });
363 373
364 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 374 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
365 expectLater(pub.nextErrLine(), equals('{not json')); 375 expect(pub.nextErrLine(), completion(equals('{not json')));
366 pub.shouldExit(1); 376 pub.shouldExit(1);
367 }); 377 });
368 378
369 integration('package creation provides a malformed error', () { 379 integration('package creation provides a malformed error', () {
370 var server = new ScheduledServer(); 380 var server = new ScheduledServer();
371 credentialsFile(server, 'access token').scheduleCreate(); 381 d.credentialsFile(server, 'access token').create();
372 var pub = startPubLish(server); 382 var pub = startPublish(server);
373 383
374 confirmPublish(pub); 384 confirmPublish(pub);
375 handleUploadForm(server); 385 handleUploadForm(server);
376 handleUpload(server); 386 handleUpload(server);
377 387
378 var body = {'error': 'Your package was too boring.'}; 388 var body = {'error': 'Your package was too boring.'};
379 server.handle('GET', '/create', (request, response) { 389 server.handle('GET', '/create', (request) {
380 response.statusCode = 400; 390 request.response.statusCode = 400;
381 response.write(json.stringify(body)); 391 request.response.write(json.stringify(body));
382 response.close(); 392 request.response.close();
383 }); 393 });
384 394
385 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 395 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
386 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 396 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
387 pub.shouldExit(1); 397 pub.shouldExit(1);
388 }); 398 });
389 399
390 integration('package creation provides a malformed success', () { 400 integration('package creation provides a malformed success', () {
391 var server = new ScheduledServer(); 401 var server = new ScheduledServer();
392 credentialsFile(server, 'access token').scheduleCreate(); 402 d.credentialsFile(server, 'access token').create();
393 var pub = startPubLish(server); 403 var pub = startPublish(server);
394 404
395 confirmPublish(pub); 405 confirmPublish(pub);
396 handleUploadForm(server); 406 handleUploadForm(server);
397 handleUpload(server); 407 handleUpload(server);
398 408
399 var body = {'success': 'Your package was awesome.'}; 409 var body = {'success': 'Your package was awesome.'};
400 server.handle('GET', '/create', (request, response) { 410 server.handle('GET', '/create', (request) {
401 response.write(json.stringify(body)); 411 request.response.write(json.stringify(body));
402 response.close(); 412 request.response.close();
403 }); 413 });
404 414
405 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 415 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
406 expectLater(pub.nextErrLine(), equals(json.stringify(body))); 416 expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
407 pub.shouldExit(1); 417 pub.shouldExit(1);
408 }); 418 });
409 419
410 group('--force', () { 420 group('--force', () {
411 setUp(() => normalPackage.scheduleCreate()); 421 setUp(() => d.validPackage.create());
412 422
413 integration('cannot be combined with --dry-run', () { 423 integration('cannot be combined with --dry-run', () {
414 schedulePub(args: ['lish', '--force', '--dry-run'], 424 schedulePub(args: ['lish', '--force', '--dry-run'],
415 error: "Cannot use both --force and --dry-run.", 425 error: "Cannot use both --force and --dry-run.",
416 exitCode: exit_codes.USAGE); 426 exitCode: exit_codes.USAGE);
417 }); 427 });
418 428
419 integration('publishes if there are no warnings or errors', () { 429 integration('publishes if there are no warnings or errors', () {
420 var server = new ScheduledServer(); 430 var server = new ScheduledServer();
421 credentialsFile(server, 'access token').scheduleCreate(); 431 d.credentialsFile(server, 'access token').create();
422 var pub = startPubLish(server, args: ['--force']); 432 var pub = startPublish(server, args: ['--force']);
423 433
424 handleUploadForm(server); 434 handleUploadForm(server);
425 handleUpload(server); 435 handleUpload(server);
426 436
427 server.handle('GET', '/create', (request, response) { 437 server.handle('GET', '/create', (request) {
428 response.write(json.stringify({ 438 request.response.write(json.stringify({
429 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 439 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
430 })); 440 }));
431 response.close(); 441 request.response.close();
432 }); 442 });
433 443
434 pub.shouldExit(0); 444 pub.shouldExit(0);
435 expectLater(pub.remainingStdout(), contains( 445 expect(pub.remainingStdout(), completion(contains(
436 'Package test_pkg 1.0.0 uploaded!')); 446 'Package test_pkg 1.0.0 uploaded!')));
437 }); 447 });
438 448
439 integration('publishes if there are warnings', () { 449 integration('publishes if there are warnings', () {
440 var pkg = package("test_pkg", "1.0.0"); 450 var pkg = packageMap("test_pkg", "1.0.0");
441 pkg["author"] = "Nathan Weizenbaum"; 451 pkg["author"] = "Nathan Weizenbaum";
442 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 452 d.dir(appPath, [d.pubspec(pkg)]).create();
443 453
444 var server = new ScheduledServer(); 454 var server = new ScheduledServer();
445 credentialsFile(server, 'access token').scheduleCreate(); 455 d.credentialsFile(server, 'access token').create();
446 var pub = startPubLish(server, args: ['--force']); 456 var pub = startPublish(server, args: ['--force']);
447 457
448 handleUploadForm(server); 458 handleUploadForm(server);
449 handleUpload(server); 459 handleUpload(server);
450 460
451 server.handle('GET', '/create', (request, response) { 461 server.handle('GET', '/create', (request) {
452 response.write(json.stringify({ 462 request.response.write(json.stringify({
453 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} 463 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
454 })); 464 }));
455 response.close(); 465 request.response.close();
456 }); 466 });
457 467
458 pub.shouldExit(0); 468 pub.shouldExit(0);
459 expectLater(pub.remainingStderr(), contains( 469 expect(pub.remainingStderr(), completion(contains(
460 'Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml' 470 'Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml'
461 ' should have an email address\n' 471 ' should have an email address\n'
462 ' (e.g. "name <email>").')); 472 ' (e.g. "name <email>").')));
463 expectLater(pub.remainingStdout(), contains( 473 expect(pub.remainingStdout(), completion(contains(
464 'Package test_pkg 1.0.0 uploaded!')); 474 'Package test_pkg 1.0.0 uploaded!')));
465 }); 475 });
466 476
467 integration('does not publish if there are errors', () { 477 integration('does not publish if there are errors', () {
468 var pkg = package("test_pkg", "1.0.0"); 478 var pkg = packageMap("test_pkg", "1.0.0");
469 pkg.remove("homepage"); 479 pkg.remove("homepage");
470 dir(appPath, [pubspec(pkg)]).scheduleCreate(); 480 d.dir(appPath, [d.pubspec(pkg)]).create();
471 481
472 var server = new ScheduledServer(); 482 var server = new ScheduledServer();
473 var pub = startPubLish(server, args: ['--force']); 483 var pub = startPublish(server, args: ['--force']);
474 484
475 pub.shouldExit(0); 485 pub.shouldExit(0);
476 expectLater(pub.remainingStderr(), contains( 486 expect(pub.remainingStderr(), completion(contains(
477 "Sorry, your package is missing a requirement and can't be " 487 "Sorry, your package is missing a requirement and can't be "
478 "published yet.")); 488 "published yet.")));
479 }); 489 });
480 }); 490 });
481 } 491 }
OLDNEW
« no previous file with comments | « utils/tests/pub/pub_cache_test.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698