| OLD | NEW |
| 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 'test_pub.dart'; |
| 11 import '../../../pkg/unittest/lib/unittest.dart'; | 11 import '../../../pkg/unittest/lib/unittest.dart'; |
| 12 import '../../pub/exit_codes.dart' as exit_codes; |
| 12 import '../../pub/io.dart'; | 13 import '../../pub/io.dart'; |
| 13 | 14 |
| 14 void handleUploadForm(ScheduledServer server, [Map body]) { | 15 void handleUploadForm(ScheduledServer server, [Map body]) { |
| 15 server.handle('GET', '/packages/versions/new.json', (request, response) { | 16 server.handle('GET', '/packages/versions/new.json', (request, response) { |
| 16 return server.url.then((url) { | 17 return server.url.then((url) { |
| 17 expect(request.headers.value('authorization'), | 18 expect(request.headers.value('authorization'), |
| 18 equals('Bearer access token')); | 19 equals('Bearer access token')); |
| 19 | 20 |
| 20 if (body == null) { | 21 if (body == null) { |
| 21 body = { | 22 body = { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 integration('preview package validation has a warning', () { | 98 integration('preview package validation has a warning', () { |
| 98 var pkg = package("test_pkg", "1.0.0"); | 99 var pkg = package("test_pkg", "1.0.0"); |
| 99 pkg["author"] = "Nathan Weizenbaum"; | 100 pkg["author"] = "Nathan Weizenbaum"; |
| 100 dir(appPath, [pubspec(pkg)]).scheduleCreate(); | 101 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 101 | 102 |
| 102 var server = new ScheduledServer(); | 103 var server = new ScheduledServer(); |
| 103 var pub = startPubLish(server, args: ['--dry-run']); | 104 var pub = startPubLish(server, args: ['--dry-run']); |
| 104 | 105 |
| 105 pub.shouldExit(0); | 106 pub.shouldExit(0); |
| 106 expectLater(pub.remainingStderr(), | 107 expectLater(pub.remainingStderr(), |
| 107 contains('Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml' | 108 contains('Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml' |
| 108 ' should have an email address\n' | 109 ' should have an email address\n' |
| 109 ' (e.g. "name <email>").\n\n' | 110 ' (e.g. "name <email>").\n\n' |
| 110 'Package has 1 warning.')); | 111 'Package has 1 warning.')); |
| 111 }); | 112 }); |
| 112 | 113 |
| 113 integration('preview package validation has no warnings', () { | 114 integration('preview package validation has no warnings', () { |
| 114 var pkg = package("test_pkg", "1.0.0"); | 115 var pkg = package("test_pkg", "1.0.0"); |
| 115 pkg["author"] = "Nathan Weizenbaum <nweiz@google.com>"; | 116 pkg["author"] = "Nathan Weizenbaum <nweiz@google.com>"; |
| 116 dir(appPath, [pubspec(pkg)]).scheduleCreate(); | 117 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 117 | 118 |
| 118 var server = new ScheduledServer(); | 119 var server = new ScheduledServer(); |
| 119 var pub = startPubLish(server, args: ['--dry-run']); | 120 var pub = startPubLish(server, args: ['--dry-run']); |
| 120 | 121 |
| 121 pub.shouldExit(0); | 122 pub.shouldExit(0); |
| 122 expectLater(pub.remainingStderr(), | 123 expectLater(pub.remainingStderr(), |
| 123 contains('Package has 0 warnings.')); | 124 contains('Package has 0 warnings.')); |
| 124 }); | 125 }); |
| 125 | 126 |
| 126 integration('package validation has a warning and is canceled', () { | 127 integration('package validation has a warning and is canceled', () { |
| 127 var pkg = package("test_pkg", "1.0.0"); | 128 var pkg = package("test_pkg", "1.0.0"); |
| 128 pkg["author"] = "Nathan Weizenbaum"; | 129 pkg["author"] = "Nathan Weizenbaum"; |
| 129 dir(appPath, [pubspec(pkg)]).scheduleCreate(); | 130 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 130 | 131 |
| 131 var server = new ScheduledServer(); | 132 var server = new ScheduledServer(); |
| 132 var pub = startPubLish(server); | 133 var pub = startPubLish(server); |
| 133 | 134 |
| 134 pub.writeLine("n"); | 135 pub.writeLine("n"); |
| 135 pub.shouldExit(0); | 136 pub.shouldExit(0); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 var body = {'success': 'Your package was awesome.'}; | 399 var body = {'success': 'Your package was awesome.'}; |
| 399 server.handle('GET', '/create', (request, response) { | 400 server.handle('GET', '/create', (request, response) { |
| 400 response.outputStream.writeString(json.stringify(body)); | 401 response.outputStream.writeString(json.stringify(body)); |
| 401 response.outputStream.close(); | 402 response.outputStream.close(); |
| 402 }); | 403 }); |
| 403 | 404 |
| 404 expectLater(pub.nextErrLine(), equals('Invalid server response:')); | 405 expectLater(pub.nextErrLine(), equals('Invalid server response:')); |
| 405 expectLater(pub.nextErrLine(), equals(json.stringify(body))); | 406 expectLater(pub.nextErrLine(), equals(json.stringify(body))); |
| 406 pub.shouldExit(1); | 407 pub.shouldExit(1); |
| 407 }); | 408 }); |
| 409 |
| 410 group('--force', () { |
| 411 setUp(() => normalPackage.scheduleCreate()); |
| 412 |
| 413 integration('cannot be combined with --dry-run', () { |
| 414 schedulePub(args: ['lish', '--force', '--dry-run'], |
| 415 error: "Cannot use both --force and --dry-run.", |
| 416 exitCode: exit_codes.USAGE); |
| 417 }); |
| 418 |
| 419 integration('publishes if there are no warnings or errors', () { |
| 420 var server = new ScheduledServer(); |
| 421 credentialsFile(server, 'access token').scheduleCreate(); |
| 422 var pub = startPubLish(server, args: ['--force']); |
| 423 |
| 424 handleUploadForm(server); |
| 425 handleUpload(server); |
| 426 |
| 427 server.handle('GET', '/create', (request, response) { |
| 428 response.outputStream.writeString(json.stringify({ |
| 429 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} |
| 430 })); |
| 431 response.outputStream.close(); |
| 432 }); |
| 433 |
| 434 pub.shouldExit(0); |
| 435 expectLater(pub.remainingStdout(), contains( |
| 436 'Package test_pkg 1.0.0 uploaded!')); |
| 437 }); |
| 438 |
| 439 integration('publishes if there are warnings', () { |
| 440 var pkg = package("test_pkg", "1.0.0"); |
| 441 pkg["author"] = "Nathan Weizenbaum"; |
| 442 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 443 |
| 444 var server = new ScheduledServer(); |
| 445 credentialsFile(server, 'access token').scheduleCreate(); |
| 446 var pub = startPubLish(server, args: ['--force']); |
| 447 |
| 448 handleUploadForm(server); |
| 449 handleUpload(server); |
| 450 |
| 451 server.handle('GET', '/create', (request, response) { |
| 452 response.outputStream.writeString(json.stringify({ |
| 453 'success': {'message': 'Package test_pkg 1.0.0 uploaded!'} |
| 454 })); |
| 455 response.outputStream.close(); |
| 456 }); |
| 457 |
| 458 pub.shouldExit(0); |
| 459 expectLater(pub.remainingStderr(), contains( |
| 460 'Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml' |
| 461 ' should have an email address\n' |
| 462 ' (e.g. "name <email>").')); |
| 463 expectLater(pub.remainingStdout(), contains( |
| 464 'Package test_pkg 1.0.0 uploaded!')); |
| 465 }); |
| 466 |
| 467 integration('does not publish if there are errors', () { |
| 468 var pkg = package("test_pkg", "1.0.0"); |
| 469 pkg.remove("homepage"); |
| 470 dir(appPath, [pubspec(pkg)]).scheduleCreate(); |
| 471 |
| 472 var server = new ScheduledServer(); |
| 473 var pub = startPubLish(server, args: ['--force']); |
| 474 |
| 475 pub.shouldExit(0); |
| 476 expectLater(pub.remainingStderr(), contains( |
| 477 "Sorry, your package is missing a requirement and can't be " |
| 478 "published yet.")); |
| 479 }); |
| 480 }); |
| 408 } | 481 } |
| OLD | NEW |