MockOperatingSystemUtils -> FakeOperatingSystemUtils (#77988)
This commit is contained in:
@@ -5,9 +5,7 @@
|
|||||||
// @dart = 2.8
|
// @dart = 2.8
|
||||||
|
|
||||||
import 'package:flutter_tools/src/base/logger.dart';
|
import 'package:flutter_tools/src/base/logger.dart';
|
||||||
import 'package:flutter_tools/src/base/os.dart';
|
|
||||||
import 'package:flutter_tools/src/ios/devices.dart';
|
import 'package:flutter_tools/src/ios/devices.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
|
||||||
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
import '../../src/context.dart';
|
||||||
@@ -22,36 +20,32 @@ void main() {
|
|||||||
// and 65535; this test verifies we are killing iproxy processes when
|
// and 65535; this test verifies we are killing iproxy processes when
|
||||||
// we timeout on a port
|
// we timeout on a port
|
||||||
testWithoutContext('IOSDevicePortForwarder.forward will kill iproxy processes before invoking a second', () async {
|
testWithoutContext('IOSDevicePortForwarder.forward will kill iproxy processes before invoking a second', () async {
|
||||||
const int devicePort = 456;
|
|
||||||
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||||
const FakeCommand(
|
const FakeCommand(
|
||||||
command: <String>['iproxy', '49154:456', '--udid', '1234'],
|
command: <String>['iproxy', '12345:456', '--udid', '1234'],
|
||||||
// iproxy does not exit with 0 when it cannot forward.
|
// iproxy does not exit with 0 when it cannot forward.
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
stdout: null, // no stdout indicates failure.
|
stdout: null, // no stdout indicates failure.
|
||||||
environment: kDyLdLibEntry,
|
environment: kDyLdLibEntry,
|
||||||
),
|
),
|
||||||
const FakeCommand(
|
const FakeCommand(
|
||||||
command: <String>['iproxy', '49155:456', '--udid', '1234'],
|
command: <String>['iproxy', '12346:456', '--udid', '1234'],
|
||||||
exitCode: 0,
|
exitCode: 0,
|
||||||
stdout: 'not empty',
|
stdout: 'not empty',
|
||||||
environment: kDyLdLibEntry,
|
environment: kDyLdLibEntry,
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
final MockOperatingSystemUtils operatingSystemUtils = MockOperatingSystemUtils();
|
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
|
||||||
when(operatingSystemUtils.findFreePort()).thenAnswer((Invocation invocation) => Future<int>.value(49154));
|
|
||||||
|
|
||||||
final IOSDevicePortForwarder portForwarder = IOSDevicePortForwarder.test(
|
final IOSDevicePortForwarder portForwarder = IOSDevicePortForwarder.test(
|
||||||
processManager: processManager,
|
processManager: processManager,
|
||||||
logger: BufferLogger.test(),
|
logger: BufferLogger.test(),
|
||||||
operatingSystemUtils: operatingSystemUtils,
|
operatingSystemUtils: operatingSystemUtils,
|
||||||
);
|
);
|
||||||
final int hostPort = await portForwarder.forward(devicePort);
|
final int hostPort = await portForwarder.forward(456);
|
||||||
|
|
||||||
// First port tried (49154) should fail, then succeed on the next
|
// First port tried (12345) should fail, then succeed on the next
|
||||||
expect(hostPort, 49154 + 1);
|
expect(hostPort, 12345 + 1);
|
||||||
expect(processManager, hasNoRemainingExpectations);
|
expect(processManager, hasNoRemainingExpectations);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import 'package:package_config/package_config.dart';
|
|||||||
import 'package:yaml/yaml.dart';
|
import 'package:yaml/yaml.dart';
|
||||||
|
|
||||||
import '../src/common.dart';
|
import '../src/common.dart';
|
||||||
import '../src/context.dart';
|
import '../src/context.dart' hide FakeOperatingSystemUtils;
|
||||||
import '../src/fakes.dart';
|
import '../src/fakes.dart';
|
||||||
import '../src/pubspec_schema.dart';
|
import '../src/pubspec_schema.dart';
|
||||||
import '../src/testbed.dart';
|
import '../src/testbed.dart';
|
||||||
@@ -2159,8 +2159,7 @@ void main() {
|
|||||||
|
|
||||||
testWithoutContext('Symlink failures give developer mode instructions on recent versions of Windows', () async {
|
testWithoutContext('Symlink failures give developer mode instructions on recent versions of Windows', () async {
|
||||||
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
||||||
final MockOperatingSystemUtils os = MockOperatingSystemUtils();
|
final FakeOperatingSystemUtils os = FakeOperatingSystemUtils('Microsoft Windows [Version 10.0.14972.1]');
|
||||||
when(os.name).thenReturn('Microsoft Windows [Version 10.0.14972.1]');
|
|
||||||
|
|
||||||
const FileSystemException e = FileSystemException('', '', OSError('', 1314));
|
const FileSystemException e = FileSystemException('', '', OSError('', 1314));
|
||||||
|
|
||||||
@@ -2170,8 +2169,7 @@ void main() {
|
|||||||
|
|
||||||
testWithoutContext('Symlink failures instruct developers to run as administrator on older versions of Windows', () async {
|
testWithoutContext('Symlink failures instruct developers to run as administrator on older versions of Windows', () async {
|
||||||
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
||||||
final MockOperatingSystemUtils os = MockOperatingSystemUtils();
|
final FakeOperatingSystemUtils os = FakeOperatingSystemUtils('Microsoft Windows [Version 10.0.14393]');
|
||||||
when(os.name).thenReturn('Microsoft Windows [Version 10.0.14393]');
|
|
||||||
|
|
||||||
const FileSystemException e = FileSystemException('', '', OSError('', 1314));
|
const FileSystemException e = FileSystemException('', '', OSError('', 1314));
|
||||||
|
|
||||||
@@ -2181,8 +2179,7 @@ void main() {
|
|||||||
|
|
||||||
testWithoutContext('Symlink failures only give instructions for specific errors', () async {
|
testWithoutContext('Symlink failures only give instructions for specific errors', () async {
|
||||||
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
final Platform platform = FakePlatform(operatingSystem: 'windows');
|
||||||
final MockOperatingSystemUtils os = MockOperatingSystemUtils();
|
final FakeOperatingSystemUtils os = FakeOperatingSystemUtils('Microsoft Windows [Version 10.0.14393]');
|
||||||
when(os.name).thenReturn('Microsoft Windows [Version 10.0.14393]');
|
|
||||||
|
|
||||||
const FileSystemException e = FileSystemException('', '', OSError('', 999));
|
const FileSystemException e = FileSystemException('', '', OSError('', 999));
|
||||||
|
|
||||||
@@ -2200,7 +2197,13 @@ class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterprete
|
|||||||
class MockWebProject extends Mock implements WebProject {}
|
class MockWebProject extends Mock implements WebProject {}
|
||||||
class MockWindowsProject extends Mock implements WindowsProject {}
|
class MockWindowsProject extends Mock implements WindowsProject {}
|
||||||
class MockLinuxProject extends Mock implements LinuxProject {}
|
class MockLinuxProject extends Mock implements LinuxProject {}
|
||||||
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
|
|
||||||
|
class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
||||||
|
FakeOperatingSystemUtils(this.name);
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String name;
|
||||||
|
}
|
||||||
|
|
||||||
class FakeSystemClock extends Fake implements SystemClock {
|
class FakeSystemClock extends Fake implements SystemClock {
|
||||||
DateTime currentTime;
|
DateTime currentTime;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ 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/web/chrome.dart';
|
import 'package:flutter_tools/src/web/chrome.dart';
|
||||||
import 'package:mockito/mockito.dart';
|
|
||||||
import '../../src/common.dart';
|
import '../../src/common.dart';
|
||||||
import '../../src/context.dart';
|
import '../../src/context.dart';
|
||||||
|
|
||||||
@@ -39,11 +39,7 @@ void main() {
|
|||||||
|
|
||||||
setUp(() {
|
setUp(() {
|
||||||
exceptionHandler = FileExceptionHandler();
|
exceptionHandler = FileExceptionHandler();
|
||||||
operatingSystemUtils = MockOperatingSystemUtils();
|
operatingSystemUtils = FakeOperatingSystemUtils();
|
||||||
when(operatingSystemUtils.findFreePort())
|
|
||||||
.thenAnswer((Invocation invocation) async {
|
|
||||||
return 1234;
|
|
||||||
});
|
|
||||||
platform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{
|
platform = FakePlatform(operatingSystem: 'macos', environment: <String, String>{
|
||||||
kChromeEnvironment: 'example_chrome',
|
kChromeEnvironment: 'example_chrome',
|
||||||
});
|
});
|
||||||
@@ -119,7 +115,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'example_url',
|
'example_url',
|
||||||
],
|
],
|
||||||
@@ -171,7 +167,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'example_url',
|
'example_url',
|
||||||
],
|
],
|
||||||
@@ -220,7 +216,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'--headless',
|
'--headless',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
@@ -260,7 +256,7 @@ void main() {
|
|||||||
command: const <String>[
|
command: const <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'example_url',
|
'example_url',
|
||||||
],
|
],
|
||||||
@@ -294,7 +290,7 @@ void main() {
|
|||||||
const List<String> args = <String>[
|
const List<String> args = <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'--headless',
|
'--headless',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
@@ -334,7 +330,7 @@ void main() {
|
|||||||
command: <String>[
|
command: <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
'--user-data-dir=/.tmp_rand0/flutter_tools_chrome_device.rand0',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'--headless',
|
'--headless',
|
||||||
'--disable-gpu',
|
'--disable-gpu',
|
||||||
@@ -356,14 +352,12 @@ void main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
|
|
||||||
|
|
||||||
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
|
Future<Chromium> _testLaunchChrome(String userDataDir, FakeProcessManager processManager, ChromiumLauncher chromeLauncher) {
|
||||||
processManager.addCommand(FakeCommand(
|
processManager.addCommand(FakeCommand(
|
||||||
command: <String>[
|
command: <String>[
|
||||||
'example_chrome',
|
'example_chrome',
|
||||||
'--user-data-dir=$userDataDir',
|
'--user-data-dir=$userDataDir',
|
||||||
'--remote-debugging-port=1234',
|
'--remote-debugging-port=12345',
|
||||||
...kChromeArgs,
|
...kChromeArgs,
|
||||||
'example_url',
|
'example_url',
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user