Unverified Commit e524a303 authored by Emmanuel Garcia's avatar Emmanuel Garcia Committed by GitHub

Print stdout and stderr when the ssh command failed (#55762)

parent 069dc9c7
......@@ -802,7 +802,11 @@ class _FuchsiaPortForwarder extends DevicePortForwarder {
];
final ProcessResult result = await globals.processManager.run(command);
if (result.exitCode != 0) {
throwToolExit('Unforward command failed: $result');
throwToolExit(
'Unforward command failed:\n'
'stdout: ${result.stdout}\n'
'stderr: ${result.stderr}'
);
}
}
......
......@@ -563,6 +563,49 @@ void main() {
}, testOn: 'posix');
});
group('portForwarder', () {
MockProcessManager mockProcessManager;
MockFile sshConfig;
setUp(() {
mockProcessManager = MockProcessManager();
sshConfig = MockFile();
when(sshConfig.path).thenReturn('irrelevant');
when(sshConfig.existsSync()).thenReturn(true);
when(sshConfig.absolute).thenReturn(sshConfig);
});
testUsingContext('`unforward` prints stdout and stderr if ssh command failed', () async {
final FuchsiaDevice device = FuchsiaDevice('id', name: 'tester');
final MockProcessResult mockFailureProcessResult = MockProcessResult();
when(mockFailureProcessResult.exitCode).thenReturn(1);
when<String>(mockFailureProcessResult.stdout as String).thenReturn('<stdout>');
when<String>(mockFailureProcessResult.stderr as String).thenReturn('<stderr>');
when(mockProcessManager.run(<String>[
'ssh',
'-F',
'irrelevant',
'-O',
'cancel',
'-vvv',
'-L',
'0:127.0.0.1:1',
'id',
])).thenAnswer((Invocation invocation) {
return Future<ProcessResult>.value(mockFailureProcessResult);
});
await expectLater(
() => device.portForwarder.unforward(ForwardedPort(/*hostPort=*/ 0, /*devicePort=*/ 1)),
throwsToolExit(message: 'Unforward command failed:\nstdout: <stdout>\nstderr: <stderr>'),
);
}, overrides: <Type, Generator>{
ProcessManager: () => mockProcessManager,
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig),
});
});
group(FuchsiaIsolateDiscoveryProtocol, () {
MockPortForwarder portForwarder;
......
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