| 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:convert'; | 7 import 'dart:convert'; | 
| 8 import 'dart:io'; | 8 import 'dart:io'; | 
| 9 | 9 | 
| 10 import 'package:scheduled_test/scheduled_process.dart'; | 10 import 'package:scheduled_test/scheduled_process.dart'; | 
| 11 import 'package:scheduled_test/scheduled_server.dart'; | 11 import 'package:scheduled_test/scheduled_server.dart'; | 
| 12 import 'package:scheduled_test/scheduled_test.dart'; | 12 import 'package:scheduled_test/scheduled_test.dart'; | 
| 13 | 13 | 
|  | 14 import '../lib/src/exit_codes.dart' as exit_codes; | 
| 14 import '../lib/src/io.dart'; | 15 import '../lib/src/io.dart'; | 
| 15 import '../lib/src/utils.dart'; | 16 import '../lib/src/utils.dart'; | 
| 16 import 'descriptor.dart' as d; | 17 import 'descriptor.dart' as d; | 
| 17 import 'test_pub.dart'; | 18 import 'test_pub.dart'; | 
| 18 | 19 | 
| 19 final USAGE_STRING = ''' | 20 final USAGE_STRING = ''' | 
| 20 Manage uploaders for a package on pub.dartlang.org. | 21 Manage uploaders for a package on pub.dartlang.org. | 
| 21 | 22 | 
| 22 Usage: pub uploader [options] {add/remove} <email> | 23 Usage: pub uploader [options] {add/remove} <email> | 
| 23 -h, --help       Print usage information for this command. | 24 -h, --help       Print usage information for this command. | 
| 24     --server     The package server on which the package is hosted. | 25     --server     The package server on which the package is hosted. | 
| 25                  (defaults to "https://pub.dartlang.org") | 26                  (defaults to "https://pub.dartlang.org") | 
| 26 | 27 | 
| 27     --package    The package whose uploaders will be modified. | 28     --package    The package whose uploaders will be modified. | 
| 28                  (defaults to the current package) | 29                  (defaults to the current package) | 
| 29 '''; | 30 '''; | 
| 30 | 31 | 
| 31 ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) { | 32 ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) { | 
| 32   var tokenEndpoint = server.url.then((url) => | 33   var tokenEndpoint = server.url.then((url) => | 
| 33       url.resolve('/token').toString()); | 34       url.resolve('/token').toString()); | 
| 34   args = flatten(['uploader', '--server', tokenEndpoint, args]); | 35   args = flatten(['uploader', '--server', tokenEndpoint, args]); | 
| 35   return startPub(args: args, tokenEndpoint: tokenEndpoint); | 36   return startPub(args: args, tokenEndpoint: tokenEndpoint); | 
| 36 } | 37 } | 
| 37 | 38 | 
| 38 main() { | 39 main() { | 
| 39   initConfig(); | 40   initConfig(); | 
| 40   group('displays usage', () { | 41   group('displays usage', () { | 
| 41     integration('when run with no arguments', () { | 42     integration('when run with no arguments', () { | 
| 42       schedulePub(args: ['uploader'], | 43       schedulePub(args: ['uploader'], | 
| 43           output: USAGE_STRING, exitCode: 64); | 44           output: USAGE_STRING, exitCode: exit_codes.USAGE); | 
| 44     }); | 45     }); | 
| 45 | 46 | 
| 46     integration('when run with only a command', () { | 47     integration('when run with only a command', () { | 
| 47       schedulePub(args: ['uploader', 'add'], | 48       schedulePub(args: ['uploader', 'add'], | 
| 48           output: USAGE_STRING, exitCode: 64); | 49           output: USAGE_STRING, exitCode: exit_codes.USAGE); | 
| 49     }); | 50     }); | 
| 50 | 51 | 
| 51     integration('when run with an invalid command', () { | 52     integration('when run with an invalid command', () { | 
| 52       schedulePub(args: ['uploader', 'foo', 'email'], | 53       schedulePub(args: ['uploader', 'foo', 'email'], | 
| 53           output: USAGE_STRING, exitCode: 64); | 54           output: USAGE_STRING, exitCode: exit_codes.USAGE); | 
| 54     }); | 55     }); | 
| 55   }); | 56   }); | 
| 56 | 57 | 
| 57   integration('adds an uploader', () { | 58   integration('adds an uploader', () { | 
| 58     var server = new ScheduledServer(); | 59     var server = new ScheduledServer(); | 
| 59     d.credentialsFile(server, 'access token').create(); | 60     d.credentialsFile(server, 'access token').create(); | 
| 60     var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | 61     var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | 
| 61 | 62 | 
| 62     server.handle('POST', '/api/packages/pkg/uploaders', (request) { | 63     server.handle('POST', '/api/packages/pkg/uploaders', (request) { | 
| 63       expect(new ByteStream(request).toBytes().then((bodyBytes) { | 64       expect(new ByteStream(request).toBytes().then((bodyBytes) { | 
| 64         expect(new String.fromCharCodes(bodyBytes), equals('email=email')); | 65         expect(new String.fromCharCodes(bodyBytes), equals('email=email')); | 
| 65 | 66 | 
| 66         request.response.headers.contentType = | 67         request.response.headers.contentType = | 
| 67             new ContentType("application", "json"); | 68             new ContentType("application", "json"); | 
| 68         request.response.write(JSON.encode({ | 69         request.response.write(JSON.encode({ | 
| 69           'success': {'message': 'Good job!'} | 70           'success': {'message': 'Good job!'} | 
| 70         })); | 71         })); | 
| 71         request.response.close(); | 72         request.response.close(); | 
| 72       }), completes); | 73       }), completes); | 
| 73     }); | 74     }); | 
| 74 | 75 | 
| 75     expect(pub.nextLine(), completion(equals('Good job!'))); | 76     expect(pub.nextLine(), completion(equals('Good job!'))); | 
| 76     pub.shouldExit(0); | 77     pub.shouldExit(exit_codes.SUCCESS); | 
| 77   }); | 78   }); | 
| 78 | 79 | 
| 79   integration('removes an uploader', () { | 80   integration('removes an uploader', () { | 
| 80     var server = new ScheduledServer(); | 81     var server = new ScheduledServer(); | 
| 81     d.credentialsFile(server, 'access token').create(); | 82     d.credentialsFile(server, 'access token').create(); | 
| 82     var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); | 83     var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); | 
| 83 | 84 | 
| 84     server.handle('DELETE', '/api/packages/pkg/uploaders/email', (request) { | 85     server.handle('DELETE', '/api/packages/pkg/uploaders/email', (request) { | 
| 85       request.response.headers.contentType = | 86       request.response.headers.contentType = | 
| 86           new ContentType("application", "json"); | 87           new ContentType("application", "json"); | 
| 87       request.response.write(JSON.encode({ | 88       request.response.write(JSON.encode({ | 
| 88         'success': {'message': 'Good job!'} | 89         'success': {'message': 'Good job!'} | 
| 89       })); | 90       })); | 
| 90       request.response.close(); | 91       request.response.close(); | 
| 91     }); | 92     }); | 
| 92 | 93 | 
| 93     expect(pub.nextLine(), completion(equals('Good job!'))); | 94     expect(pub.nextLine(), completion(equals('Good job!'))); | 
| 94     pub.shouldExit(0); | 95     pub.shouldExit(exit_codes.SUCCESS); | 
| 95   }); | 96   }); | 
| 96 | 97 | 
| 97   integration('defaults to the current package', () { | 98   integration('defaults to the current package', () { | 
| 98     d.validPackage.create(); | 99     d.validPackage.create(); | 
| 99 | 100 | 
| 100     var server = new ScheduledServer(); | 101     var server = new ScheduledServer(); | 
| 101     d.credentialsFile(server, 'access token').create(); | 102     d.credentialsFile(server, 'access token').create(); | 
| 102     var pub = startPubUploader(server, ['add', 'email']); | 103     var pub = startPubUploader(server, ['add', 'email']); | 
| 103 | 104 | 
| 104     server.handle('POST', '/api/packages/test_pkg/uploaders', (request) { | 105     server.handle('POST', '/api/packages/test_pkg/uploaders', (request) { | 
| 105       request.response.headers.contentType = | 106       request.response.headers.contentType = | 
| 106           new ContentType("application", "json"); | 107           new ContentType("application", "json"); | 
| 107       request.response.write(JSON.encode({ | 108       request.response.write(JSON.encode({ | 
| 108         'success': {'message': 'Good job!'} | 109         'success': {'message': 'Good job!'} | 
| 109       })); | 110       })); | 
| 110       request.response.close(); | 111       request.response.close(); | 
| 111     }); | 112     }); | 
| 112 | 113 | 
| 113     expect(pub.nextLine(), completion(equals('Good job!'))); | 114     expect(pub.nextLine(), completion(equals('Good job!'))); | 
| 114     pub.shouldExit(0); | 115     pub.shouldExit(exit_codes.SUCCESS); | 
| 115   }); | 116   }); | 
| 116 | 117 | 
| 117   integration('add provides an error', () { | 118   integration('add provides an error', () { | 
| 118     var server = new ScheduledServer(); | 119     var server = new ScheduledServer(); | 
| 119     d.credentialsFile(server, 'access token').create(); | 120     d.credentialsFile(server, 'access token').create(); | 
| 120     var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | 121     var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | 
| 121 | 122 | 
| 122     server.handle('POST', '/api/packages/pkg/uploaders', (request) { | 123     server.handle('POST', '/api/packages/pkg/uploaders', (request) { | 
| 123       request.response.statusCode = 400; | 124       request.response.statusCode = 400; | 
| 124       request.response.headers.contentType = | 125       request.response.headers.contentType = | 
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 176     server.handle('DELETE', '/api/packages/pkg/uploaders/email', (request) { | 177     server.handle('DELETE', '/api/packages/pkg/uploaders/email', (request) { | 
| 177       request.response.write("{not json"); | 178       request.response.write("{not json"); | 
| 178       request.response.close(); | 179       request.response.close(); | 
| 179     }); | 180     }); | 
| 180 | 181 | 
| 181     expect(pub.nextErrLine(), completion(equals('Invalid server response:'))); | 182     expect(pub.nextErrLine(), completion(equals('Invalid server response:'))); | 
| 182     expect(pub.nextErrLine(), completion(equals('{not json'))); | 183     expect(pub.nextErrLine(), completion(equals('{not json'))); | 
| 183     pub.shouldExit(1); | 184     pub.shouldExit(1); | 
| 184   }); | 185   }); | 
| 185 } | 186 } | 
| OLD | NEW | 
|---|