summaryrefslogtreecommitdiffstats
path: root/node-admin/src/test/java
diff options
context:
space:
mode:
authorValerij Fredriksen <valerij92@gmail.com>2020-04-04 17:20:14 +0200
committerValerij Fredriksen <valerijf@verizonmedia.com>2020-04-04 23:25:52 +0200
commit2eb79dd21aa2f4c43a306b3261d7783bc386a8d9 (patch)
tree63f1bf606053b023cba3c20d095dad15bd757164 /node-admin/src/test/java
parent84b1401cb1a92885205a39a13b76f98df7762f08 (diff)
Refactor SystemCtlTester more in-line with YumTester
Diffstat (limited to 'node-admin/src/test/java')
-rw-r--r--node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTesterTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTesterTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTesterTest.java
new file mode 100644
index 00000000000..1c3a6f6a412
--- /dev/null
+++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/systemd/SystemCtlTesterTest.java
@@ -0,0 +1,52 @@
+// Copyright 2020 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.node.admin.task.util.systemd;
+
+import com.yahoo.vespa.hosted.node.admin.component.TestTaskContext;
+import com.yahoo.vespa.hosted.node.admin.task.util.process.TestTerminal;
+import org.junit.Test;
+
+import java.util.List;
+import java.util.function.Function;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author freva
+ */
+public class SystemCtlTesterTest {
+
+ private static final String unit = "my-unit";
+ private final TestTerminal terminal = new TestTerminal();
+ private final SystemCtlTester systemCtl = new SystemCtlTester(terminal);
+ private final TestTaskContext context = new TestTaskContext();
+
+ @Test
+ public void return_expectations() {
+ assertSystemCtlMethod(sct -> sct.expectEnable(unit), sc -> sc.enable(unit).converge(context));
+ assertSystemCtlMethod(sct -> sct.expectDisable(unit), sc -> sc.disable(unit).converge(context));
+ assertSystemCtlMethod(sct -> sct.expectStart(unit), sc -> sc.start(unit).converge(context));
+ assertSystemCtlMethod(sct -> sct.expectStop(unit), sc -> sc.stop(unit).converge(context));
+ assertSystemCtlMethod(sct -> sct.expectServiceExists(unit), sc -> sc.serviceExists(context, unit));
+ assertSystemCtlMethod(sct -> sct.expectIsActive(unit), sc -> sc.isActive(context, unit));
+ }
+
+ @Test
+ public void void_tests() {
+ systemCtl.expectRestart(unit);
+ systemCtl.restart(unit).converge(context);
+ terminal.verifyAllCommandsExecuted();
+
+ systemCtl.expectDaemonReload();
+ systemCtl.daemonReload(context);
+ terminal.verifyAllCommandsExecuted();
+ }
+
+ private void assertSystemCtlMethod(Function<SystemCtlTester, SystemCtlTester.Expectation> systemCtlTesterExpectationFunction,
+ Function<SystemCtl, Boolean> systemCtlFunction) {
+ List.of(true, false).forEach(wantedReturnValue -> {
+ systemCtlTesterExpectationFunction.apply(systemCtl).andReturn(wantedReturnValue);
+ assertEquals(wantedReturnValue, systemCtlFunction.apply(systemCtl));
+ terminal.verifyAllCommandsExecuted();
+ });
+ }
+} \ No newline at end of file