-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
test(contrib/drivers/mariadb): add infrastructure, core and model tests #4719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gqcn
merged 5 commits into
gogf:master
from
lingcoder:test/mariadb-pr1-infra-core-model
Mar 24, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6d748b8
contrib/drivers/mariadb: add infrastructure, core, basic, and model t…
lingcoder 05b85d4
test(contrib/drivers/mariadb): add nil check before accessing err.Err…
lingcoder a08e252
Apply gci import order changes
github-actions[bot] 4a73593
ci: trigger CI re-run after gci auto-fix
lingcoder 21f9d91
ci: trigger CI re-run after gci auto-fix
lingcoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. | ||
| // | ||
| // This Source Code Form is subject to the terms of the MIT License. | ||
| // If a copy of the MIT was not distributed with this file, | ||
| // You can obtain one at https://github.com/gogf/gf. | ||
|
|
||
| package mariadb_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/gogf/gf/v2/database/gdb" | ||
| "github.com/gogf/gf/v2/test/gtest" | ||
| ) | ||
|
|
||
| func Test_Instance(t *testing.T) { | ||
| gtest.C(t, func(t *gtest.T) { | ||
| _, err := gdb.Instance("none") | ||
| t.AssertNE(err, nil) | ||
|
|
||
| db, err := gdb.Instance() | ||
| t.AssertNil(err) | ||
|
|
||
| err1 := db.PingMaster() | ||
| err2 := db.PingSlave() | ||
| t.Assert(err1, nil) | ||
| t.Assert(err2, nil) | ||
| }) | ||
| } | ||
|
|
||
| func Test_Func_FormatSqlWithArgs(t *testing.T) { | ||
| // mysql | ||
| gtest.C(t, func(t *gtest.T) { | ||
| var s string | ||
| s = gdb.FormatSqlWithArgs("select * from table where id>=? and sex=?", []any{100, 1}) | ||
| t.Assert(s, "select * from table where id>=100 and sex=1") | ||
| }) | ||
| // mssql | ||
| gtest.C(t, func(t *gtest.T) { | ||
| var s string | ||
| s = gdb.FormatSqlWithArgs("select * from table where id>=@p1 and sex=@p2", []any{100, 1}) | ||
| t.Assert(s, "select * from table where id>=100 and sex=1") | ||
| }) | ||
| // pgsql | ||
| gtest.C(t, func(t *gtest.T) { | ||
| var s string | ||
| s = gdb.FormatSqlWithArgs("select * from table where id>=$1 and sex=$2", []any{100, 1}) | ||
| t.Assert(s, "select * from table where id>=100 and sex=1") | ||
| }) | ||
| // oracle | ||
| gtest.C(t, func(t *gtest.T) { | ||
| var s string | ||
| s = gdb.FormatSqlWithArgs("select * from table where id>=:v1 and sex=:v2", []any{100, 1}) | ||
| t.Assert(s, "select * from table where id>=100 and sex=1") | ||
| }) | ||
| } | ||
|
|
||
| func Test_Func_ToSQL(t *testing.T) { | ||
| gtest.C(t, func(t *gtest.T) { | ||
| sql, err := gdb.ToSQL(ctx, func(ctx context.Context) error { | ||
| value, err := db.Ctx(ctx).Model(TableName).Fields("nickname").Where("id", 1).Value() | ||
| t.Assert(value, nil) | ||
| return err | ||
| }) | ||
| t.AssertNil(err) | ||
| t.Assert(sql, "SELECT `nickname` FROM `user` WHERE `id`=1 LIMIT 1") | ||
| }) | ||
| } | ||
|
|
||
| func Test_Func_CatchSQL(t *testing.T) { | ||
| table := createInitTable() | ||
| defer dropTable(table) | ||
| gtest.C(t, func(t *gtest.T) { | ||
| array, err := gdb.CatchSQL(ctx, func(ctx context.Context) error { | ||
| value, err := db.Ctx(ctx).Model(table).Fields("nickname").Where("id", 1).Value() | ||
| t.Assert(value, "name_1") | ||
| return err | ||
| }) | ||
| t.AssertNil(err) | ||
| t.AssertGE(len(array), 1) | ||
| }) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.