blob: 3e444f08508bfbe2a82b49c1e69916c8f0b471cf (
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
|
// 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;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class AddYumRepoTaskTest extends TaskTestBase {
private Path expectedPath;
private String expectedContent;
private AddYumRepoTask task;
public void setUp() {
String repository = "repo-id";
String name = "name";
String baseUrl = "base-url";
boolean enabled = true;
expectedContent = "# This file was generated by node admin\n" +
"# Do NOT modify this file by hand\n" +
"\n" +
"[repo-id]\n" +
"name=name\n" +
"baseurl=base-url\n" +
"enabled=1\n" +
"gpgcheck=0\n";
task = new AddYumRepoTask(repository, name, baseUrl, enabled);
expectedPath = Paths.get("/etc/yum.repos.d/" + repository + ".repo");
}
@Test
public void alreadyExistsIsNoOp() {
when(fileSystemMock.isRegularFile(expectedPath)).thenReturn(true);
assertFalse(task.execute(contextMock));
}
@Test
public void fileContent() {
assertEquals(expectedContent, task.getRepoFileContent());
}
@Test
public void createsFile() {
when(fileSystemMock.isRegularFile(expectedPath)).thenReturn(false);
when(contextMock.executeSubtask(any())).thenReturn(true);
assertTrue(task.execute(contextMock));
// Writing a file with the expected content
ArgumentCaptor<WriteFileTask> writeFileTaskArgumentCaptor =
ArgumentCaptor.forClass(WriteFileTask.class);
verify(contextMock, times(1))
.executeSubtask(writeFileTaskArgumentCaptor.capture());
WriteFileTask writeFileTask = writeFileTaskArgumentCaptor.getValue();
assertEquals(expectedPath, writeFileTask.getPath());
assertEquals(expectedContent, writeFileTask.getContentProducer().call());
assertEquals("rw-r--r--", writeFileTask.getPermissions().get());
assertEquals("root", writeFileTask.getOwner().get());
assertEquals("root", writeFileTask.getGroup().get());
}
}
|