Skip to content

test(contrib/drivers/mariadb): add infrastructure, core and model tests#4719

Open
lingcoder wants to merge 2 commits intogogf:masterfrom
lingcoder:test/mariadb-pr1-infra-core-model
Open

test(contrib/drivers/mariadb): add infrastructure, core and model tests#4719
lingcoder wants to merge 2 commits intogogf:masterfrom
lingcoder:test/mariadb-pr1-infra-core-model

Conversation

@lingcoder
Copy link
Contributor

Summary

  • Add full test infrastructure (mariadb_unit_init_test.go) with MariaDB-specific helpers (createTable, createInitTable, dropTable) matching the MySQL test baseline
  • Port 4 basic tests from MySQL: Test_New, Test_DB_Ping, Test_DB_Query, Test_DB_Exec
  • Port 47 core tests covering CRUD operations, raw SQL, schema switching, and DB/TX method parity
  • Port 55 model tests covering Model API: Fields, Where, Scan, Save, Replace, InsertIgnore, InsertGetId, OmitEmpty, Distinct, Count/Min/Max/Avg/Sum, HasField, chained operations, testdata SQL-based scenarios and more
  • Add 5 testdata SQL files required by model tests (copied from MySQL baseline)

All tests are structurally identical to the MySQL driver baseline. SQL syntax is standard and shared. Package and import references are adapted for MariaDB.

ref #4689

…ests

Align MariaDB test coverage with MySQL baseline (PR 1/6).
- Extend init_test.go with db3, dbPrefix, dbInvalid, partition setup
- Add basic_test.go (instance and connection tests)
- Add core_test.go (core database operation tests)
- Add model_test.go (non-conflicting model tests)

ref gogf#4689
@lingcoder lingcoder force-pushed the test/mariadb-pr1-infra-core-model branch from c048f26 to 65a644b Compare March 2, 2026 07:12
@gqcn gqcn requested a review from Copilot March 3, 2026 01:40
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

Adds a full MariaDB driver test suite under contrib/drivers/mariadb, aligning MariaDB coverage with the existing MySQL driver baseline as part of the broader driver test-coverage initiative (#4689).

Changes:

  • Added MariaDB unit test infrastructure and helpers (DB setup, schemas, table helpers).
  • Ported core driver tests (CRUD, raw SQL, schema switching, DB/TX parity, etc.).
  • Ported extensive Model API tests and added required testdata/ SQL fixtures.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
contrib/drivers/mariadb/mariadb_unit_init_test.go Test initialization/config, schemas, table helpers, and partition test setup.
contrib/drivers/mariadb/mariadb_z_unit_basic_test.go Basic DB instance and SQL capture/toSQL tests.
contrib/drivers/mariadb/mariadb_z_unit_core_test.go Core DB/ORM behavior tests (CRUD, types, ctx, joins, cache clearing, etc.).
contrib/drivers/mariadb/mariadb_z_unit_model_test.go Large suite of Model API behavior tests and SQL expectation checks.
contrib/drivers/mariadb/testdata/reservedwords_table_tpl.sql Fixture for reserved-word column/table handling.
contrib/drivers/mariadb/testdata/fix_gdb_order_by.sql Fixture for ORDER BY SQL generation regression test.
contrib/drivers/mariadb/testdata/fix_gdb_join.sql Fixture for join SQL generation regression test.
contrib/drivers/mariadb/testdata/fix_gdb_join_expect.sql Expected SQL output for the join regression test.
contrib/drivers/mariadb/testdata/date_time_example.sql Fixture for date/time type round-trip tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1569 to +1574
gtest.C(t, func(t *gtest.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_, err := db.Query(ctx, "SELECT SLEEP(10)")
t.Assert(gstr.Contains(err.Error(), "deadline"), true)
})
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.

err.Error() is called without first asserting err != nil. If the query unexpectedly completes before the context deadline (or returns a nil error for any reason), this will panic and hide the real test failure. Assert err is non-nil before inspecting the message (or assert on errors.Is(err, context.DeadlineExceeded) where applicable).

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.

不采纳吧。与 MySQL 基线完全一致。这个测试用 1 秒超时执行 SLEEP(10),err 必然非 nil。改了反而跟基线不一致吧。 mysql基线该处修改是2021年,一直很稳定
@gqcn

Copy link
Contributor Author

Choose a reason for hiding this comment

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

改也行,改了吧。加行代码的事情

Copy link
Contributor Author

@lingcoder lingcoder Mar 3, 2026

Choose a reason for hiding this comment

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

改了,重推了。把mysql testcase参考处也加了nil断言,省的后面又参考到了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adopted. Added t.AssertNE(err, nil) before err.Error() in both MySQL and MariaDB.

createShopDBTable()
insertShopDBData()

// defer dropShopDBTable()
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.

dbx_order is created and populated, but the cleanup defer is commented out. This can leave state behind in the test database if the suite is interrupted and makes local/dev environments harder to keep clean. Consider re-enabling defer dropShopDBTable() (or use a unique table name per run).

Suggested change
// defer dropShopDBTable()
defer dropShopDBTable()

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.

不采纳。与 MySQL 基线完全一致

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. Matches MySQL baseline exactly (mysql_z_unit_init_test.go:181). Intentionally kept commented out — partition table may be needed by subsequent tests.

Comment on lines 46 to +58
nodeDefault := gdb.ConfigNode{
ExecTimeout: time.Second * 2,
Link: fmt.Sprintf("mariadb:root:%s@tcp(127.0.0.1:3307)/?loc=Local&parseTime=true", TestDbPass),
TranTimeout: time.Second * 3,
}
err := gdb.AddConfigNode(gdb.DefaultGroupName, nodeDefault)
if err != nil {
panic(err)
partitionDefault := gdb.ConfigNode{
Link: fmt.Sprintf("mariadb:root:%s@tcp(127.0.0.1:3307)/?loc=Local&parseTime=true", TestDbPass),
Debug: true,
TranTimeout: time.Second * 3,
}
nodePrefix := gdb.ConfigNode{
Link: fmt.Sprintf("mariadb:root:%s@tcp(127.0.0.1:3307)/?loc=Local&parseTime=true", TestDbPass),
TranTimeout: time.Second * 3,
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.

The DSNs in init() hardcode root even though TestDbUser exists and is used elsewhere (e.g. Test_New). To avoid config drift if the test user changes, consider formatting these DSNs using TestDbUser too.

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.

不采纳。与 MySQL 基线完全一致。TestDbUser 用在需要额外连接的场景,init 里的 DSN 是标准配置,所有驱动都用 root。

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. Matches MySQL baseline exactly (mysql_z_unit_init_test.go:46,50,55,61 all hardcode root). This is the standard pattern across all driver init files.

@gqcn gqcn changed the title contrib/drivers/mariadb: add infrastructure, core and model tests test(contrib/drivers/mariadb): add infrastructure, core and model tests Mar 3, 2026
@lingcoder lingcoder force-pushed the test/mariadb-pr1-infra-core-model branch from b2176a8 to 367d75a Compare March 3, 2026 08:10
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