|
50 | 50 | import java.nio.file.DirectoryStream;
|
51 | 51 | import java.nio.file.Files;
|
52 | 52 | import java.nio.file.Path;
|
| 53 | +import java.util.Arrays; |
53 | 54 | import java.util.Map;
|
| 55 | +import java.util.stream.Stream; |
54 | 56 |
|
55 | 57 | import static org.hamcrest.CoreMatchers.containsString;
|
56 | 58 | import static org.hamcrest.CoreMatchers.not;
|
@@ -90,34 +92,34 @@ public void setUp() throws Exception {
|
90 | 92 | env = TestEnvironment.newEnvironment(settings);
|
91 | 93 | }
|
92 | 94 |
|
93 |
| - void createPlugin(String name) throws IOException { |
94 |
| - createPlugin(env.pluginsFile(), name); |
| 95 | + void createPlugin(String name, String... additionalProps) throws IOException { |
| 96 | + createPlugin(env.pluginsFile(), name, Version.CURRENT, additionalProps); |
95 | 97 | }
|
96 | 98 |
|
97 | 99 | void createPlugin(String name, Version version) throws IOException {
|
98 | 100 | createPlugin(env.pluginsFile(), name, version);
|
99 | 101 | }
|
100 | 102 |
|
101 |
| - void createPlugin(Path path, String name) throws IOException { |
102 |
| - createPlugin(path, name, Version.CURRENT); |
103 |
| - } |
104 |
| - |
105 |
| - void createPlugin(Path path, String name, Version version) throws IOException { |
106 |
| - PluginTestUtil.writePluginProperties( |
107 |
| - path.resolve(name), |
108 |
| - "description", |
109 |
| - "dummy", |
110 |
| - "name", |
111 |
| - name, |
112 |
| - "version", |
113 |
| - "1.0", |
114 |
| - "opensearch.version", |
115 |
| - version.toString(), |
116 |
| - "java.version", |
117 |
| - System.getProperty("java.specification.version"), |
118 |
| - "classname", |
119 |
| - "SomeClass" |
120 |
| - ); |
| 103 | + void createPlugin(Path path, String name, Version version, String... additionalProps) throws IOException { |
| 104 | + String[] properties = Stream.concat( |
| 105 | + Stream.of( |
| 106 | + "description", |
| 107 | + "dummy", |
| 108 | + "name", |
| 109 | + name, |
| 110 | + "version", |
| 111 | + "1.0", |
| 112 | + "opensearch.version", |
| 113 | + version.toString(), |
| 114 | + "java.version", |
| 115 | + System.getProperty("java.specification.version"), |
| 116 | + "classname", |
| 117 | + "SomeClass" |
| 118 | + ), |
| 119 | + Arrays.stream(additionalProps) |
| 120 | + ).toArray(String[]::new); |
| 121 | + String pluginFolderName = additionalProps.length == 0 ? name : additionalProps[1]; |
| 122 | + PluginTestUtil.writePluginProperties(path.resolve(pluginFolderName), properties); |
121 | 123 | }
|
122 | 124 |
|
123 | 125 | static MockTerminal removePlugin(String name, Path home, boolean purge) throws Exception {
|
@@ -154,6 +156,17 @@ public void testBasic() throws Exception {
|
154 | 156 | assertRemoveCleaned(env);
|
155 | 157 | }
|
156 | 158 |
|
| 159 | + public void testRemovePluginWithCustomFolderName() throws Exception { |
| 160 | + createPlugin("fake", "custom.foldername", "custom-folder"); |
| 161 | + Files.createFile(env.pluginsFile().resolve("custom-folder").resolve("plugin.jar")); |
| 162 | + Files.createDirectory(env.pluginsFile().resolve("custom-folder").resolve("subdir")); |
| 163 | + createPlugin("other"); |
| 164 | + removePlugin("fake", home, randomBoolean()); |
| 165 | + assertFalse(Files.exists(env.pluginsFile().resolve("custom-folder"))); |
| 166 | + assertTrue(Files.exists(env.pluginsFile().resolve("other"))); |
| 167 | + assertRemoveCleaned(env); |
| 168 | + } |
| 169 | + |
157 | 170 | public void testRemoveOldVersion() throws Exception {
|
158 | 171 | createPlugin(
|
159 | 172 | "fake",
|
@@ -261,6 +274,7 @@ protected boolean addShutdownHook() {
|
261 | 274 | BufferedReader reader = new BufferedReader(new StringReader(terminal.getOutput()));
|
262 | 275 | BufferedReader errorReader = new BufferedReader(new StringReader(terminal.getErrorOutput()))
|
263 | 276 | ) {
|
| 277 | + assertEquals("searching in other folders to find if plugin exists with custom folder name", reader.readLine()); |
264 | 278 | assertEquals("-> removing [fake]...", reader.readLine());
|
265 | 279 | assertEquals(
|
266 | 280 | "ERROR: plugin [fake] not found; run 'opensearch-plugin list' to get list of installed plugins",
|
|
0 commit comments