You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/10/16 14:22:13 UTC

(shardingsphere) branch master updated: Add test cases on MySQLAuthenticationPlugin (#33268)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new fc3fe915018 Add test cases on MySQLAuthenticationPlugin (#33268)
fc3fe915018 is described below

commit fc3fe915018be18cdbf4d5f697130fbd72965e8f
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Wed Oct 16 22:22:05 2024 +0800

    Add test cases on MySQLAuthenticationPlugin (#33268)
    
    * Add more cases on InstanceMetaDataBuilder
    
    * Add test cases on MySQLAuthenticationPlugin
---
 .../mysql/constant/MySQLAuthenticationPlugin.java  |  5 +--
 .../constant/MySQLAuthenticationPluginTest.java    | 36 ++++++++++++++++++++++
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPlugin.java b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPlugin.java
index 14bef7dfae7..1a5f9a69cdd 100644
--- a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPlugin.java
+++ b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPlugin.java
@@ -57,9 +57,6 @@ public enum MySQLAuthenticationPlugin {
      * @return mysql authentication plugin
      */
     public static MySQLAuthenticationPlugin getPluginByName(final String pluginName) {
-        if (VALUE_AND_COLUMN_TYPE_MAP.containsKey(pluginName)) {
-            return VALUE_AND_COLUMN_TYPE_MAP.get(pluginName);
-        }
-        return DEFAULT;
+        return VALUE_AND_COLUMN_TYPE_MAP.getOrDefault(pluginName, DEFAULT);
     }
 }
diff --git a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPluginTest.java b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPluginTest.java
new file mode 100644
index 00000000000..55d2d09efb6
--- /dev/null
+++ b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLAuthenticationPluginTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.shardingsphere.db.protocol.mysql.constant;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+class MySQLAuthenticationPluginTest {
+    
+    @Test
+    void assertGetPluginByName() {
+        assertThat(MySQLAuthenticationPlugin.getPluginByName("mysql_native_password"), is(MySQLAuthenticationPlugin.NATIVE));
+    }
+    
+    @Test
+    void assertGetPluginByNameWithDefault() {
+        assertThat(MySQLAuthenticationPlugin.getPluginByName("invalid"), is(MySQLAuthenticationPlugin.DEFAULT));
+    }
+}