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 { ...@@ -395,7 +395,6 @@ class FuchsiaDeviceDiscovery implements DeviceDiscovery {
final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{}; final Map<String, HealthCheckResult> results = <String, HealthCheckResult>{};
for (final String deviceId in await discoverDevices()) { for (final String deviceId in await discoverDevices()) {
try { try {
StringBuffer stderr;
final int resolveResult = await exec( final int resolveResult = await exec(
_ffx, _ffx,
<String>[ <String>[
...@@ -404,11 +403,9 @@ class FuchsiaDeviceDiscovery implements DeviceDiscovery { ...@@ -404,11 +403,9 @@ class FuchsiaDeviceDiscovery implements DeviceDiscovery {
'--format', '--format',
'a', 'a',
deviceId, deviceId,
], ]
stderr: stderr
); );
final String stderrOutput = stderr.toString().trim(); if (resolveResult == 0) {
if (resolveResult == 0 && ! stderrOutput.contains('No devices found')) {
results['fuchsia-device-$deviceId'] = HealthCheckResult.success(); results['fuchsia-device-$deviceId'] = HealthCheckResult.success();
} else { } else {
results['fuchsia-device-$deviceId'] = HealthCheckResult.failure('Cannot resolve device $deviceId'); results['fuchsia-device-$deviceId'] = HealthCheckResult.failure('Cannot resolve device $deviceId');
......
...@@ -322,7 +322,6 @@ Future<int> exec( ...@@ -322,7 +322,6 @@ Future<int> exec(
List<String> arguments, { List<String> arguments, {
Map<String, String> environment, Map<String, String> environment,
bool canFail = false, // as in, whether failures are ok. False means that they are fatal. 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, String workingDirectory,
}) async { }) async {
return _execute( return _execute(
...@@ -330,7 +329,6 @@ Future<int> exec( ...@@ -330,7 +329,6 @@ Future<int> exec(
arguments, arguments,
environment: environment, environment: environment,
canFail : canFail, canFail : canFail,
stderr: stderr,
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
); );
} }
......
...@@ -93,9 +93,6 @@ class FuchsiaFfx { ...@@ -93,9 +93,6 @@ class FuchsiaFfx {
_logger.printError('ffx failed: ${result.stderr}'); _logger.printError('ffx failed: ${result.stderr}');
return null; return null;
} }
if (result.stderr.contains('No devices found')) {
return null;
}
return result.stdout.trim(); return result.stdout.trim();
} }
} }
...@@ -130,6 +130,85 @@ void main() { ...@@ -130,6 +130,85 @@ void main() {
<String>['device1']); <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 { 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