Skip to content

Commit

Permalink
两个测试用于演示
Browse files Browse the repository at this point in the history
  • Loading branch information
wln32 committed Jan 13, 2025
1 parent bd045de commit acb7a79
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
28 changes: 28 additions & 0 deletions contrib/drivers/mysql/mysql_z_unit_feature_ctx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,31 @@ func Test_Ctx_Model(t *testing.T) {
db.Model(table).All()
})
}

type implScanner struct {
v int
}

func (t *implScanner) Scan(src any) error {
t.v = 10
return nil
}

type testImplSqlScanner struct {
Id implScanner
Passport *implScanner
Password string
}

func Test_CustomConvertFunc(t *testing.T) {
table := createInitTable()
defer dropTable(table)
gtest.C(t, func(t *gtest.T) {
var impl testImplSqlScanner
err := db.Model(table).Scan(&impl)
t.AssertNil(err)
t.Assert(impl.Id, implScanner{v: 10})
t.Assert(impl.Password, "pass_1")
t.Assert(impl.Passport, &implScanner{v: 10})
})
}
32 changes: 32 additions & 0 deletions contrib/drivers/mysql/mysql_z_unit_issue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1590,3 +1590,35 @@ func issue4034SaveAppDevice(ctx context.Context, table string, tx gdb.TX) error
}).Save()
return err
}

func Test_issue4086(t *testing.T) {
type ProxyParam struct {
ProxyId int64 `json:"proxyId" orm:"proxy_id" description:""`
RecommendIds []int64 `json:"recommendIds" orm:"recommend_ids" description:""`
Photos []string `json:"photos" orm:"photos" description:""`
}
gtest.C(t, func(t *gtest.T) {
table := "proxy_param"
array := gstr.SplitAndTrim(gtest.DataContent(`issue4086.sql`), ";")
for _, v := range array {
_, err := db.Exec(ctx, v)
t.AssertNil(err)
}
defer dropTable(table)

var proxyParamList []*ProxyParam
err := db.Model(table).Ctx(context.Background()).Scan(&proxyParamList)
t.AssertNil(err)
t.Assert(len(proxyParamList), 2)
t.Assert(proxyParamList[0], &ProxyParam{
ProxyId: 1,
RecommendIds: []int64{584, 585},
Photos: nil,
})
t.Assert(proxyParamList[1], &ProxyParam{
ProxyId: 2,
RecommendIds: []int64{},
Photos: nil,
})
})
}

0 comments on commit acb7a79

Please sign in to comment.