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

Side by Side Diff: mojo/public/dart/third_party/shelf_static/test/test_util.dart

Issue 1346773002: Stop running pub get at gclient sync time and fix build bugs (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2015, 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 shelf_static.test_util;
6
7 import 'dart:async';
8
9 import 'package:path/path.dart' as p;
10 import 'package:shelf/shelf.dart';
11 import 'package:shelf_static/src/util.dart';
12 import 'package:test/test.dart';
13
14 final p.Context _ctx = p.url;
15
16 /// Makes a simple GET request to [handler] and returns the result.
17 Future<Response> makeRequest(Handler handler, String path,
18 {String handlerPath, Map<String, String> headers}) {
19 var rootedHandler = _rootHandler(handlerPath, handler);
20 return new Future.sync(() => rootedHandler(_fromPath(path, headers)));
21 }
22
23 Request _fromPath(String path, Map<String, String> headers) =>
24 new Request('GET', Uri.parse('http://localhost' + path), headers: headers);
25
26 Handler _rootHandler(String path, Handler handler) {
27 if (path == null || path.isEmpty) {
28 return handler;
29 }
30
31 return (Request request) {
32 if (!_ctx.isWithin("/$path", request.requestedUri.path)) {
33 return new Response.notFound('not found');
34 }
35 assert(request.handlerPath == '/');
36
37 var relativeRequest = request.change(path: path);
38
39 return handler(relativeRequest);
40 };
41 }
42
43 Matcher atSameTimeToSecond(value) =>
44 new _SecondResolutionDateTimeMatcher(value);
45
46 class _SecondResolutionDateTimeMatcher extends Matcher {
47 final DateTime _target;
48
49 _SecondResolutionDateTimeMatcher(DateTime target)
50 : this._target = toSecondResolution(target);
51
52 bool matches(item, Map matchState) {
53 if (item is! DateTime) return false;
54
55 return datesEqualToSecond(_target, item);
56 }
57
58 Description describe(Description descirption) => descirption.add(
59 'Must be at the same moment as $_target with resolution '
60 'to the second.');
61 }
62
63 bool datesEqualToSecond(DateTime d1, DateTime d2) {
64 return toSecondResolution(d1).isAtSameMomentAs(toSecondResolution(d2));
65 }
OLDNEW
« no previous file with comments | « mojo/public/dart/third_party/shelf_static/test/test_all.dart ('k') | mojo/public/dart/third_party/shelf_static/tool/travis.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698