diff options
author | Valerij Fredriksen <valerij92@gmail.com> | 2020-04-04 17:19:33 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2020-04-04 23:25:52 +0200 |
commit | 84b1401cb1a92885205a39a13b76f98df7762f08 (patch) | |
tree | ac1ead1c2ef89e6962d24c168af26e404b97c714 /node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTesterTest.java | |
parent | b75b9ceb0ea1ac9a2689a7c4c7b57c3829d264d3 (diff) |
Implement YumTester
Diffstat (limited to 'node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTesterTest.java')
-rw-r--r-- | node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTesterTest.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTesterTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTesterTest.java new file mode 100644 index 00000000000..ef380046b75 --- /dev/null +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTesterTest.java @@ -0,0 +1,61 @@ +// 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.yum; + +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.Optional; +import java.util.function.Function; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; + +/** + * @author freva + */ +public class YumTesterTest { + + private static final String[] packages = {"pkg1", "pkg2"}; + private static final String[] repos = {"repo1", "repo2"}; + private static final YumPackageName minimalPackage = YumPackageName.fromString("my-pkg-1.13.1-0.el7"); + private static final YumPackageName fullPackage = YumPackageName.fromString("2:my-pkg-1.13.1-0.el7.x86_64"); + + private final TestTerminal terminal = new TestTerminal(); + private final YumTester yum = new YumTester(terminal); + private final TestTaskContext context = new TestTaskContext(); + + @Test + public void generic_yum_methods() { + assertYumMethod(yum -> yum.expectInstall(packages).withEnableRepo(repos), + yum -> yum.install(List.of(packages)).enableRepo(repos).converge(context)); + + assertYumMethod(yum -> yum.expectUpdate(packages).withEnableRepo(repos), + yum -> yum.upgrade(List.of(packages)).enableRepo(repos).converge(context)); + + assertYumMethod(yum -> yum.expectRemove(packages).withEnableRepo(repos), + yum -> yum.remove(List.of(packages)).enableRepo(repos).converge(context)); + + assertYumMethod(yum -> yum.expectInstallFixedVersion(minimalPackage.toName()).withEnableRepo(repos), + yum -> yum.installFixedVersion(minimalPackage).enableRepo(repos).converge(context)); + } + + @Test + public void expect_query_installed() { + Stream.of(minimalPackage, fullPackage, null).forEach(pkg -> { + yum.expectQueryInstalled(packages[0]).andReturn(pkg); + assertEquals(Optional.ofNullable(pkg), yum.queryInstalled(context, packages[0])); + terminal.verifyAllCommandsExecuted(); + }); + } + + private void assertYumMethod(Function<YumTester, YumTester.GenericYumCommandExpectation> yumTesterExpectationFunction, + Function<Yum, Boolean> yumFunction) { + List.of(true, false).forEach(wantedReturnValue -> { + yumTesterExpectationFunction.apply(yum).andReturn(wantedReturnValue); + assertEquals(wantedReturnValue, yumFunction.apply(yum)); + terminal.verifyAllCommandsExecuted(); + }); + } +}
\ No newline at end of file |