Unverified Commit ca677011 authored by jcollins-g's avatar jcollins-g Committed by GitHub

Fix flutter tools packages_test when run off bots (#14692)

* Fix packages tests when run off bots

* Tweak dependencies to make bots happy

* Review comment
parent 24efb55b
......@@ -73,6 +73,7 @@ Future<int> run(
context.putIfAbsent(Config, () => new Config());
// Order-independent context entries
context.putIfAbsent(BotDetector, () => const BotDetector());
context.putIfAbsent(DeviceManager, () => new DeviceManager());
context.putIfAbsent(DevFSConfig, () => new DevFSConfig());
context.putIfAbsent(Doctor, () => new Doctor());
......
......@@ -15,7 +15,12 @@ import 'context.dart';
import 'file_system.dart';
import 'platform.dart';
bool get isRunningOnBot {
final BotDetector _kBotDetector = const BotDetector();
class BotDetector {
const BotDetector();
bool get isRunningOnBot {
return
platform.environment['BOT'] == 'true' ||
......@@ -36,6 +41,14 @@ bool get isRunningOnBot {
// Properties on Flutter's Chrome Infra bots.
platform.environment['CHROME_HEADLESS'] == '1' ||
platform.environment.containsKey('BUILDBOT_BUILDERNAME');
}
}
bool get isRunningOnBot {
if (context == null) {
return _kBotDetector.isRunningOnBot;
}
return context[BotDetector].isRunningOnBot;
}
String hex(List<int> bytes) {
......
......@@ -13,6 +13,7 @@ import 'base/io.dart';
import 'base/logger.dart';
import 'base/os.dart';
import 'base/platform.dart';
import 'base/utils.dart';
import 'cache.dart';
import 'disabled_usage.dart';
import 'usage.dart';
......@@ -25,6 +26,7 @@ Future<Null> runInContext(List<String> args, Runner runner) {
return executableContext.runInZone(() {
// Initialize the context with some defaults.
// This list must be kept in sync with lib/executable.dart.
context.putIfAbsent(BotDetector, () => const BotDetector());
context.putIfAbsent(Stdio, () => const Stdio());
context.putIfAbsent(Platform, () => const LocalPlatform());
context.putIfAbsent(FileSystem, () => const LocalFileSystem());
......
......@@ -7,6 +7,7 @@ import 'dart:async';
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart' hide IOSink;
import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/packages.dart';
import 'package:process/process.dart';
......@@ -16,6 +17,22 @@ import '../src/common.dart';
import '../src/context.dart';
import '../src/mocks.dart' show MockProcessManager, MockStdio, PromptingProcess;
class AlwaysTrueBotDetector implements BotDetector {
const AlwaysTrueBotDetector();
@override
bool get isRunningOnBot => true;
}
class AlwaysFalseBotDetector implements BotDetector {
const AlwaysFalseBotDetector();
@override
bool get isRunningOnBot => false;
}
void main() {
Cache.disableLocking();
group('packages get/upgrade', () {
......@@ -221,7 +238,20 @@ void main() {
mockStdio = new MockStdio();
});
testUsingContext('test', () async {
testUsingContext('test without bot', () async {
await createTestCommandRunner(new PackagesCommand()).run(<String>['packages', 'test']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(3));
expect(commands[0], matches(r'dart-sdk[\\/]bin[\\/]pub'));
expect(commands[1], 'run');
expect(commands[2], 'test');
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysFalseBotDetector(),
});
testUsingContext('test with bot', () async {
await createTestCommandRunner(new PackagesCommand()).run(<String>['packages', 'test']);
final List<String> commands = mockProcessManager.commands;
expect(commands, hasLength(4));
......@@ -232,6 +262,7 @@ void main() {
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
Stdio: () => mockStdio,
BotDetector: () => const AlwaysTrueBotDetector(),
});
testUsingContext('run', () async {
......
......@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/port_scanner.dart';
import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
......@@ -91,6 +92,7 @@ void testUsingContext(String description, dynamic testMethod(), {
// The context always starts with these value since others depend on them.
testContext
..putIfAbsent(BotDetector, () => const BotDetector())
..putIfAbsent(Stdio, () => const Stdio())
..putIfAbsent(Platform, () => const LocalPlatform())
..putIfAbsent(FileSystem, () => const LocalFileSystem())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment