This is an automated email from the ASF dual-hosted git repository.

sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 92a50ce53a IGNITE-18041 Fixed Unknown error when running CLI sql 
command with file option. Fixes #1294
92a50ce53a is described below

commit 92a50ce53a1178008d10e442fe79509696d62229
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Tue Nov 15 18:35:59 2022 +0200

    IGNITE-18041 Fixed Unknown error when running CLI sql command with file 
option. Fixes #1294
    
    Signed-off-by: Slava Koptilin <[email protected]>
---
 .../cli/commands/sql/ItSqlCommandTest.java         | 12 ++++++
 .../cli/commands/sql/ItSqlReplCommandTest.java     | 44 ++++++++++++++++++++++
 .../internal/cli/commands/sql/SqlReplCommand.java  |  2 +-
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git 
a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
 
b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
index d369b5a3f4..b481a5f967 100644
--- 
a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
+++ 
b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlCommandTest.java
@@ -43,6 +43,18 @@ class ItSqlCommandTest extends 
CliCommandTestInitializedIntegrationBase {
         dropAllTables();
     }
 
+    @Test
+    @DisplayName("Should throw error if executed with non-existing file")
+    void nonExistingFile() {
+        execute("sql", "-f", "nonexisting", "--jdbc-url", JDBC_URL);
+
+        assertAll(
+                () -> assertExitCodeIs(1),
+                this::assertOutputIsEmpty,
+                () -> assertErrOutputContains("File with command not found")
+        );
+    }
+
     @Test
     @DisplayName("Should execute select * from table and display table when 
jdbc-url is correct")
     void selectFromTable() {
diff --git 
a/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java
 
b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java
new file mode 100644
index 0000000000..89291c22dc
--- /dev/null
+++ 
b/modules/cli/src/integrationTest/java/org/apache/ignite/internal/cli/commands/sql/ItSqlReplCommandTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.cli.commands.sql;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import 
org.apache.ignite.internal.cli.commands.CliCommandTestInitializedIntegrationBase;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+/** Tests for {@link SqlReplCommand}. */
+class ItSqlReplCommandTest extends CliCommandTestInitializedIntegrationBase {
+    @Override
+    protected Class<?> getCommandClass() {
+        return SqlReplCommand.class;
+    }
+
+    @Test
+    @DisplayName("Should throw error if executed with non-existing file")
+    void nonExistingFile() {
+        execute("-f", "nonexisting", "--jdbc-url", JDBC_URL);
+
+        assertAll(
+                this::assertOutputIsEmpty,
+                // Actual output starts with exception since this test doesn't 
use ReplExecutor and exception is handled by picocli.
+                () -> assertErrOutputContains("File with command not found")
+        );
+    }
+}
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
index 9dfde2f49f..b020803dae 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/sql/SqlReplCommand.java
@@ -86,7 +86,7 @@ public class SqlReplCommand extends BaseCommand implements 
Runnable {
     public void run() {
         try (SqlManager sqlManager = new SqlManager(jdbc)) {
             // When passing white space to this command, picocli will treat it 
as a positional argument
-            if (execOptions == null || execOptions.command.isBlank()) {
+            if (execOptions == null || (execOptions.command != null && 
execOptions.command.isBlank())) {
                 replExecutorProvider.get().execute(Repl.builder()
                         .withPromptProvider(() -> "sql-cli> ")
                         .withCompleter(new SqlCompleter(new 
SqlSchemaProvider(sqlManager::getMetadata)))

Reply via email to