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

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

Issue 12437022: Use scheduled_test for Pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-upload 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_test.dart ('k') | utils/tests/pub/sdk_constraint_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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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_uploader_test; 5 library pub_uploader_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 '../../../pkg/scheduled_test/lib/scheduled_process.dart';
11 import '../../../pkg/scheduled_test/lib/scheduled_server.dart';
12 import '../../../pkg/scheduled_test/lib/scheduled_test.dart';
13
14 import '../../pub/io.dart';
15 import '../../pub/utils.dart';
16 import 'descriptor.dart' as d;
10 import 'test_pub.dart'; 17 import 'test_pub.dart';
11 import '../../../pkg/unittest/lib/unittest.dart';
12 import '../../pub/utils.dart';
13 import '../../pub/io.dart';
14 18
15 final USAGE_STRING = ''' 19 final USAGE_STRING = '''
16 Manage uploaders for a package on pub.dartlang.org. 20 Manage uploaders for a package on pub.dartlang.org.
17 21
18 Usage: pub uploader [options] {add/remove} <email> 22 Usage: pub uploader [options] {add/remove} <email>
19 --server The package server on which the package is hosted 23 --server The package server on which the package is hosted
20 (defaults to "https://pub.dartlang.org") 24 (defaults to "https://pub.dartlang.org")
21 25
22 --package The package whose uploaders will be modified 26 --package The package whose uploaders will be modified
23 (defaults to the current package) 27 (defaults to the current package)
(...skipping 19 matching lines...) Expand all
43 }); 47 });
44 48
45 integration('when run with an invalid command', () { 49 integration('when run with an invalid command', () {
46 schedulePub(args: ['uploader', 'foo', 'email'], 50 schedulePub(args: ['uploader', 'foo', 'email'],
47 output: USAGE_STRING, exitCode: 64); 51 output: USAGE_STRING, exitCode: 64);
48 }); 52 });
49 }); 53 });
50 54
51 integration('adds an uploader', () { 55 integration('adds an uploader', () {
52 var server = new ScheduledServer(); 56 var server = new ScheduledServer();
53 credentialsFile(server, 'access token').scheduleCreate(); 57 d.credentialsFile(server, 'access token').create();
54 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); 58 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
55 59
56 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { 60 server.handle('POST', '/packages/pkg/uploaders.json', (request) {
57 expect(new ByteStream(request).toBytes().then((bodyBytes) { 61 expect(new ByteStream(request).toBytes().then((bodyBytes) {
58 expect(new String.fromCharCodes(bodyBytes), equals('email=email')); 62 expect(new String.fromCharCodes(bodyBytes), equals('email=email'));
59 63
60 response.headers.contentType = new ContentType("application", "json"); 64 request.response.headers.contentType =
61 response.write(json.stringify({ 65 new ContentType("application", "json");
66 request.response.write(json.stringify({
62 'success': {'message': 'Good job!'} 67 'success': {'message': 'Good job!'}
63 })); 68 }));
64 response.close(); 69 request.response.close();
65 }), completes); 70 }), completes);
66 }); 71 });
67 72
68 expectLater(pub.nextLine(), equals('Good job!')); 73 expect(pub.nextLine(), completion(equals('Good job!')));
69 pub.shouldExit(0); 74 pub.shouldExit(0);
70 }); 75 });
71 76
72 integration('removes an uploader', () { 77 integration('removes an uploader', () {
73 var server = new ScheduledServer(); 78 var server = new ScheduledServer();
74 credentialsFile(server, 'access token').scheduleCreate(); 79 d.credentialsFile(server, 'access token').create();
75 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); 80 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
76 81
77 server.handle('DELETE', '/packages/pkg/uploaders/email.json', 82 server.handle('DELETE', '/packages/pkg/uploaders/email.json', (request) {
78 (request, response) { 83 request.response.headers.contentType =
79 response.headers.contentType = new ContentType("application", "json"); 84 new ContentType("application", "json");
80 response.write(json.stringify({ 85 request.response.write(json.stringify({
81 'success': {'message': 'Good job!'} 86 'success': {'message': 'Good job!'}
82 })); 87 }));
83 response.close(); 88 request.response.close();
84 }); 89 });
85 90
86 expectLater(pub.nextLine(), equals('Good job!')); 91 expect(pub.nextLine(), completion(equals('Good job!')));
87 pub.shouldExit(0); 92 pub.shouldExit(0);
88 }); 93 });
89 94
90 integration('defaults to the current package', () { 95 integration('defaults to the current package', () {
91 normalPackage.scheduleCreate(); 96 d.validPackage.create();
92 97
93 var server = new ScheduledServer(); 98 var server = new ScheduledServer();
94 credentialsFile(server, 'access token').scheduleCreate(); 99 d.credentialsFile(server, 'access token').create();
95 var pub = startPubUploader(server, ['add', 'email']); 100 var pub = startPubUploader(server, ['add', 'email']);
96 101
97 server.handle('POST', '/packages/test_pkg/uploaders.json', 102 server.handle('POST', '/packages/test_pkg/uploaders.json', (request) {
98 (request, response) { 103 request.response.headers.contentType =
99 response.headers.contentType = new ContentType("application", "json"); 104 new ContentType("application", "json");
100 response.write(json.stringify({ 105 request.response.write(json.stringify({
101 'success': {'message': 'Good job!'} 106 'success': {'message': 'Good job!'}
102 })); 107 }));
103 response.close(); 108 request.response.close();
104 }); 109 });
105 110
106 expectLater(pub.nextLine(), equals('Good job!')); 111 expect(pub.nextLine(), completion(equals('Good job!')));
107 pub.shouldExit(0); 112 pub.shouldExit(0);
108 }); 113 });
109 114
110 integration('add provides an error', () { 115 integration('add provides an error', () {
111 var server = new ScheduledServer(); 116 var server = new ScheduledServer();
112 credentialsFile(server, 'access token').scheduleCreate(); 117 d.credentialsFile(server, 'access token').create();
113 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); 118 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
114 119
115 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { 120 server.handle('POST', '/packages/pkg/uploaders.json', (request) {
116 response.statusCode = 400; 121 request.response.statusCode = 400;
117 response.headers.contentType = new ContentType("application", "json"); 122 request.response.headers.contentType =
118 response.write(json.stringify({ 123 new ContentType("application", "json");
124 request.response.write(json.stringify({
119 'error': {'message': 'Bad job!'} 125 'error': {'message': 'Bad job!'}
120 })); 126 }));
121 response.close(); 127 request.response.close();
122 }); 128 });
123 129
124 expectLater(pub.nextErrLine(), equals('Bad job!')); 130 expect(pub.nextErrLine(), completion(equals('Bad job!')));
125 pub.shouldExit(1); 131 pub.shouldExit(1);
126 }); 132 });
127 133
128 integration('remove provides an error', () { 134 integration('remove provides an error', () {
129 var server = new ScheduledServer(); 135 var server = new ScheduledServer();
130 credentialsFile(server, 'access token').scheduleCreate(); 136 d.credentialsFile(server, 'access token').create();
131 var pub = startPubUploader(server, 137 var pub = startPubUploader(server,
132 ['--package', 'pkg', 'remove', 'e/mail']); 138 ['--package', 'pkg', 'remove', 'e/mail']);
133 139
134 server.handle('DELETE', '/packages/pkg/uploaders/e%2Fmail.json', 140 server.handle('DELETE', '/packages/pkg/uploaders/e%2Fmail.json', (request) {
135 (request, response) { 141 request.response.statusCode = 400;
136 response.statusCode = 400; 142 request.response.headers.contentType =
137 response.headers.contentType = new ContentType("application", "json"); 143 new ContentType("application", "json");
138 response.write(json.stringify({ 144 request.response.write(json.stringify({
139 'error': {'message': 'Bad job!'} 145 'error': {'message': 'Bad job!'}
140 })); 146 }));
141 response.close(); 147 request.response.close();
142 }); 148 });
143 149
144 expectLater(pub.nextErrLine(), equals('Bad job!')); 150 expect(pub.nextErrLine(), completion(equals('Bad job!')));
145 pub.shouldExit(1); 151 pub.shouldExit(1);
146 }); 152 });
147 153
148 integration('add provides invalid JSON', () { 154 integration('add provides invalid JSON', () {
149 var server = new ScheduledServer(); 155 var server = new ScheduledServer();
150 credentialsFile(server, 'access token').scheduleCreate(); 156 d.credentialsFile(server, 'access token').create();
151 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); 157 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']);
152 158
153 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { 159 server.handle('POST', '/packages/pkg/uploaders.json', (request) {
154 response.write("{not json"); 160 request.response.write("{not json");
155 response.close(); 161 request.response.close();
156 }); 162 });
157 163
158 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 164 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
159 expectLater(pub.nextErrLine(), equals('{not json')); 165 expect(pub.nextErrLine(), completion(equals('{not json')));
160 pub.shouldExit(1); 166 pub.shouldExit(1);
161 }); 167 });
162 168
163 integration('remove provides invalid JSON', () { 169 integration('remove provides invalid JSON', () {
164 var server = new ScheduledServer(); 170 var server = new ScheduledServer();
165 credentialsFile(server, 'access token').scheduleCreate(); 171 d.credentialsFile(server, 'access token').create();
166 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); 172 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']);
167 173
168 server.handle('DELETE', '/packages/pkg/uploaders/email.json', 174 server.handle('DELETE', '/packages/pkg/uploaders/email.json', (request) {
169 (request, response) { 175 request.response.write("{not json");
170 response.write("{not json"); 176 request.response.close();
171 response.close();
172 }); 177 });
173 178
174 expectLater(pub.nextErrLine(), equals('Invalid server response:')); 179 expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
175 expectLater(pub.nextErrLine(), equals('{not json')); 180 expect(pub.nextErrLine(), completion(equals('{not json')));
176 pub.shouldExit(1); 181 pub.shouldExit(1);
177 }); 182 });
178 } 183 }
OLDNEW
« no previous file with comments | « utils/tests/pub/pub_test.dart ('k') | utils/tests/pub/sdk_constraint_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698