| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library pub_uploader_test; | |
| 6 | |
| 7 import 'dart:convert'; | |
| 8 | |
| 9 import 'package:scheduled_test/scheduled_process.dart'; | |
| 10 import 'package:scheduled_test/scheduled_server.dart'; | |
| 11 import 'package:scheduled_test/scheduled_test.dart'; | |
| 12 import 'package:shelf/shelf.dart' as shelf; | |
| 13 | |
| 14 import '../lib/src/exit_codes.dart' as exit_codes; | |
| 15 import '../lib/src/utils.dart'; | |
| 16 import 'descriptor.dart' as d; | |
| 17 import 'test_pub.dart'; | |
| 18 | |
| 19 final USAGE_STRING = ''' | |
| 20 Manage uploaders for a package on pub.dartlang.org. | |
| 21 | |
| 22 Usage: pub uploader [options] {add/remove} <email> | |
| 23 -h, --help Print this usage information. | |
| 24 --server The package server on which the package is hosted. | |
| 25 (defaults to "https://pub.dartlang.org") | |
| 26 | |
| 27 --package The package whose uploaders will be modified. | |
| 28 (defaults to the current package) | |
| 29 | |
| 30 Run "pub help" to see global options. | |
| 31 See http://dartlang.org/tools/pub/cmd/pub-uploader.html for detailed documentati
on. | |
| 32 '''; | |
| 33 | |
| 34 ScheduledProcess startPubUploader(ScheduledServer server, List<String> args) { | |
| 35 var tokenEndpoint = | |
| 36 server.url.then((url) => url.resolve('/token').toString()); | |
| 37 args = flatten(['uploader', '--server', tokenEndpoint, args]); | |
| 38 return startPub(args: args, tokenEndpoint: tokenEndpoint); | |
| 39 } | |
| 40 | |
| 41 main() { | |
| 42 initConfig(); | |
| 43 group('displays usage', () { | |
| 44 integration('when run with no arguments', () { | |
| 45 schedulePub( | |
| 46 args: ['uploader'], | |
| 47 output: USAGE_STRING, | |
| 48 exitCode: exit_codes.USAGE); | |
| 49 }); | |
| 50 | |
| 51 integration('when run with only a command', () { | |
| 52 schedulePub( | |
| 53 args: ['uploader', 'add'], | |
| 54 output: USAGE_STRING, | |
| 55 exitCode: exit_codes.USAGE); | |
| 56 }); | |
| 57 | |
| 58 integration('when run with an invalid command', () { | |
| 59 schedulePub( | |
| 60 args: ['uploader', 'foo', 'email'], | |
| 61 output: USAGE_STRING, | |
| 62 exitCode: exit_codes.USAGE); | |
| 63 }); | |
| 64 }); | |
| 65 | |
| 66 integration('adds an uploader', () { | |
| 67 var server = new ScheduledServer(); | |
| 68 d.credentialsFile(server, 'access token').create(); | |
| 69 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | |
| 70 | |
| 71 server.handle('POST', '/api/packages/pkg/uploaders', (request) { | |
| 72 return request.readAsString().then((body) { | |
| 73 expect(body, equals('email=email')); | |
| 74 | |
| 75 return new shelf.Response.ok(JSON.encode({ | |
| 76 'success': { | |
| 77 'message': 'Good job!' | |
| 78 } | |
| 79 }), headers: { | |
| 80 'content-type': 'application/json' | |
| 81 }); | |
| 82 }); | |
| 83 }); | |
| 84 | |
| 85 pub.stdout.expect('Good job!'); | |
| 86 pub.shouldExit(exit_codes.SUCCESS); | |
| 87 }); | |
| 88 | |
| 89 integration('removes an uploader', () { | |
| 90 var server = new ScheduledServer(); | |
| 91 d.credentialsFile(server, 'access token').create(); | |
| 92 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); | |
| 93 | |
| 94 server.handle('DELETE', '/api/packages/pkg/uploaders/email', (request) { | |
| 95 return new shelf.Response.ok(JSON.encode({ | |
| 96 'success': { | |
| 97 'message': 'Good job!' | |
| 98 } | |
| 99 }), headers: { | |
| 100 'content-type': 'application/json' | |
| 101 }); | |
| 102 }); | |
| 103 | |
| 104 pub.stdout.expect('Good job!'); | |
| 105 pub.shouldExit(exit_codes.SUCCESS); | |
| 106 }); | |
| 107 | |
| 108 integration('defaults to the current package', () { | |
| 109 d.validPackage.create(); | |
| 110 | |
| 111 var server = new ScheduledServer(); | |
| 112 d.credentialsFile(server, 'access token').create(); | |
| 113 var pub = startPubUploader(server, ['add', 'email']); | |
| 114 | |
| 115 server.handle('POST', '/api/packages/test_pkg/uploaders', (request) { | |
| 116 return new shelf.Response.ok(JSON.encode({ | |
| 117 'success': { | |
| 118 'message': 'Good job!' | |
| 119 } | |
| 120 }), headers: { | |
| 121 'content-type': 'application/json' | |
| 122 }); | |
| 123 }); | |
| 124 | |
| 125 pub.stdout.expect('Good job!'); | |
| 126 pub.shouldExit(exit_codes.SUCCESS); | |
| 127 }); | |
| 128 | |
| 129 integration('add provides an error', () { | |
| 130 var server = new ScheduledServer(); | |
| 131 d.credentialsFile(server, 'access token').create(); | |
| 132 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | |
| 133 | |
| 134 server.handle('POST', '/api/packages/pkg/uploaders', (request) { | |
| 135 return new shelf.Response(400, body: JSON.encode({ | |
| 136 'error': { | |
| 137 'message': 'Bad job!' | |
| 138 } | |
| 139 }), headers: { | |
| 140 'content-type': 'application/json' | |
| 141 }); | |
| 142 }); | |
| 143 | |
| 144 pub.stderr.expect('Bad job!'); | |
| 145 pub.shouldExit(1); | |
| 146 }); | |
| 147 | |
| 148 integration('remove provides an error', () { | |
| 149 var server = new ScheduledServer(); | |
| 150 d.credentialsFile(server, 'access token').create(); | |
| 151 var pub = | |
| 152 startPubUploader(server, ['--package', 'pkg', 'remove', 'e/mail']); | |
| 153 | |
| 154 server.handle('DELETE', '/api/packages/pkg/uploaders/e%2Fmail', (request) { | |
| 155 return new shelf.Response(400, body: JSON.encode({ | |
| 156 'error': { | |
| 157 'message': 'Bad job!' | |
| 158 } | |
| 159 }), headers: { | |
| 160 'content-type': 'application/json' | |
| 161 }); | |
| 162 }); | |
| 163 | |
| 164 pub.stderr.expect('Bad job!'); | |
| 165 pub.shouldExit(1); | |
| 166 }); | |
| 167 | |
| 168 integration('add provides invalid JSON', () { | |
| 169 var server = new ScheduledServer(); | |
| 170 d.credentialsFile(server, 'access token').create(); | |
| 171 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | |
| 172 | |
| 173 server.handle( | |
| 174 'POST', | |
| 175 '/api/packages/pkg/uploaders', | |
| 176 (request) => new shelf.Response.ok("{not json")); | |
| 177 | |
| 178 pub.stderr.expect(emitsLines('Invalid server response:\n' '{not json')); | |
| 179 pub.shouldExit(1); | |
| 180 }); | |
| 181 | |
| 182 integration('remove provides invalid JSON', () { | |
| 183 var server = new ScheduledServer(); | |
| 184 d.credentialsFile(server, 'access token').create(); | |
| 185 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); | |
| 186 | |
| 187 server.handle( | |
| 188 'DELETE', | |
| 189 '/api/packages/pkg/uploaders/email', | |
| 190 (request) => new shelf.Response.ok("{not json")); | |
| 191 | |
| 192 pub.stderr.expect(emitsLines('Invalid server response:\n' '{not json')); | |
| 193 pub.shouldExit(1); | |
| 194 }); | |
| 195 } | |
| OLD | NEW |