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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | utils/tests/pub/test_pub.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library pub_uploader_test;
6
7 import 'dart:io';
8 import 'dart:json';
9
10 import 'test_pub.dart';
11 import '../../../pkg/unittest/lib/unittest.dart';
12 import '../../pub/utils.dart';
13 import '../../pub/io.dart';
14
15 final USAGE_STRING = '''
16 Manage uploaders for a package on pub.dartlang.org.
17
18 Usage: pub uploader [options] {add/remove} <email>
19 --server The package server on which the package is hosted
20 (defaults to "https://pub.dartlang.org")
21
22 --package The package whose uploaders will be modified
23 (defaults to the current package)
24 ''';
25
26 ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) {
27 var tokenEndpoint = server.url.transform((url) =>
28 url.resolve('/token').toString());
29 args = flatten(['uploader', '--server', tokenEndpoint, args]);
30 return startPub(args: args, tokenEndpoint: tokenEndpoint);
31 }
32
33 main() {
34 group('displays usage', () {
35 test('when run with no arguments', () =>
36 runPub(args: ['uploader'], output: USAGE_STRING, exitCode: 64));
37
38 test('when run with only a command', () =>
39 runPub(args: ['uploader', 'add'], output: USAGE_STRING, exitCode: 64));
40
41 test('when run with an invalid command', () => runPub(
42 args: ['uploader', 'foo', 'email'],
43 output: USAGE_STRING, exitCode: 64));
44 });
45
46 test('adds an uploader', () {
47 var server = new ScheduledServer();
48 credentialsFile(server, 'access token').scheduleCreate();
49 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
50
51 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) {
52 expect(consumeInputStream(request.inputStream).transform((bodyBytes) {
53 expect(new String.fromCharCodes(bodyBytes), equals('email=email'));
54
55 response.headers.contentType = new ContentType("application", "json");
56 response.outputStream.writeString(JSON.stringify({
57 'success': {'message': 'Good job!'}
58 }));
59 response.outputStream.close();
60 }), completes);
61 });
62
63 expectLater(pub.nextLine(), equals('Good job!'));
64 pub.shouldExit(0);
65
66 run();
67 });
68
69 test('removes an uploader', () {
70 var server = new ScheduledServer();
71 credentialsFile(server, 'access token').scheduleCreate();
72 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
73
74 server.handle('DELETE', '/packages/pkg/uploaders/email.json',
75 (request, response) {
76 response.headers.contentType = new ContentType("application", "json");
77 response.outputStream.writeString(JSON.stringify({
78 'success': {'message': 'Good job!'}
79 }));
80 response.outputStream.close();
81 });
82
83 expectLater(pub.nextLine(), equals('Good job!'));
84 pub.shouldExit(0);
85
86 run();
87 });
88
89 test('defaults to the current package', () {
90 normalPackage.scheduleCreate();
91
92 var server = new ScheduledServer();
93 credentialsFile(server, 'access token').scheduleCreate();
94 var pub = startPubUploader(server, ['add', 'email']);
95
96 server.handle('POST', '/packages/test_pkg/uploaders.json',
97 (request, response) {
98 response.headers.contentType = new ContentType("application", "json");
99 response.outputStream.writeString(JSON.stringify({
100 'success': {'message': 'Good job!'}
101 }));
102 response.outputStream.close();
103 });
104
105 expectLater(pub.nextLine(), equals('Good job!'));
106 pub.shouldExit(0);
107
108 run();
109 });
110
111 test('add provides an error', () {
112 var server = new ScheduledServer();
113 credentialsFile(server, 'access token').scheduleCreate();
114 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
115
116 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) {
117 response.statusCode = 400;
118 response.headers.contentType = new ContentType("application", "json");
119 response.outputStream.writeString(JSON.stringify({
120 'error': {'message': 'Bad job!'}
121 }));
122 response.outputStream.close();
123 });
124
125 expectLater(pub.nextErrLine(), equals('Bad job!'));
126 pub.shouldExit(1);
127
128 run();
129 });
130
131 test('remove provides an error', () {
132 var server = new ScheduledServer();
133 credentialsFile(server, 'access token').scheduleCreate();
134 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
135
136 server.handle('DELETE', '/packages/pkg/uploaders/email.json',
137 (request, response) {
138 response.statusCode = 400;
139 response.headers.contentType = new ContentType("application", "json");
140 response.outputStream.writeString(JSON.stringify({
141 'error': {'message': 'Bad job!'}
142 }));
143 response.outputStream.close();
144 });
145
146 expectLater(pub.nextErrLine(), equals('Bad job!'));
147 pub.shouldExit(1);
148
149 run();
150 });
151
152 test('add provides invalid JSON', () {
153 var server = new ScheduledServer();
154 credentialsFile(server, 'access token').scheduleCreate();
155 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
156
157 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) {
158 response.outputStream.writeString("{not json");
159 response.outputStream.close();
160 });
161
162 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
163 expectLater(pub.nextErrLine(), equals('{not json'));
164 pub.shouldExit(1);
165
166 run();
167 });
168
169 test('remove provides invalid JSON', () {
170 var server = new ScheduledServer();
171 credentialsFile(server, 'access token').scheduleCreate();
172 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
173
174 server.handle('DELETE', '/packages/pkg/uploaders/email.json',
175 (request, response) {
176 response.outputStream.writeString("{not json");
177 response.outputStream.close();
178 });
179
180 expectLater(pub.nextErrLine(), equals('Invalid server response:'));
181 expectLater(pub.nextErrLine(), equals('{not json'));
182 pub.shouldExit(1);
183
184 run();
185 });
186 }
OLDNEW
« 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