test(contrib/drivers/mariadb): add infrastructure, core and model tests#4719
test(contrib/drivers/mariadb): add infrastructure, core and model tests#4719lingcoder wants to merge 2 commits intogogf:masterfrom
Conversation
…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
c048f26 to
65a644b
Compare
There was a problem hiding this comment.
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.
| 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) | ||
| }) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
不采纳吧。与 MySQL 基线完全一致。这个测试用 1 秒超时执行 SLEEP(10),err 必然非 nil。改了反而跟基线不一致吧。 mysql基线该处修改是2021年,一直很稳定
@gqcn
There was a problem hiding this comment.
改了,重推了。把mysql testcase参考处也加了nil断言,省的后面又参考到了
There was a problem hiding this comment.
Adopted. Added t.AssertNE(err, nil) before err.Error() in both MySQL and MariaDB.
| createShopDBTable() | ||
| insertShopDBData() | ||
|
|
||
| // defer dropShopDBTable() |
There was a problem hiding this comment.
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).
| // defer dropShopDBTable() | |
| defer dropShopDBTable() |
There was a problem hiding this comment.
不采纳。与 MySQL 基线完全一致
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
不采纳。与 MySQL 基线完全一致。TestDbUser 用在需要额外连接的场景,init 里的 DSN 是标准配置,所有驱动都用 root。
There was a problem hiding this comment.
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.
…or() in Test_DB_Ctx
b2176a8 to
367d75a
Compare
Summary
mariadb_unit_init_test.go) with MariaDB-specific helpers (createTable, createInitTable, dropTable) matching the MySQL test baselineTest_New,Test_DB_Ping,Test_DB_Query,Test_DB_ExecAll 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