Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library validator_test; | |
| 6 | |
| 7 import 'dart:io'; | |
| 8 import 'dart:json'; | |
| 9 | |
| 10 import 'test_pub.dart'; | |
| 11 import '../../../pkg/unittest/lib/unittest.dart'; | |
| 12 import '../../pub/io.dart'; | |
| 13 | |
| 14 void expectValidationError() { | |
| 15 var server = new ScheduledServer(); | |
| 16 credentialsFile(server, 'access token').scheduleCreate(); | |
| 17 var pub = startPubLish(server); | |
| 18 server.ignore('GET', '/packages/versions/new.json'); | |
| 19 | |
| 20 pub.shouldExit(1); | |
| 21 expectLater(pub.remainingStderr(), contains("Package validation failed.")); | |
| 22 } | |
| 23 | |
| 24 void expectValidationWarning() { | |
| 25 var server = new ScheduledServer(); | |
| 26 credentialsFile(server, 'access token').scheduleCreate(); | |
| 27 var pub = startPubLish(server); | |
| 28 server.ignore('GET', '/packages/versions/new.json'); | |
| 29 | |
| 30 pub.writeLine("n"); | |
| 31 | |
| 32 pub.shouldExit(1); | |
| 33 expectLater(pub.remainingStderr(), contains("Package upload aborted.")); | |
| 34 } | |
| 35 | |
| 36 void expectNoValidationError() { | |
| 37 var server = new ScheduledServer(); | |
| 38 credentialsFile(server, 'access token').scheduleCreate(); | |
| 39 var pub = startPubLish(server); | |
| 40 | |
| 41 server.handle('GET', '/packages/versions/new.json', (request, response) { | |
| 42 return server.url.chain((url) { | |
| 43 response.headers.contentType = new ContentType("application", "json"); | |
| 44 response.outputStream.writeString(JSON.stringify({ | |
| 45 'url': url.resolve('/upload').toString(), | |
| 46 'fields': {} | |
| 47 })); | |
| 48 return closeHttpResponse(request, response); | |
| 49 }); | |
| 50 }); | |
| 51 | |
| 52 server.handle('POST', '/upload', (request, response) { | |
| 53 return server.url.chain((url) { | |
| 54 response.statusCode = 302; | |
| 55 response.headers.set('location', url.resolve('/create').toString()); | |
| 56 return closeHttpResponse(request, response); | |
| 57 }); | |
| 58 }); | |
| 59 | |
| 60 pub.kill(); | |
| 61 } | |
| 62 | |
| 63 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.
| |
| 64 group('should consider a package valid if it', () { | |
| 65 test('looks normal', () { | |
| 66 dir(appPath, [libPubspec("test_pkg", "1.0.0")]).scheduleCreate(); | |
| 67 expectNoValidationError(); | |
| 68 run(); | |
| 69 }); | |
| 70 | |
| 71 test('has "authors" instead of "author"', () { | |
| 72 var package = package("test_pkg", "1.0.0"); | |
| 73 package["authors"] = [package.remove("author")]; | |
| 74 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 75 expectNoValidationError(); | |
| 76 run(); | |
| 77 }); | |
| 78 }); | |
| 79 | |
| 80 group('should consider a package invalid if it', () { | |
| 81 test('is missing the "homepage" field', () { | |
| 82 var package = package("test_pkg", "1.0.0"); | |
| 83 package.remove("homepage"); | |
| 84 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 85 | |
| 86 expectValidationError(); | |
| 87 run(); | |
| 88 }); | |
| 89 | |
| 90 test('is missing the "author" field', () { | |
| 91 var package = package("test_pkg", "1.0.0"); | |
| 92 package.remove("author"); | |
| 93 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 94 | |
| 95 expectValidationError(); | |
| 96 run(); | |
| 97 }); | |
| 98 | |
| 99 test('has a single author without an email', () { | |
| 100 var package = package("test_pkg", "1.0.0"); | |
| 101 package["author"] = "Nathan Weizenbaum"; | |
| 102 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 103 | |
| 104 expectValidationWarning(); | |
| 105 run(); | |
| 106 }); | |
| 107 | |
| 108 test('has one of several authors without an email', () { | |
| 109 var package = package("test_pkg", "1.0.0"); | |
| 110 package.remove("author"); | |
| 111 package["authors"] = [ | |
| 112 "Bob Nystrom <rnystrom@google.com>", | |
| 113 "Nathan Weizenbaum", | |
| 114 "John Messerly <jmesserly@google.com>" | |
| 115 ]; | |
| 116 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 117 | |
| 118 expectValidationWarning(); | |
| 119 run(); | |
| 120 }); | |
| 121 | |
| 122 test('has a single author without a name', () { | |
| 123 var package = package("test_pkg", "1.0.0"); | |
| 124 package["author"] = "<nweiz@google.com>"; | |
| 125 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 126 | |
| 127 expectValidationWarning(); | |
| 128 run(); | |
| 129 }); | |
| 130 | |
| 131 test('has one of several authors without a name', () { | |
| 132 var package = package("test_pkg", "1.0.0"); | |
| 133 package.remove("author"); | |
| 134 package["authors"] = [ | |
| 135 "Bob Nystrom <rnystrom@google.com>", | |
| 136 "<nweiz@google.com>", | |
| 137 "John Messerly <jmesserly@google.com>" | |
| 138 ]; | |
| 139 dir(appPath, [pubspec(package)]).scheduleCreate(); | |
| 140 | |
| 141 expectValidationWarning(); | |
| 142 run(); | |
| 143 }); | |
| 144 }); | |
| 145 } | |
| OLD | NEW |