Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(481)

Unified Diff: utils/tests/pub/pub_lish_test.dart

Issue 12437022: Use scheduled_test for Pub tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: re-upload Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/tests/pub/pub_cache_test.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/tests/pub/pub_lish_test.dart
diff --git a/utils/tests/pub/pub_lish_test.dart b/utils/tests/pub/pub_lish_test.dart
index 495055463286a5c75b7b809b888516c0bbfe17ec..8b38f2e8ae5b2c26914b18c748c2a8709ea3aba3 100644
--- a/utils/tests/pub/pub_lish_test.dart
+++ b/utils/tests/pub/pub_lish_test.dart
@@ -7,13 +7,16 @@ library pub_lish_test;
import 'dart:io';
import 'dart:json' as json;
-import 'test_pub.dart';
-import '../../../pkg/unittest/lib/unittest.dart';
+import '../../../pkg/scheduled_test/lib/scheduled_test.dart';
+import '../../../pkg/scheduled_test/lib/scheduled_server.dart';
+
import '../../pub/exit_codes.dart' as exit_codes;
import '../../pub/io.dart';
+import 'descriptor.dart' as d;
+import 'test_pub.dart';
void handleUploadForm(ScheduledServer server, [Map body]) {
- server.handle('GET', '/packages/versions/new.json', (request, response) {
+ server.handle('GET', '/packages/versions/new.json', (request) {
return server.url.then((url) {
expect(request.headers.value('authorization'),
equals('Bearer access token'));
@@ -28,53 +31,55 @@ void handleUploadForm(ScheduledServer server, [Map body]) {
};
}
- response.headers.contentType = new ContentType("application", "json");
- response.write(json.stringify(body));
- response.close();
+ request.response.headers.contentType =
+ new ContentType("application", "json");
+ request.response.write(json.stringify(body));
+ request.response.close();
});
});
}
void handleUpload(ScheduledServer server) {
- server.handle('POST', '/upload', (request, response) {
+ server.handle('POST', '/upload', (request) {
// TODO(nweiz): Once a multipart/form-data parser in Dart exists, validate
// that the request body is correctly formatted. See issue 6952.
return drainStream(request).then((_) {
return server.url;
}).then((url) {
- response.statusCode = 302;
- response.headers.set('location', url.resolve('/create').toString());
- response.close();
+ request.response.statusCode = 302;
+ request.response.headers.set(
+ 'location', url.resolve('/create').toString());
+ request.response.close();
});
});
}
main() {
initConfig();
- setUp(() => normalPackage.scheduleCreate());
+ setUp(() => d.validPackage.create());
integration('archives and uploads a package', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
handleUpload(server);
- server.handle('GET', '/create', (request, response) {
- response.write(json.stringify({
+ server.handle('GET', '/create', (request) {
+ request.response.write(json.stringify({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
- response.close();
+ request.response.close();
});
// TODO(rnystrom): The confirm line is run together with this one because
// in normal usage, the user will have entered a newline on stdin which
// gets echoed to the terminal. Do something better here?
- expectLater(pub.nextLine(), equals(
+ expect(pub.nextLine(), completion(equals(
'Looks great! Are you ready to upload your package (y/n)?'
- ' Package test_pkg 1.0.0 uploaded!'));
+ ' Package test_pkg 1.0.0 uploaded!')));
pub.shouldExit(0);
});
@@ -82,125 +87,126 @@ main() {
// test that "pub lish" chooses the correct files to publish.
integration('package validation has an error', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg.remove("homepage");
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- var pub = startPubLish(server);
+ var pub = startPublish(server);
pub.shouldExit(0);
- expectLater(pub.remainingStderr(),
- contains("Sorry, your package is missing a requirement and can't be "
- "published yet."));
+ expect(pub.remainingStderr(), completion(contains(
+ "Sorry, your package is missing a requirement and can't be published "
+ "yet.")));
});
integration('preview package validation has a warning', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg["author"] = "Nathan Weizenbaum";
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- var pub = startPubLish(server, args: ['--dry-run']);
+ var pub = startPublish(server, args: ['--dry-run']);
pub.shouldExit(0);
- expectLater(pub.remainingStderr(),
- contains('Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml'
- ' should have an email address\n'
- ' (e.g. "name <email>").\n\n'
- 'Package has 1 warning.'));
+ expect(pub.remainingStderr(), completion(contains(
+ 'Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml should '
+ 'have an email address\n'
+ ' (e.g. "name <email>").\n\n'
+ 'Package has 1 warning.')));
});
integration('preview package validation has no warnings', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg["author"] = "Nathan Weizenbaum <nweiz@google.com>";
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- var pub = startPubLish(server, args: ['--dry-run']);
+ var pub = startPublish(server, args: ['--dry-run']);
pub.shouldExit(0);
- expectLater(pub.remainingStderr(),
- contains('Package has 0 warnings.'));
+ expect(pub.remainingStderr(),
+ completion(contains('Package has 0 warnings.')));
});
integration('package validation has a warning and is canceled', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg["author"] = "Nathan Weizenbaum";
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- var pub = startPubLish(server);
+ var pub = startPublish(server);
pub.writeLine("n");
pub.shouldExit(0);
- expectLater(pub.remainingStderr(), contains("Package upload canceled."));
+ expect(pub.remainingStderr(),
+ completion(contains("Package upload canceled.")));
});
integration('package validation has a warning and continues', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg["author"] = "Nathan Weizenbaum";
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
pub.writeLine("y");
handleUploadForm(server);
handleUpload(server);
- server.handle('GET', '/create', (request, response) {
- response.write(json.stringify({
+ server.handle('GET', '/create', (request) {
+ request.response.write(json.stringify({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
- response.close();
+ request.response.close();
});
pub.shouldExit(0);
- expectLater(pub.remainingStdout(),
- contains('Package test_pkg 1.0.0 uploaded!'));
+ expect(pub.remainingStdout(),
+ completion(contains('Package test_pkg 1.0.0 uploaded!')));
});
integration('upload form provides an error', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
- server.handle('GET', '/packages/versions/new.json', (request, response) {
- response.statusCode = 400;
- response.write(json.stringify({
+ server.handle('GET', '/packages/versions/new.json', (request) {
+ request.response.statusCode = 400;
+ request.response.write(json.stringify({
'error': {'message': 'your request sucked'}
}));
- response.close();
+ request.response.close();
});
- expectLater(pub.nextErrLine(), equals('your request sucked'));
+ expect(pub.nextErrLine(), completion(equals('your request sucked')));
pub.shouldExit(1);
});
integration('upload form provides invalid JSON', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
- server.handle('GET', '/packages/versions/new.json', (request, response) {
- response.write('{not json');
- response.close();
+ server.handle('GET', '/packages/versions/new.json', (request) {
+ request.response.write('{not json');
+ request.response.close();
});
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals('{not json'));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals('{not json')));
pub.shouldExit(1);
});
integration('upload form is missing url', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
@@ -212,15 +218,15 @@ main() {
};
handleUploadForm(server, body);
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
integration('upload form url is not a string', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
@@ -233,43 +239,43 @@ main() {
};
handleUploadForm(server, body);
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
integration('upload form is missing fields', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
var body = {'url': 'http://example.com/upload'};
handleUploadForm(server, body);
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
integration('upload form fields is not a map', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
var body = {'url': 'http://example.com/upload', 'fields': 12};
handleUploadForm(server, body);
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
integration('upload form fields has a non-string value', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
@@ -278,137 +284,141 @@ main() {
'fields': {'field': 12}
};
handleUploadForm(server, body);
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
integration('cloud storage upload provides an error', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
- server.handle('POST', '/upload', (request, response) {
+ server.handle('POST', '/upload', (request) {
return drainStream(request).then((_) {
- response.statusCode = 400;
- response.headers.contentType = new ContentType('application', 'xml');
- response.write('<Error><Message>Your request sucked.'
+ request.response.statusCode = 400;
+ request.response.headers.contentType =
+ new ContentType('application', 'xml');
+ request.response.write('<Error><Message>Your request sucked.'
'</Message></Error>');
- response.close();
+ request.response.close();
});
});
// TODO(nweiz): This should use the server's error message once the client
// can parse the XML.
- expectLater(pub.nextErrLine(), equals('Failed to upload the package.'));
+ expect(pub.nextErrLine(),
+ completion(equals('Failed to upload the package.')));
pub.shouldExit(1);
});
integration("cloud storage upload doesn't redirect", () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
- server.handle('POST', '/upload', (request, response) {
+ server.handle('POST', '/upload', (request) {
return drainStream(request).then((_) {
// Don't set the location header.
- response.close();
+ request.response.close();
});
});
- expectLater(pub.nextErrLine(), equals('Failed to upload the package.'));
+ expect(pub.nextErrLine(),
+ completion(equals('Failed to upload the package.')));
pub.shouldExit(1);
});
integration('package creation provides an error', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
handleUpload(server);
- server.handle('GET', '/create', (request, response) {
- response.statusCode = 400;
- response.write(json.stringify({
+ server.handle('GET', '/create', (request) {
+ request.response.statusCode = 400;
+ request.response.write(json.stringify({
'error': {'message': 'Your package was too boring.'}
}));
- response.close();
+ request.response.close();
});
- expectLater(pub.nextErrLine(), equals('Your package was too boring.'));
+ expect(pub.nextErrLine(),
+ completion(equals('Your package was too boring.')));
pub.shouldExit(1);
});
integration('package creation provides invalid JSON', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
handleUpload(server);
- server.handle('GET', '/create', (request, response) {
- response.write('{not json');
- response.close();
+ server.handle('GET', '/create', (request) {
+ request.response.write('{not json');
+ request.response.close();
});
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals('{not json'));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals('{not json')));
pub.shouldExit(1);
});
integration('package creation provides a malformed error', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
handleUpload(server);
var body = {'error': 'Your package was too boring.'};
- server.handle('GET', '/create', (request, response) {
- response.statusCode = 400;
- response.write(json.stringify(body));
- response.close();
+ server.handle('GET', '/create', (request) {
+ request.response.statusCode = 400;
+ request.response.write(json.stringify(body));
+ request.response.close();
});
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
integration('package creation provides a malformed success', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server);
confirmPublish(pub);
handleUploadForm(server);
handleUpload(server);
var body = {'success': 'Your package was awesome.'};
- server.handle('GET', '/create', (request, response) {
- response.write(json.stringify(body));
- response.close();
+ server.handle('GET', '/create', (request) {
+ request.response.write(json.stringify(body));
+ request.response.close();
});
- expectLater(pub.nextErrLine(), equals('Invalid server response:'));
- expectLater(pub.nextErrLine(), equals(json.stringify(body)));
+ expect(pub.nextErrLine(), completion(equals('Invalid server response:')));
+ expect(pub.nextErrLine(), completion(equals(json.stringify(body))));
pub.shouldExit(1);
});
group('--force', () {
- setUp(() => normalPackage.scheduleCreate());
+ setUp(() => d.validPackage.create());
integration('cannot be combined with --dry-run', () {
schedulePub(args: ['lish', '--force', '--dry-run'],
@@ -418,64 +428,64 @@ main() {
integration('publishes if there are no warnings or errors', () {
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server, args: ['--force']);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server, args: ['--force']);
handleUploadForm(server);
handleUpload(server);
- server.handle('GET', '/create', (request, response) {
- response.write(json.stringify({
+ server.handle('GET', '/create', (request) {
+ request.response.write(json.stringify({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
- response.close();
+ request.response.close();
});
pub.shouldExit(0);
- expectLater(pub.remainingStdout(), contains(
- 'Package test_pkg 1.0.0 uploaded!'));
+ expect(pub.remainingStdout(), completion(contains(
+ 'Package test_pkg 1.0.0 uploaded!')));
});
integration('publishes if there are warnings', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg["author"] = "Nathan Weizenbaum";
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- credentialsFile(server, 'access token').scheduleCreate();
- var pub = startPubLish(server, args: ['--force']);
+ d.credentialsFile(server, 'access token').create();
+ var pub = startPublish(server, args: ['--force']);
handleUploadForm(server);
handleUpload(server);
- server.handle('GET', '/create', (request, response) {
- response.write(json.stringify({
+ server.handle('GET', '/create', (request) {
+ request.response.write(json.stringify({
'success': {'message': 'Package test_pkg 1.0.0 uploaded!'}
}));
- response.close();
+ request.response.close();
});
pub.shouldExit(0);
- expectLater(pub.remainingStderr(), contains(
+ expect(pub.remainingStderr(), completion(contains(
'Suggestions:\n* Author "Nathan Weizenbaum" in pubspec.yaml'
' should have an email address\n'
- ' (e.g. "name <email>").'));
- expectLater(pub.remainingStdout(), contains(
- 'Package test_pkg 1.0.0 uploaded!'));
+ ' (e.g. "name <email>").')));
+ expect(pub.remainingStdout(), completion(contains(
+ 'Package test_pkg 1.0.0 uploaded!')));
});
integration('does not publish if there are errors', () {
- var pkg = package("test_pkg", "1.0.0");
+ var pkg = packageMap("test_pkg", "1.0.0");
pkg.remove("homepage");
- dir(appPath, [pubspec(pkg)]).scheduleCreate();
+ d.dir(appPath, [d.pubspec(pkg)]).create();
var server = new ScheduledServer();
- var pub = startPubLish(server, args: ['--force']);
+ var pub = startPublish(server, args: ['--force']);
pub.shouldExit(0);
- expectLater(pub.remainingStderr(), contains(
+ expect(pub.remainingStderr(), completion(contains(
"Sorry, your package is missing a requirement and can't be "
- "published yet."));
+ "published yet.")));
});
});
}
« no previous file with comments | « utils/tests/pub/pub_cache_test.dart ('k') | utils/tests/pub/pub_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698