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

Side by Side Diff: test/serve_packages.dart

Issue 1523323004: Install barback from a hosted source in all tests. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Merge for real. Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 serve_packages; 5 library serve_packages;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 9
10 import 'package:path/path.dart' as p; 10 import 'package:path/path.dart' as p;
11 import 'package:pub/src/io.dart'; 11 import 'package:pub/src/io.dart';
12 import 'package:pub/src/pubspec.dart';
13 import 'package:pub/src/source_registry.dart';
12 import 'package:pub/src/utils.dart'; 14 import 'package:pub/src/utils.dart';
13 import 'package:pub_semver/pub_semver.dart'; 15 import 'package:pub_semver/pub_semver.dart';
14 import 'package:scheduled_test/scheduled_test.dart'; 16 import 'package:scheduled_test/scheduled_test.dart';
15 import 'package:yaml/yaml.dart'; 17 import 'package:yaml/yaml.dart';
16 18
17 import 'descriptor.dart' as d; 19 import 'descriptor.dart' as d;
18 import 'test_pub.dart'; 20 import 'test_pub.dart';
19 21
20 /// The [d.DirectoryDescriptor] describing the server layout of `/api/packages` 22 /// The [d.DirectoryDescriptor] describing the server layout of `/api/packages`
21 /// on the test server. 23 /// on the test server.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 }); 98 });
97 }, 'initializing the package server'); 99 }, 'initializing the package server');
98 } 100 }
99 101
100 /// Like [servePackages], but instead creates an empty server with no packages 102 /// Like [servePackages], but instead creates an empty server with no packages
101 /// registered. 103 /// registered.
102 /// 104 ///
103 /// This will always replace a previous server. 105 /// This will always replace a previous server.
104 void serveNoPackages() => servePackages((_) {}, replace: true); 106 void serveNoPackages() => servePackages((_) {}, replace: true);
105 107
108 /// A shortcut for [servePackages] that serves the version of barback used by
109 /// pub.
110 void serveBarback() {
111 servePackages((builder) {
112 builder.serveRealPackage('barback');
113 });
114 }
115
106 /// A builder for specifying which packages should be served by [servePackages]. 116 /// A builder for specifying which packages should be served by [servePackages].
107 class PackageServerBuilder { 117 class PackageServerBuilder {
108 /// A map from package names to a list of concrete packages to serve. 118 /// A map from package names to a list of concrete packages to serve.
109 final _packages = new Map<String, List<_ServedPackage>>(); 119 final _packages = new Map<String, List<_ServedPackage>>();
110 120
111 /// A group of futures from [serve] calls. 121 /// A group of futures from [serve] calls.
112 /// 122 ///
113 /// This should be accessed by calling [_awair]. 123 /// This should be accessed by calling [_awair].
114 var _futures = new FutureGroup(); 124 var _futures = new FutureGroup();
115 125
(...skipping 24 matching lines...) Expand all
140 if (contents == null) contents = [d.libDir(name, "$name $version")]; 150 if (contents == null) contents = [d.libDir(name, "$name $version")];
141 contents = [d.file("pubspec.yaml", yaml(pubspecFields))] 151 contents = [d.file("pubspec.yaml", yaml(pubspecFields))]
142 ..addAll(contents); 152 ..addAll(contents);
143 153
144 var packages = _packages.putIfAbsent(name, () => []); 154 var packages = _packages.putIfAbsent(name, () => []);
145 packages.add(new _ServedPackage(pubspecFields, contents)); 155 packages.add(new _ServedPackage(pubspecFields, contents));
146 })); 156 }));
147 } 157 }
148 158
149 /// Serves the versions of [package] and all its dependencies that are 159 /// Serves the versions of [package] and all its dependencies that are
150 /// currently checked into the Dart repository. 160 /// currently depended on by pub.
151 void serveRepoPackage(String package) { 161 void serveRealPackage(String package) {
152 _addPackage(name) { 162 _addPackage(name) {
153 if (_packages.containsKey(name)) return; 163 if (_packages.containsKey(name)) return;
154 _packages[name] = []; 164 _packages[name] = [];
155 165
156 var root = packagePath(name); 166 var root = packagePath(name);
157 var pubspec = new Map.from(loadYaml( 167 var pubspec = new Map.from(loadYaml(
158 readTextFile(p.join(root, 'pubspec.yaml')))); 168 readTextFile(p.join(root, 'pubspec.yaml'))));
159 169
160 // Remove any SDK constraints since we don't have a valid SDK version 170 // Remove any SDK constraints since we don't have a valid SDK version
161 // while testing. 171 // while testing.
(...skipping 24 matching lines...) Expand all
186 196
187 /// A package that's intended to be served. 197 /// A package that's intended to be served.
188 class _ServedPackage { 198 class _ServedPackage {
189 final Map pubspec; 199 final Map pubspec;
190 final List<d.Descriptor> contents; 200 final List<d.Descriptor> contents;
191 201
192 Version get version => new Version.parse(pubspec['version']); 202 Version get version => new Version.parse(pubspec['version']);
193 203
194 _ServedPackage(this.pubspec, this.contents); 204 _ServedPackage(this.pubspec, this.contents);
195 } 205 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698