Chromium Code Reviews| Index: utils/tests/pub/validator_test.dart |
| diff --git a/utils/tests/pub/validator_test.dart b/utils/tests/pub/validator_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5a18d8ed013593cd8b02b0e063df61e9edb49d66 |
| --- /dev/null |
| +++ b/utils/tests/pub/validator_test.dart |
| @@ -0,0 +1,145 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library validator_test; |
| + |
| +import 'dart:io'; |
| +import 'dart:json'; |
| + |
| +import 'test_pub.dart'; |
| +import '../../../pkg/unittest/lib/unittest.dart'; |
| +import '../../pub/io.dart'; |
| + |
| +void expectValidationError() { |
| + var server = new ScheduledServer(); |
| + credentialsFile(server, 'access token').scheduleCreate(); |
| + var pub = startPubLish(server); |
| + server.ignore('GET', '/packages/versions/new.json'); |
| + |
| + pub.shouldExit(1); |
| + expectLater(pub.remainingStderr(), contains("Package validation failed.")); |
| +} |
| + |
| +void expectValidationWarning() { |
| + var server = new ScheduledServer(); |
| + credentialsFile(server, 'access token').scheduleCreate(); |
| + var pub = startPubLish(server); |
| + server.ignore('GET', '/packages/versions/new.json'); |
| + |
| + pub.writeLine("n"); |
| + |
| + pub.shouldExit(1); |
| + expectLater(pub.remainingStderr(), contains("Package upload aborted.")); |
| +} |
| + |
| +void expectNoValidationError() { |
| + var server = new ScheduledServer(); |
| + credentialsFile(server, 'access token').scheduleCreate(); |
| + var pub = startPubLish(server); |
| + |
| + server.handle('GET', '/packages/versions/new.json', (request, response) { |
| + return server.url.chain((url) { |
| + response.headers.contentType = new ContentType("application", "json"); |
| + response.outputStream.writeString(JSON.stringify({ |
| + 'url': url.resolve('/upload').toString(), |
| + 'fields': {} |
| + })); |
| + return closeHttpResponse(request, response); |
| + }); |
| + }); |
| + |
| + server.handle('POST', '/upload', (request, response) { |
| + return server.url.chain((url) { |
| + response.statusCode = 302; |
| + response.headers.set('location', url.resolve('/create').toString()); |
| + return closeHttpResponse(request, response); |
| + }); |
| + }); |
| + |
| + pub.kill(); |
| +} |
| + |
| +main() { |
|
Bob Nystrom
2012/12/05 18:57:40
How about splitting these into separate unit tests
nweiz
2012/12/05 21:59:59
Done.
|
| + group('should consider a package valid if it', () { |
| + test('looks normal', () { |
| + dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); |
| + expectNoValidationError(); |
| + run(); |
| + }); |
| + |
| + test('has "authors" instead of "author"', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package["authors"] = [package.remove("author")]; |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + expectNoValidationError(); |
| + run(); |
| + }); |
| + }); |
| + |
| + group('should consider a package invalid if it', () { |
| + test('is missing the "homepage" field', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package.remove("homepage"); |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + |
| + expectValidationError(); |
| + run(); |
| + }); |
| + |
| + test('is missing the "author" field', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package.remove("author"); |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + |
| + expectValidationError(); |
| + run(); |
| + }); |
| + |
| + test('has a single author without an email', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package["author"] = "Nathan Weizenbaum"; |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + |
| + expectValidationWarning(); |
| + run(); |
| + }); |
| + |
| + test('has one of several authors without an email', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package.remove("author"); |
| + package["authors"] = [ |
| + "Bob Nystrom <rnystrom@google.com>", |
| + "Nathan Weizenbaum", |
| + "John Messerly <jmesserly@google.com>" |
| + ]; |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + |
| + expectValidationWarning(); |
| + run(); |
| + }); |
| + |
| + test('has a single author without a name', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package["author"] = "<nweiz@google.com>"; |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + |
| + expectValidationWarning(); |
| + run(); |
| + }); |
| + |
| + test('has one of several authors without a name', () { |
| + var package = package("test_pkg", "1.0.0"); |
| + package.remove("author"); |
| + package["authors"] = [ |
| + "Bob Nystrom <rnystrom@google.com>", |
| + "<nweiz@google.com>", |
| + "John Messerly <jmesserly@google.com>" |
| + ]; |
| + dir(appPath, [pubspec(package)]).scheduleCreate(); |
| + |
| + expectValidationWarning(); |
| + run(); |
| + }); |
| + }); |
| +} |