Skip to content
This repository was archived by the owner on Sep 22, 2020. It is now read-only.

Commit ce5550b

Browse files
author
clouless
committed
better debugging and failing jenkins job if cmdline foo happens
1 parent 8460bc1 commit ce5550b

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/test/java/ut/com/comsysto/poc/ao/service/PetAndOwnerDataAccessServiceTest.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,13 @@ public void getOwnersWhoHavePets() throws Exception {
3636
//
3737

3838
protected static void setUpDockerContainer(String dockerRunCommand) {
39-
CmdLineExecutionResult result = CmdLineTestHelper
40-
.executeCommand(dockerRunCommand);
41-
assertEquals(new Integer(0), result.exitCode);
42-
assertEquals(null, result.exception);
39+
CmdLineTestHelper.executeAndFailIfNotValidStatusCode(dockerRunCommand, 0);
4340
}
4441

4542
protected static void tearDownDockerContainer(String dockerGetIdCommand) {
4643
CmdLineExecutionResult result = CmdLineTestHelper
47-
.executeCommand(dockerGetIdCommand);
48-
assertEquals(new Integer(0), result.exitCode);
49-
assertEquals(null, result.exception);
44+
.executeAndFailIfNotValidStatusCode(dockerGetIdCommand, 0);
5045
String dockerId = result.stdout.trim();
51-
CmdLineTestHelper.executeCommand("docker kill " + dockerId);
46+
CmdLineTestHelper.executeAndFailIfNotValidStatusCode("docker kill " + dockerId, 0);
5247
}
5348
}

src/test/java/ut/com/comsysto/poc/ao/service/helper/CmdLineTestHelper.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public static CmdLineExecutionResult executeCommand(String command) {
1414
//
1515
// EXECUTE DOCKER COMMAND AND RETURN RESULT
1616
//
17+
System.out.println("====================");
18+
System.out.println(command);
19+
System.out.println("====================");
1720
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
1821
PumpStreamHandler psh = new PumpStreamHandler(stdout);
1922
CommandLine cmdLine = CommandLine.parse(command);
@@ -34,4 +37,12 @@ public static CmdLineExecutionResult executeCommand(String command) {
3437
}
3538
return res;
3639
}
40+
41+
public static CmdLineExecutionResult executeAndFailIfNotValidStatusCode(String command, Integer expectedExitCode) {
42+
CmdLineExecutionResult result = executeCommand(command.toString());
43+
if (! result.exitCode.equals(expectedExitCode)) {
44+
throw new RuntimeException("Exec of cmd failed with exit code: " + result.exitCode + " - " + command + " ---- EXCEPTION: " + result.exception);
45+
}
46+
return result;
47+
}
3748
}

0 commit comments

Comments
 (0)