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 8ebfa5ca25e Add test coverage for missing PostgreSQL backend
components (#36888)
8ebfa5ca25e is described below
commit 8ebfa5ca25e9f8e0065d393bbf0a2e96914eb421
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Oct 17 00:56:47 2025 +0800
Add test coverage for missing PostgreSQL backend components (#36888)
* Add test coverage for missing PostgreSQL backend components
- Add PostgreSQLCharsetVariableProviderTest with 5 test cases covering
charset variable parsing using SPI
- Add PostgreSQLSelectAdminExecutorFactoryTest with 3 test cases covering
admin executor creation logic
- Both test files use SPI mechanism for component instantiation following
project patterns
- Tests cover previously uncovered code paths in PostgreSQL proxy backend
module
- All tests pass and code is formatted with Spotless
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* Add test coverage for missing PostgreSQL backend components
---------
Co-authored-by: Claude <[email protected]>
---
CLAUDE.md | 7 +--
.../PostgreSQLCharsetVariableProviderTest.java | 62 ++++++++++++++++++++++
.../PostgreSQLSelectAdminExecutorFactoryTest.java | 59 ++++++++++++++++++++
3 files changed, 123 insertions(+), 5 deletions(-)
diff --git a/CLAUDE.md b/CLAUDE.md
index cb509ad025e..2ce1988186d 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -56,13 +56,9 @@ Key directories and their purposes:
- `jdbc/`: ShardingSphere-JDBC driver implementation
- `test/`: E2E and IT test engine and cases
-## Development Guidelines
-
-Please follow these guidelines when developing:
https://shardingsphere.apache.org/community/en/involved/contribute/dev-env/
-
## Code Standards and Conventions
-Please follow these guidelines when developing:
https://shardingsphere.apache.org/community/en/involved/conduct/code/
+Please follow these guidelines in file [CODE_OF_CONDUCT.md] when developing
## Absolute Prohibitions (Zero-Tolerance Violations)
@@ -141,3 +137,4 @@ Please follow these guidelines when developing:
https://shardingsphere.apache.or
- Re-read this protocol before starting each new task.
- Verify rule compliance after each user interaction.
- Report violations through clear error messages.
+ - Use Spotless to enforce code style after code generated.
diff --git
a/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharsetVariableProviderTest.java
b/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharsetVariableProviderTest.java
new file mode 100644
index 00000000000..88776622ece
--- /dev/null
+++
b/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/executor/variable/charset/PostgreSQLCharsetVariableProviderTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.proxy.backend.postgresql.handler.admin.executor.variable.charset;
+
+import
org.apache.shardingsphere.database.connector.core.spi.DatabaseTypedSPILoader;
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import
org.apache.shardingsphere.database.exception.core.exception.data.InvalidParameterValueException;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.proxy.backend.handler.admin.executor.variable.charset.CharsetVariableProvider;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class PostgreSQLCharsetVariableProviderTest {
+
+ private final CharsetVariableProvider provider =
DatabaseTypedSPILoader.getService(CharsetVariableProvider.class,
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL"));
+
+ @Test
+ void assertGetCharsetVariables() {
+ Collection<String> variables = provider.getCharsetVariables();
+ assertThat(variables, is(Collections.singleton("client_encoding")));
+ }
+
+ @Test
+ void assertParseDefaultCharset() {
+ Charset actual = provider.parseCharset("default");
+ assertThat(actual, is(Charset.defaultCharset()));
+ }
+
+ @Test
+ void assertParseIndicatedCharset() {
+ Charset actual = provider.parseCharset("utf8");
+ assertThat(actual, is(StandardCharsets.UTF_8));
+ }
+
+ @Test
+ void assertParseInvalidCharset() {
+ assertThrows(InvalidParameterValueException.class, () ->
provider.parseCharset("invalid_charset"));
+ }
+}
diff --git
a/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/factory/PostgreSQLSelectAdminExecutorFactoryTest.java
b/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/factory/PostgreSQLSelectAdminExecutorFactoryTest.java
new file mode 100644
index 00000000000..da6fd6191b5
--- /dev/null
+++
b/proxy/backend/dialect/postgresql/src/test/java/org/apache/shardingsphere/proxy/backend/postgresql/handler/admin/factory/PostgreSQLSelectAdminExecutorFactoryTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.proxy.backend.postgresql.handler.admin.factory;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import org.apache.shardingsphere.parser.rule.SQLParserRule;
+import org.apache.shardingsphere.sql.parser.engine.api.CacheOption;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.dml.SelectStatement;
+import org.junit.jupiter.api.Test;
+
+import java.util.Collections;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class PostgreSQLSelectAdminExecutorFactoryTest {
+
+ @Test
+ void assertNewInstanceWithPgDatabaseSystemTable() {
+ String sql = "SELECT d.datname as
\"Name\",pg_catalog.pg_get_userbyid(d.datdba) as
\"Owner\",pg_catalog.pg_encoding_to_char(d.encoding) as \"Encoding\","
+ + "d.datcollate as \"Collate\",d.datctype as
\"Ctype\",pg_catalog.array_to_string(d.datacl, E'\\n') AS \"Access privileges\"
FROM pg_catalog.pg_database d ORDER BY 1";
+
assertTrue(PostgreSQLSelectAdminExecutorFactory.newInstance(parseSQL(sql), sql,
Collections.emptyList()).isPresent());
+ }
+
+ @Test
+ void assertNewInstanceWithShardingSphereSystemTable() {
+ String sql = "SELECT * FROM shardingsphere.cluster_information";
+
assertFalse(PostgreSQLSelectAdminExecutorFactory.newInstance(parseSQL(sql),
sql, Collections.emptyList()).isPresent());
+ }
+
+ @Test
+ void assertNewInstanceWithSelectLogicSQL() {
+ String sql = "SELECT * FROM foo_tbl";
+
assertFalse(PostgreSQLSelectAdminExecutorFactory.newInstance(parseSQL(sql),
sql, Collections.emptyList()).isPresent());
+ }
+
+ private SelectStatement parseSQL(final String sql) {
+ CacheOption cacheOption = new CacheOption(0, 0L);
+ DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "PostgreSQL");
+ return (SelectStatement) new SQLParserRule(new
SQLParserRuleConfiguration(cacheOption,
cacheOption)).getSQLParserEngine(databaseType).parse(sql, false);
+ }
+}