Unverified Commit 2a62b20b authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove mocks from fuchsia device start test (#83506)

* [flutter_tools] remove mocks from fuchsia device start test

* change import
parent 6a20df4f
...@@ -27,7 +27,7 @@ import 'package:flutter_tools/src/fuchsia/tiles_ctl.dart'; ...@@ -27,7 +27,7 @@ import 'package:flutter_tools/src/fuchsia/tiles_ctl.dart';
import 'package:flutter_tools/src/globals_null_migrated.dart' as globals; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/project.dart'; import 'package:flutter_tools/src/project.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:mockito/mockito.dart'; import 'package:test/fake.dart';
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -38,7 +38,7 @@ void main() { ...@@ -38,7 +38,7 @@ void main() {
MemoryFileSystem memoryFileSystem; MemoryFileSystem memoryFileSystem;
FakeOperatingSystemUtils osUtils; FakeOperatingSystemUtils osUtils;
FakeFuchsiaDeviceTools fuchsiaDeviceTools; FakeFuchsiaDeviceTools fuchsiaDeviceTools;
MockFuchsiaSdk fuchsiaSdk; FakeFuchsiaSdk fuchsiaSdk;
Artifacts artifacts; Artifacts artifacts;
FakeProcessManager fakeSuccessfulProcessManager; FakeProcessManager fakeSuccessfulProcessManager;
FakeProcessManager fakeFailedProcessManager; FakeProcessManager fakeFailedProcessManager;
...@@ -48,7 +48,7 @@ void main() { ...@@ -48,7 +48,7 @@ void main() {
memoryFileSystem = MemoryFileSystem.test(); memoryFileSystem = MemoryFileSystem.test();
osUtils = FakeOperatingSystemUtils(); osUtils = FakeOperatingSystemUtils();
fuchsiaDeviceTools = FakeFuchsiaDeviceTools(); fuchsiaDeviceTools = FakeFuchsiaDeviceTools();
fuchsiaSdk = MockFuchsiaSdk(); fuchsiaSdk = FakeFuchsiaSdk();
sshConfig = MemoryFileSystem.test().file('ssh_config')..writeAsStringSync('\n'); sshConfig = MemoryFileSystem.test().file('ssh_config')..writeAsStringSync('\n');
artifacts = Artifacts.test(); artifacts = Artifacts.test();
for (final BuildMode mode in <BuildMode>[BuildMode.debug, BuildMode.release]) { for (final BuildMode mode in <BuildMode>[BuildMode.debug, BuildMode.release]) {
...@@ -258,7 +258,7 @@ void main() { ...@@ -258,7 +258,7 @@ void main() {
ProcessManager: () => fakeSuccessfulProcessManager, ProcessManager: () => fakeSuccessfulProcessManager,
FuchsiaDeviceTools: () => fuchsiaDeviceTools, FuchsiaDeviceTools: () => fuchsiaDeviceTools,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
FuchsiaSdk: () => MockFuchsiaSdk(pm: FailingPM()), FuchsiaSdk: () => FakeFuchsiaSdk(pm: FailingPM()),
OperatingSystemUtils: () => osUtils, OperatingSystemUtils: () => osUtils,
}); });
...@@ -295,13 +295,7 @@ void main() { ...@@ -295,13 +295,7 @@ void main() {
}); });
} }
class MockProcessManager extends Mock implements ProcessManager {} Process _createFakeProcess({
class MockProcessResult extends Mock implements ProcessResult {}
class MockProcess extends Mock implements Process {}
Process _createMockProcess({
int exitCode = 0, int exitCode = 0,
String stdout = '', String stdout = '',
String stderr = '', String stderr = '',
...@@ -313,25 +307,15 @@ Process _createMockProcess({ ...@@ -313,25 +307,15 @@ Process _createMockProcess({
final Stream<List<int>> stderrStream = Stream<List<int>>.fromIterable(<List<int>>[ final Stream<List<int>> stderrStream = Stream<List<int>>.fromIterable(<List<int>>[
utf8.encode(stderr), utf8.encode(stderr),
]); ]);
final Process process = MockProcess(); final Completer<int> exitCodeCompleter = Completer<int>();
final Process process = FakeProcess(
when(process.stdout).thenAnswer((_) => stdoutStream); stdout: stdoutStream,
when(process.stderr).thenAnswer((_) => stderrStream); stderr: stderrStream,
exitCode: persistent ? exitCodeCompleter.future : Future<int>.value(exitCode),
if (persistent) { );
final Completer<int> exitCodeCompleter = Completer<int>();
when(process.kill()).thenAnswer((_) {
exitCodeCompleter.complete(-11);
return true;
});
when(process.exitCode).thenAnswer((_) => exitCodeCompleter.future);
} else {
when(process.exitCode).thenAnswer((_) => Future<int>.value(exitCode));
}
return process; return process;
} }
class FuchsiaDeviceWithFakeDiscovery extends FuchsiaDevice { class FuchsiaDeviceWithFakeDiscovery extends FuchsiaDevice {
FuchsiaDeviceWithFakeDiscovery(String id, {String name}) : super(id, name: name); FuchsiaDeviceWithFakeDiscovery(String id, {String name}) : super(id, name: name);
...@@ -555,7 +539,7 @@ class FakeFuchsiaPM implements FuchsiaPM { ...@@ -555,7 +539,7 @@ class FakeFuchsiaPM implements FuchsiaPM {
@override @override
Future<Process> serve(String repoPath, String host, int port) async { Future<Process> serve(String repoPath, String host, int port) async {
return _createMockProcess(persistent: true); return _createFakeProcess(persistent: true);
} }
@override @override
...@@ -594,7 +578,7 @@ class FailingPM implements FuchsiaPM { ...@@ -594,7 +578,7 @@ class FailingPM implements FuchsiaPM {
@override @override
Future<Process> serve(String repoPath, String host, int port) async { Future<Process> serve(String repoPath, String host, int port) async {
return _createMockProcess(exitCode: 6); return _createFakeProcess(exitCode: 6);
} }
@override @override
...@@ -652,8 +636,8 @@ class FakeFuchsiaFfx implements FuchsiaFfx { ...@@ -652,8 +636,8 @@ class FakeFuchsiaFfx implements FuchsiaFfx {
} }
} }
class MockFuchsiaSdk extends Mock implements FuchsiaSdk { class FakeFuchsiaSdk extends Fake implements FuchsiaSdk {
MockFuchsiaSdk({ FakeFuchsiaSdk({
FuchsiaPM pm, FuchsiaPM pm,
FuchsiaKernelCompiler compiler, FuchsiaKernelCompiler compiler,
FuchsiaDevFinder devFinder, FuchsiaDevFinder devFinder,
......
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