-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShellCommandTestCase.java
126 lines (119 loc) · 4.11 KB
/
ShellCommandTestCase.java
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package jfill;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
final class ShellCommandTestCase {
@Test
@DisplayName("Test that echo output was saved to file")
void testOutput(@TempDir final Path tempDir) throws Exception {
var cacheFile = tempDir.resolve("out.txt").toFile();
new ShellCommand(
new String[]{"echo", "{{msg1}}", "{{msg2}}"},
new ResolvedValues(
Map.of(
Defaults.NO_TAG,
Map.of(
"msg1", "Hello",
"msg2", "World"
)
)
),
new ProcessBuilder().redirectOutput(cacheFile)
).execute();
Assertions.assertEquals(
"Hello World",
Files.readString(cacheFile.toPath()).replace("\n", "")
);
}
@Test
@DisplayName("Test that echo output with tags was saved to file")
void testOutputWithTag(@TempDir final Path tempDir) throws Exception {
var cacheFile = tempDir.resolve("out.txt").toFile();
new ShellCommand(
new String[]{"echo", "{{tag1:msg1}}", "{{tag2:msg2}}"},
new ResolvedValues(
Map.of(
"tag1",
Map.of(
"msg1", "Hello"
),
"tag2",
Map.of(
"msg2", "World"
)
)
),
new ProcessBuilder().redirectOutput(cacheFile)
).execute();
Assertions.assertEquals(
"Hello World",
Files.readString(cacheFile.toPath()).replace("\n", "")
);
}
@Test
@DisplayName("Test that curl was executed and status is 200")
void testExecuteCurl(@TempDir final Path tempDir) throws Exception {
var cacheFile = tempDir.resolve("out.txt").toFile();
new ShellCommand(
new String[]{"curl", "-I", "{{url}}.com"},
new ResolvedValues(
Map.of(
Defaults.NO_TAG,
Map.of(
"url", "https://www.test"
)
)
),
new ProcessBuilder().redirectOutput(cacheFile)
).execute();
Assertions.assertTrue(
Files.readString(cacheFile.toPath()).contains("200 OK")
);
}
@Test
@DisplayName("Test that when value is in the one of the word then only part of the word is replaced")
void testValueInTheBeginningOfWord(@TempDir final Path tempDir) throws Exception {
var cacheFile = tempDir.resolve("out.txt").toFile();
new ShellCommand(
new String[]{"echo", "{{url}}/users/1"},
new ResolvedValues(
Map.of(
Defaults.NO_TAG,
Map.of(
"url", "localhost"
)
)
),
new ProcessBuilder().redirectOutput(cacheFile)
).execute();
Assertions.assertEquals(
"localhost/users/1",
Files.readString(cacheFile.toPath()).replace("\n", "")
);
}
@Test
@DisplayName("Test that when value is in the one of the word then only part of the word is replaced")
void testValueInTheEndOfWord(@TempDir final Path tempDir) throws Exception {
var cacheFile = tempDir.resolve("out.txt").toFile();
new ShellCommand(
new String[]{"echo", "localhost/{{path}}"},
new ResolvedValues(
Map.of(
Defaults.NO_TAG,
Map.of(
"path", "users/1"
)
)
),
new ProcessBuilder().redirectOutput(cacheFile)
).execute();
Assertions.assertEquals(
"localhost/users/1",
Files.readString(cacheFile.toPath()).replace("\n", "")
);
}
}