| 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_uploader_test; | 5 library pub_uploader_test; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 import 'dart: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/utils.dart'; | 12 import '../../pub/utils.dart'; |
| 13 import '../../pub/io.dart'; | 13 import '../../pub/io.dart'; |
| 14 | 14 |
| 15 final USAGE_STRING = ''' | 15 final USAGE_STRING = ''' |
| 16 Manage uploaders for a package on pub.dartlang.org. | 16 Manage uploaders for a package on pub.dartlang.org. |
| 17 | 17 |
| 18 Usage: pub uploader [options] {add/remove} <email> | 18 Usage: pub uploader [options] {add/remove} <email> |
| 19 --server The package server on which the package is hosted | 19 --server The package server on which the package is hosted |
| 20 (defaults to "https://pub.dartlang.org") | 20 (defaults to "https://pub.dartlang.org") |
| 21 | 21 |
| 22 --package The package whose uploaders will be modified | 22 --package The package whose uploaders will be modified |
| 23 (defaults to the current package) | 23 (defaults to the current package) |
| 24 '''; | 24 '''; |
| 25 | 25 |
| 26 ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) { | 26 ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) { |
| 27 var tokenEndpoint = server.url.transform((url) => | 27 var tokenEndpoint = server.url.then((url) => |
| 28 url.resolve('/token').toString()); | 28 url.resolve('/token').toString()); |
| 29 args = flatten(['uploader', '--server', tokenEndpoint, args]); | 29 args = flatten(['uploader', '--server', tokenEndpoint, args]); |
| 30 return startPub(args: args, tokenEndpoint: tokenEndpoint); | 30 return startPub(args: args, tokenEndpoint: tokenEndpoint); |
| 31 } | 31 } |
| 32 | 32 |
| 33 main() { | 33 main() { |
| 34 group('displays usage', () { | 34 group('displays usage', () { |
| 35 test('when run with no arguments', () => | 35 test('when run with no arguments', () => |
| 36 runPub(args: ['uploader'], output: USAGE_STRING, exitCode: 64)); | 36 runPub(args: ['uploader'], output: USAGE_STRING, exitCode: 64)); |
| 37 | 37 |
| 38 test('when run with only a command', () => | 38 test('when run with only a command', () => |
| 39 runPub(args: ['uploader', 'add'], output: USAGE_STRING, exitCode: 64)); | 39 runPub(args: ['uploader', 'add'], output: USAGE_STRING, exitCode: 64)); |
| 40 | 40 |
| 41 test('when run with an invalid command', () => runPub( | 41 test('when run with an invalid command', () => runPub( |
| 42 args: ['uploader', 'foo', 'email'], | 42 args: ['uploader', 'foo', 'email'], |
| 43 output: USAGE_STRING, exitCode: 64)); | 43 output: USAGE_STRING, exitCode: 64)); |
| 44 }); | 44 }); |
| 45 | 45 |
| 46 test('adds an uploader', () { | 46 test('adds an uploader', () { |
| 47 var server = new ScheduledServer(); | 47 var server = new ScheduledServer(); |
| 48 credentialsFile(server, 'access token').scheduleCreate(); | 48 credentialsFile(server, 'access token').scheduleCreate(); |
| 49 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | 49 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); |
| 50 | 50 |
| 51 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { | 51 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { |
| 52 expect(consumeInputStream(request.inputStream).transform((bodyBytes) { | 52 expect(consumeInputStream(request.inputStream).then((bodyBytes) { |
| 53 expect(new String.fromCharCodes(bodyBytes), equals('email=email')); | 53 expect(new String.fromCharCodes(bodyBytes), equals('email=email')); |
| 54 | 54 |
| 55 response.headers.contentType = new ContentType("application", "json"); | 55 response.headers.contentType = new ContentType("application", "json"); |
| 56 response.outputStream.writeString(JSON.stringify({ | 56 response.outputStream.writeString(json.stringify({ |
| 57 'success': {'message': 'Good job!'} | 57 'success': {'message': 'Good job!'} |
| 58 })); | 58 })); |
| 59 response.outputStream.close(); | 59 response.outputStream.close(); |
| 60 }), completes); | 60 }), completes); |
| 61 }); | 61 }); |
| 62 | 62 |
| 63 expectLater(pub.nextLine(), equals('Good job!')); | 63 expectLater(pub.nextLine(), equals('Good job!')); |
| 64 pub.shouldExit(0); | 64 pub.shouldExit(0); |
| 65 | 65 |
| 66 run(); | 66 run(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 response.outputStream.close(); | 178 response.outputStream.close(); |
| 179 }); | 179 }); |
| 180 | 180 |
| 181 expectLater(pub.nextErrLine(), equals('Invalid server response:')); | 181 expectLater(pub.nextErrLine(), equals('Invalid server response:')); |
| 182 expectLater(pub.nextErrLine(), equals('{not json')); | 182 expectLater(pub.nextErrLine(), equals('{not json')); |
| 183 pub.shouldExit(1); | 183 pub.shouldExit(1); |
| 184 | 184 |
| 185 run(); | 185 run(); |
| 186 }); | 186 }); |
| 187 } | 187 } |
| OLD | NEW |