重构: User 默认实现移到 req/userx,消除 req 对 contracts 的循环依赖
GetAnonymous/GetSystemUser 原来在 contracts/base 里实现,req 自己的测试 又要用它们构造测试用户,形成 req(测试)依赖 contracts、contracts(正式 代码)依赖 req 的循环——两边 go.mod 只能靠指向本地兄弟目录的 replace 绕过, 没法各自独立解析成真实版本号。 跟 resx 之于 req.Resource 一个思路:接口留在 req 包,默认实现挪到子包 req/userx,req 主包保持不引入实现细节所需的依赖(这里是 samber/lo)。 req 自己的测试文件改用 req/userx,不用触碰 contracts 了;contracts/base 里的 GetAnonymous/GetSystemUser 改成指向 req/userx 的函数别名,保持 兼容不用改调用方。
This commit is contained in:
@@ -3,11 +3,11 @@ package resx_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.fsdpf.net/go/contracts/base"
|
||||
"git.fsdpf.net/go/db"
|
||||
"git.fsdpf.net/go/db/engine"
|
||||
"git.fsdpf.net/go/req"
|
||||
"git.fsdpf.net/go/req/resx"
|
||||
"git.fsdpf.net/go/req/userx"
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/samber/do/v2"
|
||||
"github.com/stretchr/testify/suite"
|
||||
@@ -56,7 +56,7 @@ func (t *resourceTest) TestInsertRows() {
|
||||
result := "INSERT INTO `users` (`created_user`, `fields`, `name`, `owned_user`) " +
|
||||
"VALUES ('00000000-0000-0000-0000-000000000000', '{\\\"aa\\\":1}', '张三', '00000000-0000-0000-0000-000000000000')"
|
||||
|
||||
sql, _, _ := t.res.GetDBTable(base.GetAnonymous()).Insert().Rows(
|
||||
sql, _, _ := t.res.GetDBTable(userx.GetAnonymous()).Insert().Rows(
|
||||
db.Record{"name": "张三", "id": 1, "fields": map[string]any{"aa": 1}},
|
||||
).Executor().ToSQL()
|
||||
t.Equal(result, sql)
|
||||
@@ -64,7 +64,7 @@ func (t *resourceTest) TestInsertRows() {
|
||||
// 注意:db-v2 的 exp.NewRecordFromStruct 传入指针 struct 时会 panic
|
||||
// (util.SafeGetFieldByIndex 未对指针做 reflect.Indirect),此处暂不测试指针形式
|
||||
|
||||
sql, _, _ = t.res.GetDBTable(base.GetAnonymous()).Insert().Rows(
|
||||
sql, _, _ = t.res.GetDBTable(userx.GetAnonymous()).Insert().Rows(
|
||||
Temp{Name: "张三", Fields: map[string]any{"aa": 1}},
|
||||
).Executor().ToSQL()
|
||||
t.Equal(result, sql)
|
||||
@@ -74,7 +74,7 @@ func (t *resourceTest) TestInsertColsVals() {
|
||||
"('李四', '{\\\"aa\\\":1}', '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000'), " +
|
||||
"('王五', '{\\\"aa\\\":3}', '00000000-0000-0000-0000-000000000000', '00000000-0000-0000-0000-000000000000')"
|
||||
|
||||
sql, _, _ := t.res.GetDBTable(base.GetAnonymous()).Insert().Cols("name", "fields").Vals(
|
||||
sql, _, _ := t.res.GetDBTable(userx.GetAnonymous()).Insert().Cols("name", "fields").Vals(
|
||||
db.Vals{"李四", map[string]any{"aa": 1}},
|
||||
db.Vals{"王五", map[string]any{"aa": 3}},
|
||||
).Executor().ToSQL()
|
||||
|
||||
Reference in New Issue
Block a user