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