Search in sources :

Example 16 with MockTerminal

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

the class ListPluginsCommandTests method listPlugins.

static MockTerminal listPlugins(Path home, String[] args) throws Exception {
    String[] argsAndHome = new String[args.length + 1];
    System.arraycopy(args, 0, argsAndHome, 0, args.length);
    argsAndHome[args.length] = "-Epath.home=" + home;
    MockTerminal terminal = new MockTerminal();
    int status = new ListPluginsCommand() {

        @Override
        protected boolean addShutdownHook() {
            return false;
        }
    }.main(argsAndHome, terminal);
    assertEquals(ExitCodes.OK, status);
    return terminal;
}
Also used : MockTerminal(org.elasticsearch.cli.MockTerminal)

Example 17 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 18 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 19 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 20 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