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

Unified Diff: utils/tests/pub/pub_uploader_test.dart

Issue 11569046: Add a pub command for managing uploaders for packages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tests/pub/pub_uploader_test.dart
diff --git a/utils/tests/pub/pub_uploader_test.dart b/utils/tests/pub/pub_uploader_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7fb7565f5bceb6bcf8e3a91a91e31dc6dd391329
--- /dev/null
+++ b/utils/tests/pub/pub_uploader_test.dart
@@ -0,0 +1,186 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library pub_uploader_test;
+
+import 'dart:io';
+import 'dart:json';
+
+import 'test_pub.dart';
+import '../../../pkg/unittest/lib/unittest.dart';
+import '../../pub/utils.dart';
+import '../../pub/io.dart';
+
+final USAGE_STRING = '''
+ Manage uploaders for a package on pub.dartlang.org.
+
+ Usage: pub uploader [options] {add/remove} <email>
+ --server The package server on which the package is hosted
+ (defaults to "https://pub.dartlang.org")
+
+ --package The package whose uploaders will be modified
+ (defaults to the current package)
+ ''';
+
+ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) {
+ var tokenEndpoint = server.url.transform((url) =>
+ url.resolve('/token').toString());
+ args = flatten(['uploader', '--server', tokenEndpoint, args]);
+ return startPub(args: args, tokenEndpoint: tokenEndpoint);
+}
+
+main() {
+ group('displays usage', () {
+ test('when run with no arguments', () =>
+ runPub(args: ['uploader'], output: USAGE_STRING, exitCode: 64));
+
+ test('when run with only a command', () =>
+ runPub(args: ['uploader', 'add'], output: USAGE_STRING, exitCode: 64));
+
+ test('when run with an invalid command', () => runPub(
+ args: ['uploader', 'foo', 'email'],
+ output: USAGE_STRING, exitCode: 64));
+ });
+
+ test('adds an uploader', () {
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
+
+ server.handle('POST', '/packages/pkg/uploaders.json', (request, response) {
+ expect(consumeInputStream(request.inputStream).transform((bodyBytes) {
+ expect(new String.fromCharCodes(bodyBytes), equals('email=email'));
+
+ response.headers.contentType = new ContentType("application", "json");
+ response.outputStream.writeString(JSON.stringify({
+ 'success': {'message': 'Good job!'}
+ }));
+ response.outputStream.close();
+ }), completes);
+ });
+
+ expectLater(pub.nextLine(), equals('Good job!'));
+ pub.shouldExit(0);
+
+ run();
+ });
+
+ test('removes an uploader', () {
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
+
+ server.handle('DELETE', '/packages/pkg/uploaders/email.json',
+ (request, response) {
+ response.headers.contentType = new ContentType("application", "json");
+ response.outputStream.writeString(JSON.stringify({
+ 'success': {'message': 'Good job!'}
+ }));
+ response.outputStream.close();
+ });
+
+ expectLater(pub.nextLine(), equals('Good job!'));
+ pub.shouldExit(0);
+
+ run();
+ });
+
+ test('defaults to the current package', () {
+ normalPackage.scheduleCreate();
+
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['add', 'email']);
+
+ server.handle('POST', '/packages/test_pkg/uploaders.json',
+ (request, response) {
+ response.headers.contentType = new ContentType("application", "json");
+ response.outputStream.writeString(JSON.stringify({
+ 'success': {'message': 'Good job!'}
+ }));
+ response.outputStream.close();
+ });
+
+ expectLater(pub.nextLine(), equals('Good job!'));
+ pub.shouldExit(0);
+
+ run();
+ });
+
+ test('add provides an error', () {
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
+
+ server.handle('POST', '/packages/pkg/uploaders.json', (request, response) {
+ response.statusCode = 400;
+ response.headers.contentType = new ContentType("application", "json");
+ response.outputStream.writeString(JSON.stringify({
+ 'error': {'message': 'Bad job!'}
+ }));
+ response.outputStream.close();
+ });
+
+ expectLater(pub.nextErrLine(), equals('Bad job!'));
+ pub.shouldExit(1);
+
+ run();
+ });
+
+ test('remove provides an error', () {
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
+
+ server.handle('DELETE', '/packages/pkg/uploaders/email.json',
+ (request, response) {
+ response.statusCode = 400;
+ response.headers.contentType = new ContentType("application", "json");
+ response.outputStream.writeString(JSON.stringify({
+ 'error': {'message': 'Bad job!'}
+ }));
+ response.outputStream.close();
+ });
+
+ expectLater(pub.nextErrLine(), equals('Bad job!'));
+ pub.shouldExit(1);
+
+ run();
+ });
+
+ test('add provides invalid JSON', () {
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
+
+ server.handle('POST', '/packages/pkg/uploaders.json', (request, response) {
+ response.outputStream.writeString("{not json");
+ response.outputStream.close();
+ });
+
+ expectLater(pub.nextErrLine(), equals('Invalid server response:'));
+ expectLater(pub.nextErrLine(), equals('{not json'));
+ pub.shouldExit(1);
+
+ run();
+ });
+
+ test('remove provides invalid JSON', () {
+ var server = new ScheduledServer();
+ credentialsFile(server, 'access token').scheduleCreate();
+ var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
+
+ server.handle('DELETE', '/packages/pkg/uploaders/email.json',
+ (request, response) {
+ response.outputStream.writeString("{not json");
+ response.outputStream.close();
+ });
+
+ expectLater(pub.nextErrLine(), equals('Invalid server response:'));
+ expectLater(pub.nextErrLine(), equals('{not json'));
+ pub.shouldExit(1);
+
+ run();
+ });
+}
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698