Search in sources :

Example 6 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class InternalSettingsPreparerTests method testReplacePromptPlaceholders.

public void testReplacePromptPlaceholders() {
    MockTerminal terminal = new MockTerminal();
    terminal.addTextInput("text");
    terminal.addSecretInput("replaced");
    Settings.Builder builder = Settings.builder().put(baseEnvSettings).put("password.replace", InternalSettingsPreparer.SECRET_PROMPT_VALUE).put("dont.replace", "prompt:secret").put("dont.replace2", "_prompt:secret_").put("dont.replace3", "_prompt:text__").put("dont.replace4", "__prompt:text_").put("dont.replace5", "prompt:secret__").put("replace_me", InternalSettingsPreparer.TEXT_PROMPT_VALUE);
    Settings settings = InternalSettingsPreparer.prepareEnvironment(builder.build(), terminal).settings();
    assertThat(settings.get("password.replace"), equalTo("replaced"));
    assertThat(settings.get("replace_me"), equalTo("text"));
    // verify other values unchanged
    assertThat(settings.get("dont.replace"), equalTo("prompt:secret"));
    assertThat(settings.get("dont.replace2"), equalTo("_prompt:secret_"));
    assertThat(settings.get("dont.replace3"), equalTo("_prompt:text__"));
    assertThat(settings.get("dont.replace4"), equalTo("__prompt:text_"));
    assertThat(settings.get("dont.replace5"), equalTo("prompt:secret__"));
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal) MockSecureSettings(org.elasticsearch.common.settings.MockSecureSettings) Settings(org.elasticsearch.common.settings.Settings)

Example 7 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class InstallPluginCommandTests method testOfficialPluginsHelpSorted.

public void testOfficialPluginsHelpSorted() throws Exception {
    MockTerminal terminal = new MockTerminal();
    new InstallPluginCommand() {

        @Override
        protected boolean addShutdownHook() {
            return false;
        }
    }.main(new String[] { "--help" }, terminal);
    try (BufferedReader reader = new BufferedReader(new StringReader(terminal.getOutput()))) {
        String line = reader.readLine();
        // first find the beginning of our list of official plugins
        while (line.endsWith("may be installed by name:") == false) {
            line = reader.readLine();
        }
        // now check each line compares greater than the last, until we reach an empty line
        String prev = reader.readLine();
        line = reader.readLine();
        while (line != null && line.trim().isEmpty() == false) {
            assertTrue(prev + " < " + line, prev.compareTo(line) < 0);
            prev = line;
            line = reader.readLine();
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Matchers.containsString(org.hamcrest.Matchers.containsString) MockTerminal(org.elasticsearch.cli.MockTerminal)

Example 8 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class InstallPluginCommandTests method testQuietFlagEnabled.

public void testQuietFlagEnabled() throws Exception {
    MockTerminal terminal = new MockTerminal();
    terminal.setVerbosity(Terminal.Verbosity.SILENT);
    installPlugin(terminal, false);
    assertThat(terminal.getOutput(), not(containsString("100%")));
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Example 9 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class InstallPluginCommandTests method installPlugin.

static MockTerminal installPlugin(String pluginUrl, Path home, boolean jarHellCheck) throws Exception {
    Environment env = new Environment(Settings.builder().put("path.home", home).build());
    MockTerminal terminal = new MockTerminal();
    new InstallPluginCommand() {

        @Override
        void jarHellCheck(Path candidate, Path pluginsDir) throws Exception {
            if (jarHellCheck) {
                super.jarHellCheck(candidate, pluginsDir);
            }
        }
    }.execute(terminal, pluginUrl, true, env);
    return terminal;
}
Also used : Path(java.nio.file.Path) Environment(org.elasticsearch.env.Environment) MockTerminal(org.elasticsearch.cli.MockTerminal) NoSuchFileException(java.nio.file.NoSuchFileException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) UserException(org.elasticsearch.cli.UserException)

Example 10 with MockTerminal

use of org.elasticsearch.cli.MockTerminal in project elasticsearch by elastic.

the class InstallPluginCommandTests method testBatchFlag.

public void testBatchFlag() throws Exception {
    MockTerminal terminal = new MockTerminal();
    installPlugin(terminal, true);
    assertThat(terminal.getOutput(), containsString("WARNING: plugin requires additional permissions"));
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Aggregations

MockTerminal (org.elasticsearch.cli.MockTerminal)20 Path (java.nio.file.Path)5 Environment (org.elasticsearch.env.Environment)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 UserException (org.elasticsearch.cli.UserException)2 Settings (org.elasticsearch.common.settings.Settings)2 MalformedURLException (java.net.MalformedURLException)1 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1 Directory (org.apache.lucene.store.Directory)1 FSDirectory (org.apache.lucene.store.FSDirectory)1 Lock (org.apache.lucene.store.Lock)1 LockObtainFailedException (org.apache.lucene.store.LockObtainFailedException)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)1