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'; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 }); | 67 }); |
68 | 68 |
69 test('removes an uploader', () { | 69 test('removes an uploader', () { |
70 var server = new ScheduledServer(); | 70 var server = new ScheduledServer(); |
71 credentialsFile(server, 'access token').scheduleCreate(); | 71 credentialsFile(server, 'access token').scheduleCreate(); |
72 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); | 72 var pub = startPubUploader(server, ['--package', 'pkg', 'remove', 'email']); |
73 | 73 |
74 server.handle('DELETE', '/packages/pkg/uploaders/email.json', | 74 server.handle('DELETE', '/packages/pkg/uploaders/email.json', |
75 (request, response) { | 75 (request, response) { |
76 response.headers.contentType = new ContentType("application", "json"); | 76 response.headers.contentType = new ContentType("application", "json"); |
77 response.outputStream.writeString(JSON.stringify({ | 77 response.outputStream.writeString(json.stringify({ |
78 'success': {'message': 'Good job!'} | 78 'success': {'message': 'Good job!'} |
79 })); | 79 })); |
80 response.outputStream.close(); | 80 response.outputStream.close(); |
81 }); | 81 }); |
82 | 82 |
83 expectLater(pub.nextLine(), equals('Good job!')); | 83 expectLater(pub.nextLine(), equals('Good job!')); |
84 pub.shouldExit(0); | 84 pub.shouldExit(0); |
85 | 85 |
86 run(); | 86 run(); |
87 }); | 87 }); |
88 | 88 |
89 test('defaults to the current package', () { | 89 test('defaults to the current package', () { |
90 normalPackage.scheduleCreate(); | 90 normalPackage.scheduleCreate(); |
91 | 91 |
92 var server = new ScheduledServer(); | 92 var server = new ScheduledServer(); |
93 credentialsFile(server, 'access token').scheduleCreate(); | 93 credentialsFile(server, 'access token').scheduleCreate(); |
94 var pub = startPubUploader(server, ['add', 'email']); | 94 var pub = startPubUploader(server, ['add', 'email']); |
95 | 95 |
96 server.handle('POST', '/packages/test_pkg/uploaders.json', | 96 server.handle('POST', '/packages/test_pkg/uploaders.json', |
97 (request, response) { | 97 (request, response) { |
98 response.headers.contentType = new ContentType("application", "json"); | 98 response.headers.contentType = new ContentType("application", "json"); |
99 response.outputStream.writeString(JSON.stringify({ | 99 response.outputStream.writeString(json.stringify({ |
100 'success': {'message': 'Good job!'} | 100 'success': {'message': 'Good job!'} |
101 })); | 101 })); |
102 response.outputStream.close(); | 102 response.outputStream.close(); |
103 }); | 103 }); |
104 | 104 |
105 expectLater(pub.nextLine(), equals('Good job!')); | 105 expectLater(pub.nextLine(), equals('Good job!')); |
106 pub.shouldExit(0); | 106 pub.shouldExit(0); |
107 | 107 |
108 run(); | 108 run(); |
109 }); | 109 }); |
110 | 110 |
111 test('add provides an error', () { | 111 test('add provides an error', () { |
112 var server = new ScheduledServer(); | 112 var server = new ScheduledServer(); |
113 credentialsFile(server, 'access token').scheduleCreate(); | 113 credentialsFile(server, 'access token').scheduleCreate(); |
114 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); | 114 var pub = startPubUploader(server, ['--package', 'pkg', 'add', 'email']); |
115 | 115 |
116 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { | 116 server.handle('POST', '/packages/pkg/uploaders.json', (request, response) { |
117 response.statusCode = 400; | 117 response.statusCode = 400; |
118 response.headers.contentType = new ContentType("application", "json"); | 118 response.headers.contentType = new ContentType("application", "json"); |
119 response.outputStream.writeString(JSON.stringify({ | 119 response.outputStream.writeString(json.stringify({ |
120 'error': {'message': 'Bad job!'} | 120 'error': {'message': 'Bad job!'} |
121 })); | 121 })); |
122 response.outputStream.close(); | 122 response.outputStream.close(); |
123 }); | 123 }); |
124 | 124 |
125 expectLater(pub.nextErrLine(), equals('Bad job!')); | 125 expectLater(pub.nextErrLine(), equals('Bad job!')); |
126 pub.shouldExit(1); | 126 pub.shouldExit(1); |
127 | 127 |
128 run(); | 128 run(); |
129 }); | 129 }); |
130 | 130 |
131 test('remove provides an error', () { | 131 test('remove provides an error', () { |
132 var server = new ScheduledServer(); | 132 var server = new ScheduledServer(); |
133 credentialsFile(server, 'access token').scheduleCreate(); | 133 credentialsFile(server, 'access token').scheduleCreate(); |
134 var pub = startPubUploader(server, | 134 var pub = startPubUploader(server, |
135 ['--package', 'pkg', 'remove', 'e/mail']); | 135 ['--package', 'pkg', 'remove', 'e/mail']); |
136 | 136 |
137 server.handle('DELETE', '/packages/pkg/uploaders/e%2Fmail.json', | 137 server.handle('DELETE', '/packages/pkg/uploaders/e%2Fmail.json', |
138 (request, response) { | 138 (request, response) { |
139 response.statusCode = 400; | 139 response.statusCode = 400; |
140 response.headers.contentType = new ContentType("application", "json"); | 140 response.headers.contentType = new ContentType("application", "json"); |
141 response.outputStream.writeString(JSON.stringify({ | 141 response.outputStream.writeString(json.stringify({ |
142 'error': {'message': 'Bad job!'} | 142 'error': {'message': 'Bad job!'} |
143 })); | 143 })); |
144 response.outputStream.close(); | 144 response.outputStream.close(); |
145 }); | 145 }); |
146 | 146 |
147 expectLater(pub.nextErrLine(), equals('Bad job!')); | 147 expectLater(pub.nextErrLine(), equals('Bad job!')); |
148 pub.shouldExit(1); | 148 pub.shouldExit(1); |
149 | 149 |
150 run(); | 150 run(); |
151 }); | 151 }); |
(...skipping 26 matching lines...) Expand all 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 |