Skip to content

test(contrib/drivers/mariadb): add layer 3 features and issue regression tests#4724

Open
lingcoder wants to merge 1 commit intogogf:masterfrom
lingcoder:test/mariadb-pr6-layer3-issues
Open

test(contrib/drivers/mariadb): add layer 3 features and issue regression tests#4724
lingcoder wants to merge 1 commit intogogf:masterfrom
lingcoder:test/mariadb-pr6-layer3-issues

Conversation

@lingcoder
Copy link
Contributor

@lingcoder lingcoder commented Mar 2, 2026

Summary

  • Port 5 feature tests: duplicate-key handling (OnDuplicate/OnDuplicateEx/Save), JSON field operations, row-level locking (Lock/LockUpdate/LockShared with transactions), master-slave configuration, table metadata inspection
  • Port 1 partition test: RANGE partitioning with Partition() clause (adapted from MySQL baseline)
  • Port 30 issue regression tests from MySQL baseline
  • Includes 14 testdata SQL files for issue-specific table schemas

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

@lingcoder lingcoder force-pushed the test/mariadb-pr6-layer3-issues branch from 3b98af0 to 2e9efad Compare March 2, 2026 02:25
- 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)
@lingcoder lingcoder force-pushed the test/mariadb-pr6-layer3-issues branch from 2e9efad to 080e08f Compare March 2, 2026 06:01
@gqcn gqcn requested a review from Copilot March 3, 2026 01:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/*.sql schema 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.

Comment on lines +1 to +7
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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1 to +6
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,
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1 to +9
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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adopted. Pre-placed testdata copy from MySQL baseline. The ORDER BY regression test will be ported in a subsequent PR.

Comment on lines +1 to +9
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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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;

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adopted. Pre-placed testdata copy from MySQL baseline. The date/time scanning test will be ported in a subsequent PR.

Comment on lines +43 to +66
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)

Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@gqcn gqcn changed the title contrib/drivers/mariadb: add layer 3 features and issue regression tests test(contrib/drivers/mariadb): add layer 3 features and issue regression tests Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants