summaryrefslogtreecommitdiffstats
path: root/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/yum/YumTest.java
blob: 4a3c1061ea6d420349882b33a88b433720562821 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2018 Yahoo Holdings. 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.TaskContext;
import com.yahoo.vespa.hosted.node.admin.task.util.process.CommandException;
import com.yahoo.vespa.hosted.node.admin.task.util.process.TestCommandSupplier;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;

public class YumTest {
    TaskContext taskContext = mock(TaskContext.class);
    TestCommandSupplier commandSupplier = new TestCommandSupplier(taskContext);

    @Before
    public void tearDown() {
        commandSupplier.verifyInvocations();
    }

    @Test
    public void testAlreadyInstalled() {
        commandSupplier.expectCommand(
                "yum install --assumeyes --enablerepo=repo-name package-1 package-2",
                0,
                "\nNothing to do\n");

        Yum yum = new Yum(taskContext, commandSupplier);
        assertFalse(yum
                .install("package-1", "package-2")
                .enableRepo("repo-name")
                .converge());
    }

    @Test
    public void testAlreadyUpgraded() {
        commandSupplier.expectCommand(
                "yum upgrade --assumeyes package-1 package-2",
                0,
                "\nNo packages marked for update\n");

        assertFalse(new Yum(taskContext, commandSupplier)
                .upgrade("package-1", "package-2")
                .converge());
    }

    @Test
    public void testAlreadyRemoved() {
        commandSupplier.expectCommand(
                "yum remove --assumeyes package-1 package-2",
                0,
                "\nNo Packages marked for removal\n");

        assertFalse(new Yum(taskContext, commandSupplier)
                .remove("package-1", "package-2")
                .converge());
    }

    @Test
    public void testInstall() {
        commandSupplier.expectCommand(
                "yum install --assumeyes package-1 package-2",
                0,
                "installing, installing");

        Yum yum = new Yum(taskContext, commandSupplier);
        assertTrue(yum
                .install("package-1", "package-2")
                .converge());
    }

    @Test
    public void testInstallWithEnablerepo() {
        commandSupplier.expectCommand(
                "yum install --assumeyes --enablerepo=repo-name package-1 package-2",
                0,
                "installing, installing");

        Yum yum = new Yum(taskContext, commandSupplier);
        assertTrue(yum
                .install("package-1", "package-2")
                .enableRepo("repo-name")
                .converge());
    }

    @Test(expected = CommandException.class)
    public void testFailedInstall() {
        commandSupplier.expectCommand(
                "yum install --assumeyes --enablerepo=repo-name package-1 package-2",
                1,
                "error");

        Yum yum = new Yum(taskContext, commandSupplier);
        yum.install("package-1", "package-2")
                .enableRepo("repo-name")
                .converge();
        fail();
    }
}