Unverified Commit 90531179 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

MockProcessManager -> FakeProcessManager in os_test (#76264)

parent d65c98b4
...@@ -12,8 +12,6 @@ import 'package:flutter_tools/src/base/logger.dart'; ...@@ -12,8 +12,6 @@ import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart'; import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:mockito/mockito.dart';
import 'package:process/process.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -23,11 +21,9 @@ const String kPath1 = '/bar/bin/$kExecutable'; ...@@ -23,11 +21,9 @@ const String kPath1 = '/bar/bin/$kExecutable';
const String kPath2 = '/another/bin/$kExecutable'; const String kPath2 = '/another/bin/$kExecutable';
void main() { void main() {
MockProcessManager mockProcessManager;
FakeProcessManager fakeProcessManager; FakeProcessManager fakeProcessManager;
setUp(() { setUp(() {
mockProcessManager = MockProcessManager();
fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]); fakeProcessManager = FakeProcessManager.list(<FakeCommand>[]);
}); });
...@@ -90,13 +86,21 @@ void main() { ...@@ -90,13 +86,21 @@ void main() {
group('which on Windows', () { group('which on Windows', () {
testWithoutContext('throws tool exit if where throws an argument error', () async { testWithoutContext('throws tool exit if where throws an argument error', () async {
when(mockProcessManager.runSync(<String>['where', kExecutable])) fakeProcessManager.addCommand(
.thenThrow(ArgumentError('Cannot find executable for where')); FakeCommand(
command: const <String>[
'where',
kExecutable,
],
exception: ArgumentError('Cannot find executable for where'),
),
);
final OperatingSystemUtils utils = OperatingSystemUtils( final OperatingSystemUtils utils = OperatingSystemUtils(
fileSystem: MemoryFileSystem.test(), fileSystem: MemoryFileSystem.test(),
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'windows'), platform: FakePlatform(operatingSystem: 'windows'),
processManager: mockProcessManager, processManager: fakeProcessManager,
); );
expect(() => utils.which(kExecutable), throwsA(isA<ToolExit>())); expect(() => utils.which(kExecutable), throwsA(isA<ToolExit>()));
...@@ -416,17 +420,23 @@ void main() { ...@@ -416,17 +420,23 @@ void main() {
); );
}); });
testWithoutContext('If unzip throws an ArgumentError, display an install message', () { group('display an install message when unzip throws an ArgumentError', () {
testWithoutContext('Linux', () {
final FileSystem fileSystem = MemoryFileSystem.test(); final FileSystem fileSystem = MemoryFileSystem.test();
when(mockProcessManager.runSync( fakeProcessManager.addCommand(
<String>['unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path], FakeCommand(
)).thenThrow(ArgumentError()); command: <String>[
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
],
exception: ArgumentError(),
),
);
final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils( final OperatingSystemUtils linuxOsUtils = OperatingSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'linux'), platform: FakePlatform(operatingSystem: 'linux'),
processManager: mockProcessManager, processManager: fakeProcessManager,
); );
expect( expect(
...@@ -435,12 +445,24 @@ void main() { ...@@ -435,12 +445,24 @@ void main() {
message: 'Missing "unzip" tool. Unable to extract foo.zip.\n' message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
'Consider running "sudo apt-get install unzip".'), 'Consider running "sudo apt-get install unzip".'),
); );
});
testWithoutContext('macOS', () {
final FileSystem fileSystem = MemoryFileSystem.test();
fakeProcessManager.addCommand(
FakeCommand(
command: <String>[
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
],
exception: ArgumentError(),
),
);
final OperatingSystemUtils macOSUtils = OperatingSystemUtils( final OperatingSystemUtils macOSUtils = OperatingSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'macos'), platform: FakePlatform(operatingSystem: 'macos'),
processManager: mockProcessManager, processManager: fakeProcessManager,
); );
expect( expect(
...@@ -449,12 +471,24 @@ void main() { ...@@ -449,12 +471,24 @@ void main() {
(message: 'Missing "unzip" tool. Unable to extract foo.zip.\n' (message: 'Missing "unzip" tool. Unable to extract foo.zip.\n'
'Consider running "brew install unzip".'), 'Consider running "brew install unzip".'),
); );
});
testWithoutContext('unknown OS', () {
final FileSystem fileSystem = MemoryFileSystem.test();
fakeProcessManager.addCommand(
FakeCommand(
command: <String>[
'unzip', '-o', '-q', 'foo.zip', '-d', fileSystem.currentDirectory.path,
],
exception: ArgumentError(),
),
);
final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils( final OperatingSystemUtils unknownOsUtils = OperatingSystemUtils(
fileSystem: fileSystem, fileSystem: fileSystem,
logger: BufferLogger.test(), logger: BufferLogger.test(),
platform: FakePlatform(operatingSystem: 'fuchsia'), platform: FakePlatform(operatingSystem: 'fuchsia'),
processManager: mockProcessManager, processManager: fakeProcessManager,
); );
expect( expect(
...@@ -464,10 +498,9 @@ void main() { ...@@ -464,10 +498,9 @@ void main() {
'Please install unzip.'), 'Please install unzip.'),
); );
}); });
});
testWithoutContext('stream compression level', () { testWithoutContext('stream compression level', () {
expect(OperatingSystemUtils.gzipLevel1.level, equals(1)); expect(OperatingSystemUtils.gzipLevel1.level, equals(1));
}); });
} }
class MockProcessManager extends Mock implements ProcessManager {}
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