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