|
3 | 3 | import static org.junit.Assert.assertFalse;
|
4 | 4 | import static org.junit.Assert.assertTrue;
|
5 | 5 |
|
6 |
| -import com.cloudbees.jenkins.support.SafeLog; |
7 | 6 | import com.cloudbees.jenkins.support.SupportTestUtils;
|
8 | 7 | import hudson.model.Label;
|
9 | 8 | import hudson.slaves.DumbSlave;
|
10 | 9 | import java.util.Map;
|
11 |
| -import org.junit.After; |
12 |
| -import org.junit.Before; |
13 | 10 | import org.junit.Rule;
|
14 | 11 | import org.junit.Test;
|
15 |
| -import org.jvnet.hudson.test.JenkinsSessionRule; |
| 12 | +import org.jvnet.hudson.test.JenkinsRule; |
16 | 13 |
|
17 | 14 | /**
|
18 | 15 | * Tests for the {@link NodeRemoteDirectoryComponent}
|
19 | 16 | */
|
20 | 17 | public class NodeRemoteDirectoryComponentTest {
|
21 | 18 |
|
22 | 19 | @Rule
|
23 |
| - public JenkinsSessionRule r = new JenkinsSessionRule(); |
24 |
| - |
25 |
| - @Before |
26 |
| - public void clearLog() throws Throwable { |
27 |
| - SafeLog.clear(); |
28 |
| - } |
29 |
| - |
30 |
| - @After |
31 |
| - public void showLog() throws Throwable { |
32 |
| - SafeLog.show(); |
33 |
| - } |
| 20 | + public JenkinsRule j = new JenkinsRule(); |
34 | 21 |
|
35 | 22 | /*
|
36 | 23 | * Test adding agent remote directory content with the defaults.
|
37 | 24 | */
|
38 | 25 | @Test
|
39 |
| - public void addContents() throws Throwable { |
40 |
| - r.then(j -> { |
41 |
| - DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null); |
| 26 | + public void addContents() throws Exception { |
| 27 | + DumbSlave agent = j.createOnlineSlave(Label.parseExpression("test"), null); |
42 | 28 |
|
43 |
| - Map<String, String> output = |
44 |
| - SupportTestUtils.invokeComponentToMap(new NodeRemoteDirectoryComponent(), agent.toComputer()); |
| 29 | + Map<String, String> output = |
| 30 | + SupportTestUtils.invokeComponentToMap(new NodeRemoteDirectoryComponent(), agent.toComputer()); |
45 | 31 |
|
46 |
| - String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
47 |
| - assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log"))); |
48 |
| - }); |
| 32 | + String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
| 33 | + assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log"))); |
49 | 34 | }
|
50 | 35 |
|
51 | 36 | /*
|
52 | 37 | * Test adding agent remote directory content with excludes pattern(s).
|
53 | 38 | */
|
54 | 39 | @Test
|
55 |
| - public void addContentsWithExcludes() throws Throwable { |
56 |
| - r.then(j -> { |
57 |
| - DumbSlave agent = j.createSlave("agent1", "test", null); |
58 |
| - agent.getComputer().connect(false).get(); |
59 |
| - j.waitOnline(agent); |
60 |
| - |
61 |
| - Map<String, String> output = SupportTestUtils.invokeComponentToMap( |
62 |
| - new NodeRemoteDirectoryComponent("", "**/*.log", true, 10), agent.toComputer()); |
63 |
| - |
64 |
| - String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
65 |
| - assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + ".*/.*.log"))); |
66 |
| - }); |
| 40 | + public void addContentsWithExcludes() throws Exception { |
| 41 | + DumbSlave agent = j.createSlave("agent1", "test", null); |
| 42 | + agent.getComputer().connect(false).get(); |
| 43 | + j.waitOnline(agent); |
| 44 | + |
| 45 | + Map<String, String> output = SupportTestUtils.invokeComponentToMap( |
| 46 | + new NodeRemoteDirectoryComponent("", "**/*.log", true, 10), agent.toComputer()); |
| 47 | + |
| 48 | + String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
| 49 | + assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + ".*/.*.log"))); |
67 | 50 | }
|
68 | 51 |
|
69 | 52 | /*
|
70 | 53 | * Test adding agent remote directory content with includes pattern(s).
|
71 | 54 | */
|
72 | 55 | @Test
|
73 |
| - public void addContentsWithIncludes() throws Throwable { |
74 |
| - r.then(j -> { |
75 |
| - DumbSlave agent = j.createSlave("agent1", "test", null); |
76 |
| - agent.getComputer().connect(false).get(); |
77 |
| - j.waitOnline(agent); |
78 |
| - |
79 |
| - Map<String, String> output = SupportTestUtils.invokeComponentToMap( |
80 |
| - new NodeRemoteDirectoryComponent("support/*.log", "", true, 10), agent.toComputer()); |
81 |
| - |
82 |
| - String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
83 |
| - assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log"))); |
84 |
| - }); |
| 56 | + public void addContentsWithIncludes() throws Exception { |
| 57 | + DumbSlave agent = j.createSlave("agent1", "test", null); |
| 58 | + agent.getComputer().connect(false).get(); |
| 59 | + j.waitOnline(agent); |
| 60 | + |
| 61 | + Map<String, String> output = SupportTestUtils.invokeComponentToMap( |
| 62 | + new NodeRemoteDirectoryComponent("support/*.log", "", true, 10), agent.toComputer()); |
| 63 | + |
| 64 | + String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
| 65 | + assertTrue(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log"))); |
85 | 66 | }
|
86 | 67 |
|
87 | 68 | /*
|
88 | 69 | * Test adding agent remote directory content with includes pattern(s).
|
89 | 70 | */
|
90 | 71 | @Test
|
91 |
| - public void addContentsWithMaxDepth() throws Throwable { |
92 |
| - r.then(j -> { |
93 |
| - DumbSlave agent = j.createSlave("agent1", "test", null); |
94 |
| - agent.getComputer().connect(false).get(); |
95 |
| - j.waitOnline(agent); |
96 |
| - |
97 |
| - Map<String, String> output = SupportTestUtils.invokeComponentToMap( |
98 |
| - new NodeRemoteDirectoryComponent("", "", true, 1), agent.toComputer()); |
99 |
| - |
100 |
| - String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
101 |
| - assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log"))); |
102 |
| - }); |
| 72 | + public void addContentsWithMaxDepth() throws Exception { |
| 73 | + DumbSlave agent = j.createSlave("agent1", "test", null); |
| 74 | + agent.getComputer().connect(false).get(); |
| 75 | + j.waitOnline(agent); |
| 76 | + |
| 77 | + Map<String, String> output = SupportTestUtils.invokeComponentToMap( |
| 78 | + new NodeRemoteDirectoryComponent("", "", true, 1), agent.toComputer()); |
| 79 | + |
| 80 | + String prefix = "nodes/slave/" + agent.getNodeName() + "/remote"; |
| 81 | + assertFalse(output.keySet().stream().anyMatch(key -> key.matches(prefix + "/support/.*.log"))); |
103 | 82 | }
|
104 | 83 | }
|
0 commit comments