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

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 08390b7ff85 [Test](nereids) add ut for ShowTableStatusCommand (#54061)
08390b7ff85 is described below

commit 08390b7ff857d6bf976580f163360566567eb2fa
Author: Jensen <[email protected]>
AuthorDate: Wed Jul 30 14:49:31 2025 +0800

    [Test](nereids) add ut for ShowTableStatusCommand (#54061)
---
 .../plans/commands/ShowTableStatusCommand.java     |   4 +-
 .../plans/commands/ShowTableStatusCommandTest.java | 145 +++++++++++++++++++++
 2 files changed, 148 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommand.java
index 07455b09245..eacc45ebc86 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommand.java
@@ -41,6 +41,7 @@ import org.apache.doris.qe.ShowResultSet;
 import org.apache.doris.qe.ShowResultSetMetaData;
 import org.apache.doris.qe.StmtExecutor;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableMap;
 
@@ -124,7 +125,8 @@ public class ShowTableStatusCommand extends ShowCommand {
     /**
      * validate
      */
-    private void validate(ConnectContext ctx) throws AnalysisException {
+    @VisibleForTesting
+    protected void validate(ConnectContext ctx) throws AnalysisException {
         if (Strings.isNullOrEmpty(db)) {
             db = ctx.getDatabase();
             if (Strings.isNullOrEmpty(db)) {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommandTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommandTest.java
new file mode 100644
index 00000000000..42cc4a3aae0
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowTableStatusCommandTest.java
@@ -0,0 +1,145 @@
+// 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.doris.nereids.trees.plans.commands;
+
+import org.apache.doris.backup.CatalogMocker;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.datasource.CatalogMgr;
+import org.apache.doris.datasource.InternalCatalog;
+import org.apache.doris.mysql.privilege.AccessControllerManager;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
+import org.apache.doris.qe.ConnectContext;
+
+import mockit.Expectations;
+import mockit.Mocked;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ShowTableStatusCommandTest {
+    private static final String internalCtl = 
InternalCatalog.INTERNAL_CATALOG_NAME;
+
+    @Mocked
+    private Env env;
+    @Mocked
+    private AccessControllerManager accessManager;
+    @Mocked
+    private ConnectContext ctx;
+    @Mocked
+    private InternalCatalog catalog;
+    @Mocked
+    private CatalogMgr catalogMgr;
+
+    @Test
+    void testValidate() {
+        new Expectations() {
+            {
+                Env.getCurrentEnv();
+                minTimes = 0;
+                result = env;
+
+                ConnectContext.get();
+                minTimes = 0;
+                result = ctx;
+
+                ctx.isSkipAuth();
+                minTimes = 0;
+                result = true;
+
+                env.getAccessManager();
+                minTimes = 0;
+                result = accessManager;
+
+                env.getCatalogMgr();
+                minTimes = 0;
+                result = catalogMgr;
+
+                catalogMgr.getCatalog(anyString);
+                minTimes = 0;
+                result = catalog;
+
+                accessManager.checkDbPriv(ctx, 
InternalCatalog.INTERNAL_CATALOG_NAME, CatalogMocker.TEST_DB_NAME,
+                        PrivPredicate.SHOW);
+                minTimes = 0;
+                result = true;
+            }
+        };
+        EqualTo equalTo = new EqualTo(new UnboundSlot("name"),
+                new StringLiteral(CatalogMocker.TEST_DB_NAME));
+
+        ShowTableStatusCommand command = new 
ShowTableStatusCommand(CatalogMocker.TEST_DB_NAME,
+                InternalCatalog.INTERNAL_CATALOG_NAME);
+        Assertions.assertDoesNotThrow(() -> command.validate(ctx));
+
+        ShowTableStatusCommand command2 = new 
ShowTableStatusCommand(CatalogMocker.TEST_DB_NAME,
+                InternalCatalog.INTERNAL_CATALOG_NAME, "%example%", equalTo);
+        Assertions.assertDoesNotThrow(() -> command2.validate(ctx));
+    }
+
+    @Test
+    void testInvalidate() {
+        new Expectations() {
+            {
+                Env.getCurrentEnv();
+                minTimes = 0;
+                result = env;
+
+                ConnectContext.get();
+                minTimes = 0;
+                result = ctx;
+
+                ctx.isSkipAuth();
+                minTimes = 0;
+                result = true;
+
+                env.getAccessManager();
+                minTimes = 0;
+                result = accessManager;
+
+                env.getCatalogMgr();
+                minTimes = 0;
+                result = catalogMgr;
+
+                catalogMgr.getCatalog(anyString);
+                minTimes = 0;
+                result = catalog;
+
+                accessManager.checkDbPriv(ctx, 
InternalCatalog.INTERNAL_CATALOG_NAME, CatalogMocker.TEST_DB_NAME,
+                        PrivPredicate.SHOW);
+                minTimes = 0;
+                result = false;
+            }
+        };
+        EqualTo equalTo = new EqualTo(new UnboundSlot("name"),
+                new StringLiteral(CatalogMocker.TEST_DB_NAME));
+
+        ShowTableStatusCommand command = new ShowTableStatusCommand("", 
InternalCatalog.INTERNAL_CATALOG_NAME);
+        Assertions.assertThrows(AnalysisException.class, () -> 
command.validate(ctx));
+
+        ShowTableStatusCommand command1 = new 
ShowTableStatusCommand(CatalogMocker.TEST_DB_NAME, "");
+        Assertions.assertThrows(AnalysisException.class, () -> 
command1.validate(ctx));
+
+        ShowTableStatusCommand command2 = new 
ShowTableStatusCommand(CatalogMocker.TEST_DB_NAME,
+                InternalCatalog.INTERNAL_CATALOG_NAME, "%example%", equalTo);
+        Assertions.assertThrows(AnalysisException.class, () -> 
command2.validate(ctx));
+    }
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to