OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013, 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 import 'dart:async'; | |
6 import 'dart:json' as json; | |
7 | |
8 import 'package:http/http.dart' as http; | |
9 import 'package:http/testing.dart'; | |
10 import 'package:pathos/path.dart' as path; | |
11 import 'package:scheduled_test/scheduled_test.dart'; | |
12 | |
13 import '../../../pub/entrypoint.dart'; | |
14 import '../../../pub/validator.dart'; | |
15 import '../../../pub/validator/dependency.dart'; | |
16 import '../descriptor.dart' as d; | |
17 import '../test_pub.dart'; | |
18 import 'utils.dart'; | |
19 | |
20 Validator dependency(Entrypoint entrypoint) => | |
21 new DependencyValidator(entrypoint); | |
22 | |
23 expectDependencyValidationError(String error) { | |
24 expect(schedulePackageValidation(dependency), | |
25 completion(pairOf(someElement(contains(error)), isEmpty))); | |
26 } | |
27 | |
28 expectDependencyValidationWarning(String warning) { | |
29 expect(schedulePackageValidation(dependency), | |
30 completion(pairOf(isEmpty, someElement(contains(warning))))); | |
31 } | |
32 | |
33 /// Sets up a test package with dependency [dep] and mocks a server with | |
34 /// [hostedVersions] of the package available. | |
35 setUpDependency(Map dep, {List<String> hostedVersions}) { | |
36 useMockClient(new MockClient((request) { | |
37 expect(request.method, equals("GET")); | |
38 expect(request.url.path, equals("/packages/foo.json")); | |
39 | |
40 if (hostedVersions == null) { | |
41 return new Future.value(new http.Response("not found", 404)); | |
42 } else { | |
43 return new Future.value(new http.Response(json.stringify({ | |
44 "name": "foo", | |
45 "uploaders": ["nweiz@google.com"], | |
46 "versions": hostedVersions | |
47 }), 200)); | |
48 } | |
49 })); | |
50 | |
51 d.dir(appPath, [ | |
52 d.libPubspec("test_pkg", "1.0.0", deps: [dep]) | |
53 ]).create(); | |
54 } | |
55 | |
56 main() { | |
57 initConfig(); | |
58 | |
59 integration('should consider a package valid if it looks normal', () { | |
60 d.validPackage.create(); | |
61 expectNoValidationError(dependency); | |
62 }); | |
63 | |
64 group('should consider a package invalid if it', () { | |
65 setUp(d.validPackage.create); | |
66 | |
67 group('has a git dependency', () { | |
68 group('where a hosted version exists', () { | |
69 integration("and should suggest the hosted primary version", () { | |
70 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, | |
71 hostedVersions: ["3.0.0-pre", "2.0.0", "1.0.0"]); | |
72 expectDependencyValidationWarning(' foo: ">=2.0.0 <3.0.0"'); | |
73 }); | |
74 | |
75 integration("and should suggest the hosted prerelease version if " | |
76 "it's the only version available", () { | |
77 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, | |
78 hostedVersions: ["3.0.0-pre", "2.0.0-pre"]); | |
79 expectDependencyValidationWarning(' foo: ">=3.0.0-pre <4.0.0"'); | |
80 }); | |
81 | |
82 integration("and should suggest a tighter constraint if primary is " | |
83 "pre-1.0.0", () { | |
84 setUpDependency({'git': 'git://github.com/dart-lang/foo'}, | |
85 hostedVersions: ["0.0.1", "0.0.2"]); | |
86 expectDependencyValidationWarning(' foo: ">=0.0.2 <0.0.3"'); | |
87 }); | |
88 }); | |
89 | |
90 group('where no hosted version exists', () { | |
91 integration("and should use the other source's version", () { | |
92 setUpDependency({ | |
93 'git': 'git://github.com/dart-lang/foo', | |
94 'version': '>=1.0.0 <2.0.0' | |
95 }); | |
96 expectDependencyValidationWarning(' foo: ">=1.0.0 <2.0.0"'); | |
97 }); | |
98 | |
99 integration("and should use the other source's unquoted version if " | |
100 "concrete", () { | |
101 setUpDependency({ | |
102 'git': 'git://github.com/dart-lang/foo', | |
103 'version': '0.2.3' | |
104 }); | |
105 expectDependencyValidationWarning(' foo: 0.2.3'); | |
106 }); | |
107 }); | |
108 }); | |
109 | |
110 group('has a path dependency', () { | |
111 group('where a hosted version exists', () { | |
112 integration("and should suggest the hosted primary version", () { | |
113 setUpDependency({'path': path.join(sandboxDir, 'foo')}, | |
114 hostedVersions: ["3.0.0-pre", "2.0.0", "1.0.0"]); | |
115 expectDependencyValidationError(' foo: ">=2.0.0 <3.0.0"'); | |
116 }); | |
117 | |
118 integration("and should suggest the hosted prerelease version if " | |
119 "it's the only version available", () { | |
120 setUpDependency({'path': path.join(sandboxDir, 'foo')}, | |
121 hostedVersions: ["3.0.0-pre", "2.0.0-pre"]); | |
122 expectDependencyValidationError(' foo: ">=3.0.0-pre <4.0.0"'); | |
123 }); | |
124 | |
125 integration("and should suggest a tighter constraint if primary is " | |
126 "pre-1.0.0", () { | |
127 setUpDependency({'path': path.join(sandboxDir, 'foo')}, | |
128 hostedVersions: ["0.0.1", "0.0.2"]); | |
129 expectDependencyValidationError(' foo: ">=0.0.2 <0.0.3"'); | |
130 }); | |
131 }); | |
132 | |
133 group('where no hosted version exists', () { | |
134 integration("and should use the other source's version", () { | |
135 setUpDependency({ | |
136 'path': path.join(sandboxDir, 'foo'), | |
137 'version': '>=1.0.0 <2.0.0' | |
138 }); | |
139 expectDependencyValidationError(' foo: ">=1.0.0 <2.0.0"'); | |
140 }); | |
141 | |
142 integration("and should use the other source's unquoted version if " | |
143 "concrete", () { | |
144 setUpDependency({ | |
145 'path': path.join(sandboxDir, 'foo'), | |
146 'version': '0.2.3' | |
147 }); | |
148 expectDependencyValidationError(' foo: 0.2.3'); | |
149 }); | |
150 }); | |
151 }); | |
152 | |
153 group('has an unconstrained dependency', () { | |
154 group('and it should not suggest a version', () { | |
155 integration("if there's no lockfile", () { | |
156 d.dir(appPath, [ | |
157 d.libPubspec("test_pkg", "1.0.0", deps: [ | |
158 {'hosted': 'foo'} | |
159 ]) | |
160 ]).create(); | |
161 | |
162 expect(schedulePackageValidation(dependency), completion( | |
163 pairOf(isEmpty, everyElement(isNot(contains("\n foo:")))))); | |
164 }); | |
165 | |
166 integration("if the lockfile doesn't have an entry for the " | |
167 "dependency", () { | |
168 d.dir(appPath, [ | |
169 d.libPubspec("test_pkg", "1.0.0", deps: [ | |
170 {'hosted': 'foo'} | |
171 ]), | |
172 d.file("pubspec.lock", json.stringify({ | |
173 'packages': { | |
174 'bar': { | |
175 'version': '1.2.3', | |
176 'source': 'hosted', | |
177 'description': { | |
178 'name': 'bar', | |
179 'url': 'http://pub.dartlang.org' | |
180 } | |
181 } | |
182 } | |
183 })) | |
184 ]).create(); | |
185 | |
186 expect(schedulePackageValidation(dependency), completion( | |
187 pairOf(isEmpty, everyElement(isNot(contains("\n foo:")))))); | |
188 }); | |
189 }); | |
190 | |
191 group('with a lockfile', () { | |
192 integration('and it should suggest a constraint based on the locked ' | |
193 'version', () { | |
194 d.dir(appPath, [ | |
195 d.libPubspec("test_pkg", "1.0.0", deps: [ | |
196 {'hosted': 'foo'} | |
197 ]), | |
198 d.file("pubspec.lock", json.stringify({ | |
199 'packages': { | |
200 'foo': { | |
201 'version': '1.2.3', | |
202 'source': 'hosted', | |
203 'description': { | |
204 'name': 'foo', | |
205 'url': 'http://pub.dartlang.org' | |
206 } | |
207 } | |
208 } | |
209 })) | |
210 ]).create(); | |
211 | |
212 expectDependencyValidationWarning(' foo: ">=1.2.3 <2.0.0"'); | |
213 }); | |
214 | |
215 integration('and it should suggest a concrete constraint if the locked ' | |
216 'version is pre-1.0.0', () { | |
217 d.dir(appPath, [ | |
218 d.libPubspec("test_pkg", "1.0.0", deps: [ | |
219 {'hosted': 'foo'} | |
220 ]), | |
221 d.file("pubspec.lock", json.stringify({ | |
222 'packages': { | |
223 'foo': { | |
224 'version': '0.1.2', | |
225 'source': 'hosted', | |
226 'description': { | |
227 'name': 'foo', | |
228 'url': 'http://pub.dartlang.org' | |
229 } | |
230 } | |
231 } | |
232 })) | |
233 ]).create(); | |
234 | |
235 expectDependencyValidationWarning(' foo: ">=0.1.2 <0.1.3"'); | |
236 }); | |
237 }); | |
238 }); | |
239 | |
240 integration('has a hosted dependency on itself', () { | |
241 d.dir(appPath, [ | |
242 d.libPubspec("test_pkg", "1.0.0", deps: [ | |
243 {'hosted': {'name': 'test_pkg', 'version': '>=1.0.0'}} | |
244 ]) | |
245 ]).create(); | |
246 | |
247 expectValidationWarning(dependency); | |
248 }); | |
249 }); | |
250 } | |
OLD | NEW |