Unverified Commit c94648f9 authored by omerlevran46's avatar omerlevran46 Committed by GitHub

[fuchsia] remove no devices found from ffx parsing (#77651)

parent 59ea6192
......@@ -395,7 +395,6 @@ class FuchsiaDeviceDiscovery implements DeviceDiscovery {
final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
for (final String deviceId in await discoverDevices()) {
try {
StringBuffer stderr;
final int resolveResult = await exec(
_ffx,
<String>[
......@@ -404,11 +403,9 @@ class FuchsiaDeviceDiscovery implements DeviceDiscovery {
'--format',
'a',
deviceId,
],
stderr: stderr
]
);
final String stderrOutput = stderr.toString().trim();
if (resolveResult == 0 && ! stderrOutput.contains('No devices found')) {
if (resolveResult == 0) {
results['fuchsia-device-$deviceId'] = HealthCheckResult.success();
} else {
results['fuchsia-device-$deviceId'] = HealthCheckResult.failure('Cannot resolve device $deviceId');
......
......@@ -322,7 +322,6 @@ Future<int> exec(
List<String> arguments, {
Map<String, String> environment,
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
StringBuffer stderr, // if not null, the stderr will be written here
String workingDirectory,
}) async {
return _execute(
......@@ -330,7 +329,6 @@ Future<int> exec(
arguments,
environment: environment,
canFail : canFail,
stderr: stderr,
workingDirectory: workingDirectory,
);
}
......
......@@ -93,9 +93,6 @@ class FuchsiaFfx {
_logger.printError('ffx failed: ${result.stderr}');
return null;
}
if (result.stderr.contains('No devices found')) {
return null;
}
return result.stdout.trim();
}
}
......@@ -130,6 +130,85 @@ void main() {
<String>['device1']);
});
});
group('ffx resolve', () {
testWithoutContext('ffx not found', () {
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: FakeProcessManager.any(),
);
expect(() async => fuchsiaFfx.list(),
throwsToolExit(message: 'Fuchsia ffx tool not found.'));
});
testWithoutContext('unknown device', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, 'target', 'list', '--format', 'a', 'unknown-device'],
exitCode: 2,
stderr: 'No devices found.',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.resolve('unknown-device'), isNull);
expect(logger.errorText, 'ffx failed: No devices found.\n');
});
testWithoutContext('error', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, 'target', 'list', '--format', 'a', 'error-device'],
exitCode: 1,
stderr: 'unexpected error',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.resolve('error-device'), isNull);
expect(logger.errorText, contains('unexpected error'));
});
testWithoutContext('valid device', () async {
ffx.createSync();
final ProcessManager processManager =
FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: <String>[ffx.path, 'target', 'list', '--format', 'a', 'known-device'],
exitCode: 0,
stdout: '1234-1234-1234-1234',
),
]);
final FuchsiaFfx fuchsiaFfx = FuchsiaFfx(
fuchsiaArtifacts: fakeFuchsiaArtifacts,
logger: logger,
processManager: processManager,
);
expect(await fuchsiaFfx.resolve('known-device'), '1234-1234-1234-1234');
expect(logger.errorText, isEmpty);
});
});
}
class FakeFuchsiaArtifacts extends Fake implements FuchsiaArtifacts {
......
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