private ExecResult execScript(SshMachineLocation machine, String cmd) { OutputStream outStream = new ByteArrayOutputStream(); OutputStream errStream = new ByteArrayOutputStream(); int exitCode = machine.execScript(ImmutableMap.of("out", outStream, "err", errStream), "mysummary", ImmutableList.of(cmd)); String outString = outStream.toString(); String errString = errStream.toString(); return new ExecResult(exitCode, outString, errString); }
@Test public void testCustomOneOffResponse() throws Exception { RecordingSshTool.setCustomOneOffResponse(".*mycmd.*", new CustomResponse(1, "mystdout", "mystderr")); ExecResult result1 = execScript(machine, "mycmd"); ExecResult result2 = execScript(machine, "mycmd"); assertEquals(result1, new ExecResult(1, "mystdout", "mystderr")); assertEquals(result2, new ExecResult(0, "", "")); }