SystemCtl { public SystemCtlStart start(String unit) { return new SystemCtlStart(unit); } SystemCtl(Terminal terminal); SystemCtl withSudo(); boolean useSudo(); void daemonReload(TaskContext taskContext); SystemCtlEnable enable(String unit); SystemCtlDisable disable(String unit); SystemCtlStart start(String unit); SystemCtlStop stop(String unit); SystemCtlRestart restart(String unit); boolean serviceExists(TaskContext context, String unit); boolean isActive(TaskContext context, String unit);  }
@Test public void start() { terminal.expectCommand( "systemctl show docker 2>&1", 0, "a=b\n" + "ActiveState=failed\n" + "bar=zoo\n") .expectCommand("systemctl start docker 2>&1", 0, ""); SystemCtl.SystemCtlStart startDockerService = new SystemCtl(terminal).start("docker"); assertTrue(startDockerService.converge(taskContext)); }
@Test public void startIsNoop() { terminal.expectCommand( "systemctl show docker 2>&1", 0, "a=b\n" + "ActiveState=active\n" + "bar=zoo\n") .expectCommand("systemctl start docker 2>&1", 0, ""); SystemCtl.SystemCtlStart startDockerService = new SystemCtl(terminal).start("docker"); assertFalse(startDockerService.converge(taskContext)); }
@Test public void startCommandFailre() { terminal.expectCommand("systemctl show docker 2>&1", 1, "error"); SystemCtl.SystemCtlStart startDockerService = new SystemCtl(terminal).start("docker"); try { startDockerService.converge(taskContext); fail(); } catch (ChildProcessFailureException e) { } }