use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class InstallPluginCommandTests method testFileNotMaven.
public void testFileNotMaven() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
String dir = randomAlphaOfLength(10) + ":" + randomAlphaOfLength(5) + "\\" + randomAlphaOfLength(5);
Exception e = expectThrows(Exception.class, // has two colons, so it appears similar to maven coordinates
() -> installPlugin("file:" + dir, env.v1()));
assertFalse(e.getMessage(), e.getMessage().contains("maven.org"));
assertTrue(e.getMessage(), e.getMessage().contains(dir));
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class InstallPluginCommandTests method testMalformedUrlNotMaven.
public void testMalformedUrlNotMaven() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
// has two colons, so it appears similar to maven coordinates
MalformedURLException e = expectThrows(MalformedURLException.class, () -> installPlugin("://host:1234", env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("no protocol"));
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class InstallPluginCommandTests method testMissingPluginId.
public void testMissingPluginId() throws IOException {
final Tuple<Path, Environment> env = createEnv(fs, temp);
final UserException e = expectThrows(UserException.class, () -> installPlugin(null, env.v1()));
assertTrue(e.getMessage(), e.getMessage().contains("at least one plugin id is required"));
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class InstallPluginCommandTests method testTransaction.
public void testTransaction() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path pluginDir = createPluginDir(temp);
String pluginZip = createPluginUrl("fake", pluginDir);
final FileNotFoundException e = expectThrows(FileNotFoundException.class, () -> installPlugins(Arrays.asList(pluginZip, pluginZip + "does-not-exist"), env.v1()));
assertThat(e, hasToString(containsString("does-not-exist")));
final Path fakeInstallPath = env.v2().pluginsFile().resolve("fake");
// fake should have been removed when the file not found exception occurred
assertFalse(Files.exists(fakeInstallPath));
assertInstallCleaned(env.v2());
}
use of org.opensearch.env.Environment in project OpenSearch by opensearch-project.
the class InstallPluginCommandTests method testExistingConfig.
public void testExistingConfig() throws Exception {
Tuple<Path, Environment> env = createEnv(fs, temp);
Path envConfigDir = env.v2().configFile().resolve("fake");
Files.createDirectories(envConfigDir);
Files.write(envConfigDir.resolve("custom.yml"), "existing config".getBytes(StandardCharsets.UTF_8));
Path pluginDir = createPluginDir(temp);
Path configDir = pluginDir.resolve("config");
Files.createDirectory(configDir);
Files.write(configDir.resolve("custom.yml"), "new config".getBytes(StandardCharsets.UTF_8));
Files.createFile(configDir.resolve("other.yml"));
String pluginZip = createPluginUrl("fake", pluginDir);
installPlugin(pluginZip, env.v1());
assertPlugin("fake", pluginDir, env.v2());
List<String> configLines = Files.readAllLines(envConfigDir.resolve("custom.yml"), StandardCharsets.UTF_8);
assertEquals(1, configLines.size());
assertEquals("existing config", configLines.get(0));
assertTrue(Files.exists(envConfigDir.resolve("other.yml")));
}
Aggregations