test(contrib/drivers/mariadb): add layer 3 features and issue regression tests#4724
test(contrib/drivers/mariadb): add layer 3 features and issue regression tests#4724lingcoder wants to merge 1 commit intogogf:masterfrom
Conversation
3b98af0 to
2e9efad
Compare
- Port feature tests: duplicate-key handling, JSON fields, row-level locking, master-slave config, table metadata, RANGE partition - Port 30 issue regression tests from MySQL baseline - Include 14 testdata SQL files for issue-specific table schemas - Adapt MariaDB-specific behavior (LOCK IN SHARE MODE, SKIP LOCKED requires 10.6+, mariadb driver name and port in link parsing test)
2e9efad to
080e08f
Compare
There was a problem hiding this comment.
Pull request overview
This PR expands the MariaDB driver’s test suite to align more closely with the MySQL baseline, adding Layer 3 feature tests, a partitioning test suite, and a large set of issue regression tests (plus accompanying SQL fixtures).
Changes:
- Added extensive MariaDB issue regression tests (ported from MySQL baseline) and corresponding
testdata/issues/*.sqlschema fixtures. - Added Layer 3 feature tests covering JSON, locking, master/slave routing, metadata inspection, partitioning, and duplicate-key behavior.
- Updated MariaDB test initialization to add a dedicated schema (
test3) for partition-related tests.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| contrib/drivers/mariadb/mariadb_unit_init_test.go | Adds test3 schema + db3 for partition tests. |
| contrib/drivers/mariadb/mariadb_z_unit_issue_test.go | Ports a large set of MySQL issue regression tests to MariaDB. |
| contrib/drivers/mariadb/mariadb_z_unit_feature_partition_test.go | Adds MariaDB partitioning tests (with skips where builder support is missing). |
| contrib/drivers/mariadb/mariadb_z_unit_feature_metadata_test.go | Adds TableFields/HasField/QuoteWord coverage. |
| contrib/drivers/mariadb/mariadb_z_unit_feature_master_slave_test.go | Adds master/slave routing tests. |
| contrib/drivers/mariadb/mariadb_z_unit_feature_lock_test.go | Adds lock-related tests including transaction scenarios. |
| contrib/drivers/mariadb/mariadb_z_unit_feature_json_test.go | Adds JSON insert/update/query/scan tests. |
| contrib/drivers/mariadb/mariadb_z_unit_feature_duplicate_test.go | Adds duplicate-key tests (currently via raw SQL). |
| contrib/drivers/mariadb/testdata/* | Adds SQL fixtures for issues and other feature tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| CREATE TABLE `instance` ( | ||
| `f_id` int(11) NOT NULL AUTO_INCREMENT, | ||
| `name` varchar(255) NULL DEFAULT '', | ||
| PRIMARY KEY (`f_id`) USING BTREE | ||
| ) ENGINE = InnoDB; | ||
|
|
||
| INSERT INTO `instance` VALUES (1, 'john'); No newline at end of file |
There was a problem hiding this comment.
This SQL testdata file isn't referenced by any tests in contrib/drivers/mariadb (no gtest.DataContent("table_with_prefix.sql") usage). If there isn't a MariaDB test that loads it (like MySQL's Test_Model_Where_FieldPrefix), consider removing it to avoid unused test fixtures, or port the corresponding test that consumes it.
| CREATE TABLE `instance` ( | |
| `f_id` int(11) NOT NULL AUTO_INCREMENT, | |
| `name` varchar(255) NULL DEFAULT '', | |
| PRIMARY KEY (`f_id`) USING BTREE | |
| ) ENGINE = InnoDB; | |
| INSERT INTO `instance` VALUES (1, 'john'); | |
| -- Intentionally left blank: unused MariaDB testdata previously removed. |
There was a problem hiding this comment.
Not adopted. These testdata SQL files are pre-placed copies from the MySQL baseline (project convention requires each driver to have its own independent testdata copy). The corresponding tests that consume these files (model_test, do_test) will be ported in subsequent PRs.
| CREATE TABLE %s ( | ||
| `id` int(10) unsigned NOT NULL AUTO_INCREMENT, | ||
| `key` varchar(45) DEFAULT NULL, | ||
| `category_id` int(10) unsigned NOT NULL, | ||
| `user_id` int(10) unsigned NOT NULL, | ||
| `title` varchar(255) NOT NULL, |
There was a problem hiding this comment.
This template SQL file doesn't appear to be used by any MariaDB tests (no references to reservedwords_table_tpl.sql/gtest.DataPath(...) under contrib/drivers/mariadb). If the corresponding reserved-words/FieldsEx test wasn't ported yet, consider either porting it or removing this fixture to keep the MariaDB testdata directory minimal and self-contained.
There was a problem hiding this comment.
Not adopted. Same as above — this is a pre-placed testdata copy from MySQL baseline. The corresponding reserved-words/FieldsEx tests will be ported in a subsequent model_test PR.
| CREATE TABLE IF NOT EXISTS `employee` | ||
| ( | ||
| id BIGINT AUTO_INCREMENT PRIMARY KEY, | ||
| name VARCHAR(255) NOT NULL, | ||
| age INT NOT NULL | ||
| ); | ||
|
|
||
| INSERT INTO employee(name, age) VALUES ('John', 30); | ||
| INSERT INTO employee(name, age) VALUES ('Mary', 28); No newline at end of file |
There was a problem hiding this comment.
This fixture SQL file isn't referenced by any MariaDB tests (no gtest.DataContent("fix_gdb_order_by.sql") usage under contrib/drivers/mariadb). If the related ORDER BY regression test wasn't ported, consider porting it; otherwise remove the unused fixture to reduce maintenance overhead.
| CREATE TABLE IF NOT EXISTS `employee` | |
| ( | |
| id BIGINT AUTO_INCREMENT PRIMARY KEY, | |
| name VARCHAR(255) NOT NULL, | |
| age INT NOT NULL | |
| ); | |
| INSERT INTO employee(name, age) VALUES ('John', 30); | |
| INSERT INTO employee(name, age) VALUES ('Mary', 28); |
There was a problem hiding this comment.
Not adopted. Pre-placed testdata copy from MySQL baseline. The ORDER BY regression test will be ported in a subsequent PR.
| CREATE TABLE `date_time_example` ( | ||
| `id` int unsigned NOT NULL AUTO_INCREMENT, | ||
| `year` year DEFAULT NULL COMMENT 'year', | ||
| `date` date DEFAULT NULL COMMENT 'Date', | ||
| `time` time DEFAULT NULL COMMENT 'time', | ||
| `datetime` datetime DEFAULT NULL COMMENT 'datetime', | ||
| `timestamp` timestamp NULL DEFAULT NULL COMMENT 'Timestamp', | ||
| PRIMARY KEY (`id`) | ||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; No newline at end of file |
There was a problem hiding this comment.
This fixture SQL file isn't referenced by any MariaDB tests (no gtest.DataContent("date_time_example.sql") usage under contrib/drivers/mariadb). If the driver is expected to cover year/date/time/datetime/timestamp scanning like the MySQL baseline, consider porting that test; otherwise remove this unused fixture.
| CREATE TABLE `date_time_example` ( | |
| `id` int unsigned NOT NULL AUTO_INCREMENT, | |
| `year` year DEFAULT NULL COMMENT 'year', | |
| `date` date DEFAULT NULL COMMENT 'Date', | |
| `time` time DEFAULT NULL COMMENT 'time', | |
| `datetime` datetime DEFAULT NULL COMMENT 'datetime', | |
| `timestamp` timestamp NULL DEFAULT NULL COMMENT 'Timestamp', | |
| PRIMARY KEY (`id`) | |
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; |
There was a problem hiding this comment.
Not adopted. Pre-placed testdata copy from MySQL baseline. The date/time scanning test will be ported in a subsequent PR.
| func Test_OnDuplicateKeyUpdate_Basic(t *testing.T) { | ||
| table := createDuplicateTable() | ||
| defer dropTable(table) | ||
|
|
||
| gtest.C(t, func(t *gtest.T) { | ||
| // First insert | ||
| _, err := db.Exec(ctx, fmt.Sprintf( | ||
| "INSERT INTO %s (email, username, score) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE username = VALUES(username), score = VALUES(score)", | ||
| table, | ||
| ), "user1@example.com", "user1", 100) | ||
| t.AssertNil(err) | ||
|
|
||
| one, err := db.Model(table).Where("email", "user1@example.com").One() | ||
| t.AssertNil(err) | ||
| t.Assert(one["username"], "user1") | ||
| t.Assert(one["score"], 100) | ||
|
|
||
| // Duplicate insert - should update | ||
| _, err = db.Exec(ctx, fmt.Sprintf( | ||
| "INSERT INTO %s (email, username, score) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE username = VALUES(username), score = VALUES(score)", | ||
| table, | ||
| ), "user1@example.com", "user1_updated", 200) | ||
| t.AssertNil(err) | ||
|
|
There was a problem hiding this comment.
These tests validate MariaDB's native ON DUPLICATE KEY UPDATE behavior via db.Exec, but they don't exercise GoFrame's ORM APIs (Model.OnDuplicate, OnDuplicateEx, Save) that the PR description calls out. As a result, regressions in the MariaDB SQL builder/driver adapter for upsert semantics could go undetected. Consider adding coverage similar to MySQL's Test_Model_OnDuplicate/Test_Model_OnDuplicateEx (using db.Model(table).OnDuplicate(...).Data(...).Save() and asserting the updated columns).
There was a problem hiding this comment.
Not adopted. This PR focuses on Layer 3 (MariaDB-specific) validation of raw ON DUPLICATE KEY UPDATE SQL behavior. ORM-level tests (Model.OnDuplicate, OnDuplicateEx, Save) already exist in the older mariadb_unit_model_test.go for Save(), and the full OnDuplicate/OnDuplicateEx coverage will be ported from MySQL baseline in a subsequent model_test PR.
Summary
Layer 3 tests cover MariaDB-specific adaptations where needed (e.g., SKIP LOCKED requires MariaDB 10.6+ — commented out for compatibility, LOCK IN SHARE MODE instead of FOR SHARE for older versions).
All tests are structurally aligned with the MySQL driver baseline. Package and import references are adapted for MariaDB.
ref #4689