diff options
author | Håkon Hallingstad <hakon@oath.com> | 2018-02-09 00:35:45 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@oath.com> | 2018-02-09 00:35:45 +0100 |
commit | c6e2e3314ab64903f45570a9116a7a69280de1ec (patch) | |
tree | b66a42cf679891c0f9b33153c26c2d90f63d41c5 /node-admin/src/test/java/com/yahoo/vespa/hosted/node | |
parent | bd90807da307dc205f24386f1b96546dd1b039c5 (diff) |
Use Terminal for Yum and SystemCtl
Diffstat (limited to 'node-admin/src/test/java/com/yahoo/vespa/hosted/node')
2 files changed, 58 insertions, 68 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTest.java index 53aafe6b47c..085402410b3 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTest.java @@ -2,13 +2,10 @@ package com.yahoo.vespa.hosted.node.admin.task.util.systemd; import com.yahoo.vespa.hosted.node.admin.component.TaskContext; -import com.yahoo.vespa.hosted.node.admin.task.util.process.Command; -import com.yahoo.vespa.hosted.node.admin.task.util.process.CommandException; -import com.yahoo.vespa.hosted.node.admin.task.util.process.TestCommandSupplier; +import com.yahoo.vespa.hosted.node.admin.task.util.process.ChildProcessFailureException; +import com.yahoo.vespa.hosted.node.admin.task.util.process.TestTerminal; import org.junit.Test; -import java.util.function.Function; - import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -19,48 +16,45 @@ import static org.mockito.Mockito.mock; */ public class SystemCtlTest { private final TaskContext taskContext = mock(TaskContext.class); - private final TestCommandSupplier testCommandSupplier = new TestCommandSupplier(taskContext); - private final Function<TaskContext, Command> commandSupplier = context -> testCommandSupplier.get(); + private final TestTerminal terminal = new TestTerminal(); @Test public void enable() throws Exception { - testCommandSupplier - .expectCommand( - "systemctl show docker", + terminal.expectCommand( + "systemctl show docker 2>&1", 0, "a=b\n" + "UnitFileState=disabled\n" + "bar=zoo\n") - .expectCommand("systemctl enable docker", 0, ""); + .expectCommand("systemctl enable docker 2>&1", 0, ""); - SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(commandSupplier).enable("docker"); + SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(terminal).enable("docker"); assertTrue(enableDockerService.converge(taskContext)); } @Test public void enableIsNoop() throws Exception { - testCommandSupplier - .expectCommand( - "systemctl show docker", + terminal.expectCommand( + "systemctl show docker 2>&1", 0, "a=b\n" + "UnitFileState=enabled\n" + "bar=zoo\n") - .expectCommand("systemctl enable docker", 0, ""); + .expectCommand("systemctl enable docker 2>&1", 0, ""); - SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(commandSupplier).enable("docker"); + SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(terminal).enable("docker"); assertFalse(enableDockerService.converge(taskContext)); } @Test public void enableCommandFailre() throws Exception { - testCommandSupplier.expectCommand("systemctl show docker", 1, "error"); - SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(commandSupplier).enable("docker"); + terminal.expectCommand("systemctl show docker 2>&1", 1, "error"); + SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(terminal).enable("docker"); try { enableDockerService.converge(taskContext); fail(); - } catch (CommandException e) { + } catch (ChildProcessFailureException e) { // success } } @@ -68,43 +62,41 @@ public class SystemCtlTest { @Test public void start() throws Exception { - testCommandSupplier - .expectCommand( - "systemctl show docker", + terminal.expectCommand( + "systemctl show docker 2>&1", 0, "a=b\n" + "ActiveState=failed\n" + "bar=zoo\n") - .expectCommand("systemctl start docker", 0, ""); + .expectCommand("systemctl start docker 2>&1", 0, ""); - SystemCtl.SystemCtlStart startDockerService = new SystemCtl(commandSupplier).start("docker"); + SystemCtl.SystemCtlStart startDockerService = new SystemCtl(terminal).start("docker"); assertTrue(startDockerService.converge(taskContext)); } @Test public void startIsNoop() throws Exception { - testCommandSupplier - .expectCommand( - "systemctl show docker", + terminal.expectCommand( + "systemctl show docker 2>&1", 0, "a=b\n" + "ActiveState=active\n" + "bar=zoo\n") - .expectCommand("systemctl start docker", 0, ""); + .expectCommand("systemctl start docker 2>&1", 0, ""); - SystemCtl.SystemCtlStart startDockerService = new SystemCtl(commandSupplier).start("docker"); + SystemCtl.SystemCtlStart startDockerService = new SystemCtl(terminal).start("docker"); assertFalse(startDockerService.converge(taskContext)); } @Test public void startCommandFailre() throws Exception { - testCommandSupplier.expectCommand("systemctl show docker", 1, "error"); - SystemCtl.SystemCtlStart startDockerService = new SystemCtl(commandSupplier).start("docker"); + terminal.expectCommand("systemctl show docker 2>&1", 1, "error"); + SystemCtl.SystemCtlStart startDockerService = new SystemCtl(terminal).start("docker"); try { startDockerService.converge(taskContext); fail(); - } catch (CommandException e) { + } catch (ChildProcessFailureException e) { // success } } @@ -112,35 +104,33 @@ public class SystemCtlTest { @Test public void disable() throws Exception { - testCommandSupplier - .expectCommand( - "systemctl show docker", + terminal.expectCommand( + "systemctl show docker 2>&1", 0, "a=b\n" + "UnitFileState=enabled\n" + "bar=zoo\n") - .expectCommand("systemctl disable docker", 0, ""); + .expectCommand("systemctl disable docker 2>&1", 0, ""); - assertTrue(new SystemCtl(commandSupplier).disable("docker").converge(taskContext)); + assertTrue(new SystemCtl(terminal).disable("docker").converge(taskContext)); } @Test public void stop() throws Exception { - testCommandSupplier - .expectCommand( - "systemctl show docker", + terminal.expectCommand( + "systemctl show docker 2>&1", 0, "a=b\n" + "ActiveState=active\n" + "bar=zoo\n") - .expectCommand("systemctl stop docker", 0, ""); + .expectCommand("systemctl stop docker 2>&1", 0, ""); - assertTrue(new SystemCtl(commandSupplier).stop("docker").converge(taskContext)); + assertTrue(new SystemCtl(terminal).stop("docker").converge(taskContext)); } @Test public void restart() throws Exception { - testCommandSupplier.expectCommand("systemctl restart docker", 0, ""); - assertTrue(new SystemCtl(commandSupplier).restart("docker").converge(taskContext)); + terminal.expectCommand("systemctl restart docker 2>&1", 0, ""); + assertTrue(new SystemCtl(terminal).restart("docker").converge(taskContext)); } }
\ No newline at end of file diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java index c893c709950..f010ea07d99 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java @@ -2,8 +2,8 @@ package com.yahoo.vespa.hosted.node.admin.task.util.yum; import com.yahoo.vespa.hosted.node.admin.component.TaskContext; -import com.yahoo.vespa.hosted.node.admin.task.util.process.CommandException; -import com.yahoo.vespa.hosted.node.admin.task.util.process.TestCommandSupplier; +import com.yahoo.vespa.hosted.node.admin.task.util.process.ChildProcessFailureException; +import com.yahoo.vespa.hosted.node.admin.task.util.process.TestTerminal; import org.junit.Before; import org.junit.Test; @@ -14,21 +14,21 @@ import static org.mockito.Mockito.mock; public class YumTest { TaskContext taskContext = mock(TaskContext.class); - TestCommandSupplier commandSupplier = new TestCommandSupplier(taskContext); + TestTerminal terminal = new TestTerminal(); @Before public void tearDown() { - commandSupplier.verifyInvocations(); + terminal.verifyAllCommandsExecuted(); } @Test public void testAlreadyInstalled() { - commandSupplier.expectCommand( - "yum install --assumeyes --enablerepo=repo-name package-1 package-2", + terminal.expectCommand( + "yum install --assumeyes --enablerepo=repo-name package-1 package-2 2>&1", 0, "foobar\nNothing to do\n"); - Yum yum = new Yum(taskContext, commandSupplier); + Yum yum = new Yum(taskContext, terminal); assertFalse(yum .install("package-1", "package-2") .enableRepo("repo-name") @@ -37,36 +37,36 @@ public class YumTest { @Test public void testAlreadyUpgraded() { - commandSupplier.expectCommand( - "yum upgrade --assumeyes package-1 package-2", + terminal.expectCommand( + "yum upgrade --assumeyes package-1 package-2 2>&1", 0, "foobar\nNo packages marked for update\n"); - assertFalse(new Yum(taskContext, commandSupplier) + assertFalse(new Yum(taskContext, terminal) .upgrade("package-1", "package-2") .converge()); } @Test public void testAlreadyRemoved() { - commandSupplier.expectCommand( - "yum remove --assumeyes package-1 package-2", + terminal.expectCommand( + "yum remove --assumeyes package-1 package-2 2>&1", 0, "foobar\nNo Packages marked for removal\n"); - assertFalse(new Yum(taskContext, commandSupplier) + assertFalse(new Yum(taskContext, terminal) .remove("package-1", "package-2") .converge()); } @Test public void testInstall() { - commandSupplier.expectCommand( - "yum install --assumeyes package-1 package-2", + terminal.expectCommand( + "yum install --assumeyes package-1 package-2 2>&1", 0, "installing, installing"); - Yum yum = new Yum(taskContext, commandSupplier); + Yum yum = new Yum(taskContext, terminal); assertTrue(yum .install("package-1", "package-2") .converge()); @@ -74,26 +74,26 @@ public class YumTest { @Test public void testInstallWithEnablerepo() { - commandSupplier.expectCommand( - "yum install --assumeyes --enablerepo=repo-name package-1 package-2", + terminal.expectCommand( + "yum install --assumeyes --enablerepo=repo-name package-1 package-2 2>&1", 0, "installing, installing"); - Yum yum = new Yum(taskContext, commandSupplier); + Yum yum = new Yum(taskContext, terminal); assertTrue(yum .install("package-1", "package-2") .enableRepo("repo-name") .converge()); } - @Test(expected = CommandException.class) + @Test(expected = ChildProcessFailureException.class) public void testFailedInstall() { - commandSupplier.expectCommand( - "yum install --assumeyes --enablerepo=repo-name package-1 package-2", + terminal.expectCommand( + "yum install --assumeyes --enablerepo=repo-name package-1 package-2 2>&1", 1, "error"); - Yum yum = new Yum(taskContext, commandSupplier); + Yum yum = new Yum(taskContext, terminal); yum.install("package-1", "package-2") .enableRepo("repo-name") .converge(); |