Fixing the pub get test so that it doesn't care what the flutter root looks like. (#13385)

This commit is contained in:
Greg Spencer 2017-12-06 13:27:29 -08:00 committed by GitHub
parent 99987c2272
commit 389e13f8b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import 'dart:async';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/io.dart'; import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
@ -16,9 +17,14 @@ import 'package:process/process.dart';
import 'package:quiver/testing/async.dart'; import 'package:quiver/testing/async.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
void main() { void main() {
setUpAll(() {
Cache.flutterRoot = getFlutterRoot();
});
testUsingContext('pub get 69', () async { testUsingContext('pub get 69', () async {
String error; String error;
@ -91,6 +97,7 @@ void main() {
String error; String error;
final MockProcessManager processMock = context.getVariable(ProcessManager); final MockProcessManager processMock = context.getVariable(ProcessManager);
final MockFileSystem fsMock = context.getVariable(FileSystem);
new FakeAsync().run((FakeAsync time) { new FakeAsync().run((FakeAsync time) {
MockDirectory.findCache = true; MockDirectory.findCache = true;
@ -102,7 +109,7 @@ void main() {
error = 'test failed unexpectedly: $thrownError'; error = 'test failed unexpectedly: $thrownError';
}); });
time.elapse(const Duration(milliseconds: 500)); time.elapse(const Duration(milliseconds: 500));
expect(processMock.lastPubCache, endsWith('flutter/.pub-cache')); expect(processMock.lastPubCache, equals(fsMock.path.join(Cache.flutterRoot, '.pub-cache')));
expect(error, isNull); expect(error, isNull);
}); });
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
@ -119,7 +126,7 @@ void main() {
final MockProcessManager processMock = context.getVariable(ProcessManager); final MockProcessManager processMock = context.getVariable(ProcessManager);
new FakeAsync().run((FakeAsync time) { new FakeAsync().run((FakeAsync time) {
MockDirectory.findCache = false; MockDirectory.findCache = true;
expect(processMock.lastPubEnvironmment, isNull); expect(processMock.lastPubEnvironmment, isNull);
expect(processMock.lastPubCache, isNull); expect(processMock.lastPubCache, isNull);
pubGet(context: PubContext.flutterTests, checkLastModified: false).then((Null value) { pubGet(context: PubContext.flutterTests, checkLastModified: false).then((Null value) {
@ -128,14 +135,14 @@ void main() {
error = 'test failed unexpectedly: $thrownError'; error = 'test failed unexpectedly: $thrownError';
}); });
time.elapse(const Duration(milliseconds: 500)); time.elapse(const Duration(milliseconds: 500));
expect(processMock.lastPubCache, equals('path/to/pub-cache')); expect(processMock.lastPubCache, equals('custom/pub-cache/path'));
expect(error, isNull); expect(error, isNull);
}); });
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
ProcessManager: () => new MockProcessManager(69), ProcessManager: () => new MockProcessManager(69),
FileSystem: () => new MockFileSystem(), FileSystem: () => new MockFileSystem(),
Platform: () => new FakePlatform( Platform: () => new FakePlatform(
environment: <String, String>{'PUB_CACHE': 'path/to/pub-cache'}, environment: <String, String>{'PUB_CACHE': 'custom/pub-cache/path'},
), ),
}); });
} }