|
@@ -3,7 +3,6 @@ package dept
|
|
|
import (
|
|
import (
|
|
|
"context"
|
|
"context"
|
|
|
"errors"
|
|
"errors"
|
|
|
- "math"
|
|
|
|
|
"testing"
|
|
"testing"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
@@ -14,7 +13,7 @@ import (
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-// TC-0310: 正常插入
|
|
|
|
|
|
|
+// TC-0310: 正常 CRUD
|
|
|
func TestSysDeptModel_CRUD(t *testing.T) {
|
|
func TestSysDeptModel_CRUD(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -60,7 +59,7 @@ func TestSysDeptModel_CRUD(t *testing.T) {
|
|
|
assert.True(t, errors.Is(err, ErrNotFound))
|
|
assert.True(t, errors.Is(err, ErrNotFound))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0442: 正常查询
|
|
|
|
|
|
|
+// TC-0442: FindAll 排序 sort asc, id asc
|
|
|
func TestSysDeptModel_FindAll_OrderBySortAscIdAsc(t *testing.T) {
|
|
func TestSysDeptModel_FindAll_OrderBySortAscIdAsc(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -69,30 +68,27 @@ func TestSysDeptModel_FindAll_OrderBySortAscIdAsc(t *testing.T) {
|
|
|
base := testutil.UniqueId()
|
|
base := testutil.UniqueId()
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
rows := []*SysDept{
|
|
rows := []*SysDept{
|
|
|
- {ParentId: 0, Name: "a_" + base, Path: "/fa/" + base + "/a/", Sort: 30, Remark: "", Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
- {ParentId: 0, Name: "b_" + base, Path: "/fa/" + base + "/b/", Sort: 10, Remark: "", Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
- {ParentId: 0, Name: "c_" + base, Path: "/fa/" + base + "/c/", Sort: 20, Remark: "", Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
|
|
+ {ParentId: 0, Name: "a_" + base, Path: "/fa/" + base + "/a/", Sort: 30, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
+ {ParentId: 0, Name: "b_" + base, Path: "/fa/" + base + "/b/", Sort: 10, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
+ {ParentId: 0, Name: "c_" + base, Path: "/fa/" + base + "/c/", Sort: 20, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
}
|
|
}
|
|
|
require.NoError(t, m.BatchInsert(ctx, rows))
|
|
require.NoError(t, m.BatchInsert(ctx, rows))
|
|
|
|
|
|
|
|
- prefix := "/fa/" + base
|
|
|
|
|
- byPath, err := m.FindByPathPrefix(ctx, prefix)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- require.Len(t, byPath, 3)
|
|
|
|
|
- ids := []int64{byPath[0].Id, byPath[1].Id, byPath[2].Id}
|
|
|
|
|
- tbl := m.TableName()
|
|
|
|
|
- t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, ids...) })
|
|
|
|
|
-
|
|
|
|
|
all, err := m.FindAll(ctx)
|
|
all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
- idSet := map[int64]struct{}{ids[0]: {}, ids[1]: {}, ids[2]: {}}
|
|
|
|
|
|
|
+ nameSet := map[string]struct{}{rows[0].Name: {}, rows[1].Name: {}, rows[2].Name: {}}
|
|
|
var picked []*SysDept
|
|
var picked []*SysDept
|
|
|
|
|
+ var ids []int64
|
|
|
for i := range all {
|
|
for i := range all {
|
|
|
- if _, ok := idSet[all[i].Id]; ok {
|
|
|
|
|
|
|
+ if _, ok := nameSet[all[i].Name]; ok {
|
|
|
picked = append(picked, all[i])
|
|
picked = append(picked, all[i])
|
|
|
|
|
+ ids = append(ids, all[i].Id)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ tbl := m.TableName()
|
|
|
|
|
+ t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, ids...) })
|
|
|
|
|
+
|
|
|
require.Len(t, picked, 3)
|
|
require.Len(t, picked, 3)
|
|
|
for i := 1; i < len(picked); i++ {
|
|
for i := 1; i < len(picked); i++ {
|
|
|
prev, cur := picked[i-1], picked[i]
|
|
prev, cur := picked[i-1], picked[i]
|
|
@@ -107,90 +103,7 @@ func TestSysDeptModel_FindAll_OrderBySortAscIdAsc(t *testing.T) {
|
|
|
assert.Equal(t, int64(30), picked[2].Sort)
|
|
assert.Equal(t, int64(30), picked[2].Sort)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0444: 正常查询
|
|
|
|
|
-func TestSysDeptModel_FindByParentId_FoundAndNotFound(t *testing.T) {
|
|
|
|
|
- ctx := context.Background()
|
|
|
|
|
- conn := testutil.GetTestSqlConn()
|
|
|
|
|
- m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
-
|
|
|
|
|
- now := time.Now().Unix()
|
|
|
|
|
- parent := &SysDept{
|
|
|
|
|
- ParentId: 0,
|
|
|
|
|
- Name: "p_" + testutil.UniqueId(),
|
|
|
|
|
- Path: "/fp/" + testutil.UniqueId() + "/",
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Remark: "",
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
- }
|
|
|
|
|
- res, err := m.Insert(ctx, parent)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- pid, err := res.LastInsertId()
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
-
|
|
|
|
|
- child := &SysDept{
|
|
|
|
|
- ParentId: pid,
|
|
|
|
|
- Name: "c_" + testutil.UniqueId(),
|
|
|
|
|
- Path: parent.Path + "sub/",
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Remark: "",
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
- }
|
|
|
|
|
- cres, err := m.Insert(ctx, child)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- cid, err := cres.LastInsertId()
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- tbl := m.TableName()
|
|
|
|
|
- t.Cleanup(func() {
|
|
|
|
|
- testutil.CleanTable(ctx, conn, tbl, cid, pid)
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
- list, err := m.FindByParentId(ctx, pid)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- require.Len(t, list, 1)
|
|
|
|
|
- assert.Equal(t, cid, list[0].Id)
|
|
|
|
|
-
|
|
|
|
|
- empty, err := m.FindByParentId(ctx, math.MaxInt64)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- assert.Len(t, empty, 0)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// TC-0446: 正常查询
|
|
|
|
|
-func TestSysDeptModel_FindByPathPrefix_LikePrefix(t *testing.T) {
|
|
|
|
|
- ctx := context.Background()
|
|
|
|
|
- conn := testutil.GetTestSqlConn()
|
|
|
|
|
- m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
-
|
|
|
|
|
- now := time.Now().Unix()
|
|
|
|
|
- pfx := "/pfx/" + testutil.UniqueId()
|
|
|
|
|
- d1 := &SysDept{ParentId: 0, Name: "n1_" + testutil.UniqueId(), Path: pfx + "/a/", Sort: 1, Remark: "", Status: 1, CreateTime: now, UpdateTime: now}
|
|
|
|
|
- d2 := &SysDept{ParentId: 0, Name: "n2_" + testutil.UniqueId(), Path: pfx + "/b/", Sort: 2, Remark: "", Status: 1, CreateTime: now, UpdateTime: now}
|
|
|
|
|
- other := &SysDept{ParentId: 0, Name: "o_" + testutil.UniqueId(), Path: "/other/" + testutil.UniqueId() + "/", Sort: 1, Remark: "", Status: 1, CreateTime: now, UpdateTime: now}
|
|
|
|
|
-
|
|
|
|
|
- r1, err := m.Insert(ctx, d1)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- id1, _ := r1.LastInsertId()
|
|
|
|
|
- r2, err := m.Insert(ctx, d2)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- id2, _ := r2.LastInsertId()
|
|
|
|
|
- r3, err := m.Insert(ctx, other)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- id3, _ := r3.LastInsertId()
|
|
|
|
|
- tbl := m.TableName()
|
|
|
|
|
- t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, id1, id2, id3) })
|
|
|
|
|
-
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, pfx)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- require.Len(t, list, 2)
|
|
|
|
|
- names := map[string]struct{}{list[0].Name: {}, list[1].Name: {}}
|
|
|
|
|
- assert.Contains(t, names, d1.Name)
|
|
|
|
|
- assert.Contains(t, names, d2.Name)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// TC-0336: 多条记录(3条)
|
|
|
|
|
|
|
+// TC-0336: 批量 Insert/Delete
|
|
|
func TestSysDeptModel_BatchInsert_BatchDelete(t *testing.T) {
|
|
func TestSysDeptModel_BatchInsert_BatchDelete(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -199,15 +112,21 @@ func TestSysDeptModel_BatchInsert_BatchDelete(t *testing.T) {
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
tag := testutil.UniqueId()
|
|
tag := testutil.UniqueId()
|
|
|
batch := []*SysDept{
|
|
batch := []*SysDept{
|
|
|
- {ParentId: 0, Name: "b1_" + tag, Path: "/bi/" + tag + "/1/", Sort: 1, Remark: "", Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
- {ParentId: 0, Name: "b2_" + tag, Path: "/bi/" + tag + "/2/", Sort: 2, Remark: "", Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
|
|
+ {ParentId: 0, Name: "b1_" + tag, Path: "/bi/" + tag + "/1/", Sort: 1, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
+ {ParentId: 0, Name: "b2_" + tag, Path: "/bi/" + tag + "/2/", Sort: 2, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
}
|
|
}
|
|
|
require.NoError(t, m.BatchInsert(ctx, batch))
|
|
require.NoError(t, m.BatchInsert(ctx, batch))
|
|
|
|
|
|
|
|
- got, err := m.FindByPathPrefix(ctx, "/bi/"+tag)
|
|
|
|
|
|
|
+ all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
- require.Len(t, got, 2)
|
|
|
|
|
- ids := []int64{got[0].Id, got[1].Id}
|
|
|
|
|
|
|
+ wanted := map[string]struct{}{batch[0].Name: {}, batch[1].Name: {}}
|
|
|
|
|
+ var ids []int64
|
|
|
|
|
+ for _, row := range all {
|
|
|
|
|
+ if _, ok := wanted[row.Name]; ok {
|
|
|
|
|
+ ids = append(ids, row.Id)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ require.Len(t, ids, 2)
|
|
|
tbl := m.TableName()
|
|
tbl := m.TableName()
|
|
|
t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, ids...) })
|
|
t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, ids...) })
|
|
|
|
|
|
|
@@ -219,7 +138,7 @@ func TestSysDeptModel_BatchInsert_BatchDelete(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0327: 事务内更新
|
|
|
|
|
|
|
+// TC-0327: 事务内 Insert/Update
|
|
|
func TestSysDeptModel_TransactCtx_InsertWithTx_UpdateWithTx(t *testing.T) {
|
|
func TestSysDeptModel_TransactCtx_InsertWithTx_UpdateWithTx(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -227,14 +146,10 @@ func TestSysDeptModel_TransactCtx_InsertWithTx_UpdateWithTx(t *testing.T) {
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
d := &SysDept{
|
|
d := &SysDept{
|
|
|
- ParentId: 0,
|
|
|
|
|
- Name: "tx_" + testutil.UniqueId(),
|
|
|
|
|
- Path: "/tx/" + testutil.UniqueId() + "/",
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Remark: "before",
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
|
|
+ ParentId: 0, Name: "tx_" + testutil.UniqueId(),
|
|
|
|
|
+ Path: "/tx/" + testutil.UniqueId() + "/",
|
|
|
|
|
+ Sort: 1, Remark: "before", Status: 1,
|
|
|
|
|
+ CreateTime: now, UpdateTime: now,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
var finalId int64
|
|
var finalId int64
|
|
@@ -262,14 +177,14 @@ func TestSysDeptModel_TransactCtx_InsertWithTx_UpdateWithTx(t *testing.T) {
|
|
|
assert.Equal(t, "after_tx", out.Remark)
|
|
assert.Equal(t, "after_tx", out.Remark)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0333: 获取表名
|
|
|
|
|
|
|
+// TC-0333: 表名
|
|
|
func TestSysDeptModel_TableName(t *testing.T) {
|
|
func TestSysDeptModel_TableName(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
assert.Equal(t, "`sys_dept`", m.TableName())
|
|
assert.Equal(t, "`sys_dept`", m.TableName())
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0319: 记录不存在
|
|
|
|
|
|
|
+// TC-0319: FindOne 不存在
|
|
|
func TestSysDeptModel_FindOne_NotFound(t *testing.T) {
|
|
func TestSysDeptModel_FindOne_NotFound(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -277,7 +192,7 @@ func TestSysDeptModel_FindOne_NotFound(t *testing.T) {
|
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0326: 记录不存在
|
|
|
|
|
|
|
+// TC-0326: Update 不存在行不报错
|
|
|
func TestSysDeptModel_Update_NonExistentRow_NoError(t *testing.T) {
|
|
func TestSysDeptModel_Update_NonExistentRow_NoError(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -288,7 +203,7 @@ func TestSysDeptModel_Update_NonExistentRow_NoError(t *testing.T) {
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0329: 记录不存在
|
|
|
|
|
|
|
+// TC-0329: Delete 不存在行不报错
|
|
|
func TestSysDeptModel_Delete_NonExistentRow_NoError(t *testing.T) {
|
|
func TestSysDeptModel_Delete_NonExistentRow_NoError(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -296,7 +211,7 @@ func TestSysDeptModel_Delete_NonExistentRow_NoError(t *testing.T) {
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0334: 空列表
|
|
|
|
|
|
|
+// TC-0334: BatchInsert 空
|
|
|
func TestSysDeptModel_BatchInsert_Empty(t *testing.T) {
|
|
func TestSysDeptModel_BatchInsert_Empty(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -304,7 +219,7 @@ func TestSysDeptModel_BatchInsert_Empty(t *testing.T) {
|
|
|
require.NoError(t, m.BatchInsert(context.Background(), []*SysDept{}))
|
|
require.NoError(t, m.BatchInsert(context.Background(), []*SysDept{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0353: 空ids
|
|
|
|
|
|
|
+// TC-0353: BatchDelete 空
|
|
|
func TestSysDeptModel_BatchDelete_Empty(t *testing.T) {
|
|
func TestSysDeptModel_BatchDelete_Empty(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -312,31 +227,17 @@ func TestSysDeptModel_BatchDelete_Empty(t *testing.T) {
|
|
|
require.NoError(t, m.BatchDelete(context.Background(), []int64{}))
|
|
require.NoError(t, m.BatchDelete(context.Background(), []int64{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0448: 无匹配
|
|
|
|
|
-func TestSysDeptModel_FindByPathPrefix_NoMatch(t *testing.T) {
|
|
|
|
|
- conn := testutil.GetTestSqlConn()
|
|
|
|
|
- m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
- list, err := m.FindByPathPrefix(context.Background(), "/notexist_"+testutil.UniqueId())
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- assert.Empty(t, list)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// TC-0316: 事务回滚后无数据
|
|
|
|
|
|
|
+// TC-0316: 事务回滚无数据
|
|
|
func TestSysDeptModel_InsertWithTx_Rollback(t *testing.T) {
|
|
func TestSysDeptModel_InsertWithTx_Rollback(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
- path := "/txrb/" + testutil.UniqueId() + "/"
|
|
|
|
|
|
|
+ uniq := "txrb_" + testutil.UniqueId()
|
|
|
d := &SysDept{
|
|
d := &SysDept{
|
|
|
- ParentId: 0,
|
|
|
|
|
- Name: "txrb_" + testutil.UniqueId(),
|
|
|
|
|
- Path: path,
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
|
|
+ ParentId: 0, Name: uniq, Path: "/" + uniq + "/",
|
|
|
|
|
+ Sort: 1, Status: 1, CreateTime: now, UpdateTime: now,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
err := m.TransactCtx(ctx, func(c context.Context, s sqlx.Session) error {
|
|
err := m.TransactCtx(ctx, func(c context.Context, s sqlx.Session) error {
|
|
@@ -347,9 +248,11 @@ func TestSysDeptModel_InsertWithTx_Rollback(t *testing.T) {
|
|
|
})
|
|
})
|
|
|
require.Error(t, err)
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, path)
|
|
|
|
|
|
|
+ all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
- assert.Empty(t, list)
|
|
|
|
|
|
|
+ for _, row := range all {
|
|
|
|
|
+ assert.NotEqual(t, uniq, row.Name)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TC-0330: 事务内删除
|
|
// TC-0330: 事务内删除
|
|
@@ -360,13 +263,9 @@ func TestSysDeptModel_DeleteWithTx(t *testing.T) {
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
d := &SysDept{
|
|
d := &SysDept{
|
|
|
- ParentId: 0,
|
|
|
|
|
- Name: "deltx_" + testutil.UniqueId(),
|
|
|
|
|
- Path: "/deltx/" + testutil.UniqueId() + "/",
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
|
|
+ ParentId: 0, Name: "deltx_" + testutil.UniqueId(),
|
|
|
|
|
+ Path: "/deltx/" + testutil.UniqueId() + "/",
|
|
|
|
|
+ Sort: 1, Status: 1, CreateTime: now, UpdateTime: now,
|
|
|
}
|
|
}
|
|
|
res, err := m.Insert(ctx, d)
|
|
res, err := m.Insert(ctx, d)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
@@ -383,22 +282,17 @@ func TestSysDeptModel_DeleteWithTx(t *testing.T) {
|
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0332: fn返回错误
|
|
|
|
|
|
|
+// TC-0332: TransactCtx fn 返回错误时回滚
|
|
|
func TestSysDeptModel_TransactCtx_Rollback(t *testing.T) {
|
|
func TestSysDeptModel_TransactCtx_Rollback(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
- path := "/txrb2/" + testutil.UniqueId() + "/"
|
|
|
|
|
|
|
+ uniq := "txrb2_" + testutil.UniqueId()
|
|
|
d := &SysDept{
|
|
d := &SysDept{
|
|
|
- ParentId: 0,
|
|
|
|
|
- Name: "txrb2_" + testutil.UniqueId(),
|
|
|
|
|
- Path: path,
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
|
|
+ ParentId: 0, Name: uniq, Path: "/" + uniq + "/",
|
|
|
|
|
+ Sort: 1, Status: 1, CreateTime: now, UpdateTime: now,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
err := m.TransactCtx(ctx, func(c context.Context, s sqlx.Session) error {
|
|
err := m.TransactCtx(ctx, func(c context.Context, s sqlx.Session) error {
|
|
@@ -410,12 +304,14 @@ func TestSysDeptModel_TransactCtx_Rollback(t *testing.T) {
|
|
|
require.Error(t, err)
|
|
require.Error(t, err)
|
|
|
require.Contains(t, err.Error(), "force rollback")
|
|
require.Contains(t, err.Error(), "force rollback")
|
|
|
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, path)
|
|
|
|
|
|
|
+ all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
- assert.Empty(t, list)
|
|
|
|
|
|
|
+ for _, row := range all {
|
|
|
|
|
+ assert.NotEqual(t, uniq, row.Name)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0343: 空列表
|
|
|
|
|
|
|
+// TC-0343: BatchUpdate 空
|
|
|
func TestSysDeptModel_BatchUpdate_Empty(t *testing.T) {
|
|
func TestSysDeptModel_BatchUpdate_Empty(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -423,7 +319,7 @@ func TestSysDeptModel_BatchUpdate_Empty(t *testing.T) {
|
|
|
require.NoError(t, m.BatchUpdate(context.Background(), []*SysDept{}))
|
|
require.NoError(t, m.BatchUpdate(context.Background(), []*SysDept{}))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0345: 多条记录(3条)
|
|
|
|
|
|
|
+// TC-0345: BatchUpdate 多条
|
|
|
func TestSysDeptModel_BatchUpdate_Multi(t *testing.T) {
|
|
func TestSysDeptModel_BatchUpdate_Multi(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -461,27 +357,32 @@ func TestSysDeptModel_BatchUpdate_Multi(t *testing.T) {
|
|
|
assert.Equal(t, int64(2), g2.Status)
|
|
assert.Equal(t, int64(2), g2.Status)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0335: 单条记录
|
|
|
|
|
|
|
+// TC-0335: BatchInsert 单条
|
|
|
func TestSysDeptModel_BatchInsert_Single(t *testing.T) {
|
|
func TestSysDeptModel_BatchInsert_Single(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
- path := "/bis/" + testutil.UniqueId() + "/"
|
|
|
|
|
- d := &SysDept{ParentId: 0, Name: "bis_" + testutil.UniqueId(), Path: path, Sort: 1, Status: 1, CreateTime: now, UpdateTime: now}
|
|
|
|
|
|
|
+ uniq := "bis_" + testutil.UniqueId()
|
|
|
|
|
+ d := &SysDept{ParentId: 0, Name: uniq, Path: "/" + uniq + "/", Sort: 1, Status: 1, CreateTime: now, UpdateTime: now}
|
|
|
require.NoError(t, m.BatchInsert(ctx, []*SysDept{d}))
|
|
require.NoError(t, m.BatchInsert(ctx, []*SysDept{d}))
|
|
|
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, path)
|
|
|
|
|
|
|
+ all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
- require.Len(t, list, 1)
|
|
|
|
|
|
|
+ var id int64
|
|
|
|
|
+ for _, row := range all {
|
|
|
|
|
+ if row.Name == uniq {
|
|
|
|
|
+ id = row.Id
|
|
|
|
|
+ break
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ require.NotZero(t, id)
|
|
|
tbl := m.TableName()
|
|
tbl := m.TableName()
|
|
|
- t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, list[0].Id) })
|
|
|
|
|
-
|
|
|
|
|
- assert.Equal(t, d.Name, list[0].Name)
|
|
|
|
|
|
|
+ t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, id) })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0341: 正常多条
|
|
|
|
|
|
|
+// TC-0341: BatchInsertWithTx 正常
|
|
|
func TestSysDeptModel_BatchInsertWithTx_Normal(t *testing.T) {
|
|
func TestSysDeptModel_BatchInsertWithTx_Normal(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -499,14 +400,21 @@ func TestSysDeptModel_BatchInsertWithTx_Normal(t *testing.T) {
|
|
|
})
|
|
})
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, "/bitx/"+tag)
|
|
|
|
|
|
|
+ all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
- require.Len(t, list, 2)
|
|
|
|
|
|
|
+ wanted := map[string]struct{}{batch[0].Name: {}, batch[1].Name: {}}
|
|
|
|
|
+ var ids []int64
|
|
|
|
|
+ for _, row := range all {
|
|
|
|
|
+ if _, ok := wanted[row.Name]; ok {
|
|
|
|
|
+ ids = append(ids, row.Id)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ require.Len(t, ids, 2)
|
|
|
tbl := m.TableName()
|
|
tbl := m.TableName()
|
|
|
- t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, list[0].Id, list[1].Id) })
|
|
|
|
|
|
|
+ t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, ids...) })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0340: 空列表
|
|
|
|
|
|
|
+// TC-0340: BatchInsertWithTx 空
|
|
|
func TestSysDeptModel_BatchInsertWithTx_Empty(t *testing.T) {
|
|
func TestSysDeptModel_BatchInsertWithTx_Empty(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -516,16 +424,16 @@ func TestSysDeptModel_BatchInsertWithTx_Empty(t *testing.T) {
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0342: 事务回滚
|
|
|
|
|
|
|
+// TC-0342: BatchInsertWithTx 回滚
|
|
|
func TestSysDeptModel_BatchInsertWithTx_Rollback(t *testing.T) {
|
|
func TestSysDeptModel_BatchInsertWithTx_Rollback(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
|
|
|
now := time.Now().Unix()
|
|
now := time.Now().Unix()
|
|
|
- path := "/bitxrb/" + testutil.UniqueId() + "/"
|
|
|
|
|
|
|
+ uniq := "rbn_" + testutil.UniqueId()
|
|
|
batch := []*SysDept{
|
|
batch := []*SysDept{
|
|
|
- {ParentId: 0, Name: "rbn_" + testutil.UniqueId(), Path: path + "1/", Sort: 1, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
|
|
|
|
+ {ParentId: 0, Name: uniq, Path: "/rbn/" + uniq + "/", Sort: 1, Status: 1, CreateTime: now, UpdateTime: now},
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
err := m.TransactCtx(ctx, func(c context.Context, s sqlx.Session) error {
|
|
err := m.TransactCtx(ctx, func(c context.Context, s sqlx.Session) error {
|
|
@@ -536,12 +444,14 @@ func TestSysDeptModel_BatchInsertWithTx_Rollback(t *testing.T) {
|
|
|
})
|
|
})
|
|
|
require.Error(t, err)
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, path)
|
|
|
|
|
|
|
+ all, err := m.FindAll(ctx)
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
- assert.Empty(t, list)
|
|
|
|
|
|
|
+ for _, row := range all {
|
|
|
|
|
+ assert.NotEqual(t, uniq, row.Name)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0349: 正常多条
|
|
|
|
|
|
|
+// TC-0349: BatchUpdateWithTx 正常
|
|
|
func TestSysDeptModel_BatchUpdateWithTx_Normal(t *testing.T) {
|
|
func TestSysDeptModel_BatchUpdateWithTx_Normal(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -580,7 +490,7 @@ func TestSysDeptModel_BatchUpdateWithTx_Normal(t *testing.T) {
|
|
|
assert.Equal(t, "butx2_new", g2.Name)
|
|
assert.Equal(t, "butx2_new", g2.Name)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0348: 空列表
|
|
|
|
|
|
|
+// TC-0348: BatchUpdateWithTx 空
|
|
|
func TestSysDeptModel_BatchUpdateWithTx_Empty(t *testing.T) {
|
|
func TestSysDeptModel_BatchUpdateWithTx_Empty(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -590,7 +500,7 @@ func TestSysDeptModel_BatchUpdateWithTx_Empty(t *testing.T) {
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0354: 单个id
|
|
|
|
|
|
|
+// TC-0354: BatchDelete 单条
|
|
|
func TestSysDeptModel_BatchDelete_Single(t *testing.T) {
|
|
func TestSysDeptModel_BatchDelete_Single(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -610,7 +520,7 @@ func TestSysDeptModel_BatchDelete_Single(t *testing.T) {
|
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0356: 包含不存在id
|
|
|
|
|
|
|
+// TC-0356: BatchDelete 包含不存在 id
|
|
|
func TestSysDeptModel_BatchDelete_ContainsNonExist(t *testing.T) {
|
|
func TestSysDeptModel_BatchDelete_ContainsNonExist(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -630,7 +540,7 @@ func TestSysDeptModel_BatchDelete_ContainsNonExist(t *testing.T) {
|
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0358: 正常多条
|
|
|
|
|
|
|
+// TC-0358: BatchDeleteWithTx 正常
|
|
|
func TestSysDeptModel_BatchDeleteWithTx_Normal(t *testing.T) {
|
|
func TestSysDeptModel_BatchDeleteWithTx_Normal(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -661,7 +571,7 @@ func TestSysDeptModel_BatchDeleteWithTx_Normal(t *testing.T) {
|
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0357: 空ids
|
|
|
|
|
|
|
+// TC-0357: BatchDeleteWithTx 空
|
|
|
func TestSysDeptModel_BatchDeleteWithTx_Empty(t *testing.T) {
|
|
func TestSysDeptModel_BatchDeleteWithTx_Empty(t *testing.T) {
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
@@ -671,30 +581,7 @@ func TestSysDeptModel_BatchDeleteWithTx_Empty(t *testing.T) {
|
|
|
require.NoError(t, err)
|
|
require.NoError(t, err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0447: LIKE注入已修复 — % 和 _ 被转义,不再作为通配符
|
|
|
|
|
-func TestSysDeptModel_FindByPathPrefix_LikeInjection(t *testing.T) {
|
|
|
|
|
- ctx := context.Background()
|
|
|
|
|
- conn := testutil.GetTestSqlConn()
|
|
|
|
|
- m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
-
|
|
|
|
|
- now := time.Now().Unix()
|
|
|
|
|
- d := &SysDept{ParentId: 0, Name: "li_" + testutil.UniqueId(), Path: "/test/", Sort: 1, Status: 1, CreateTime: now, UpdateTime: now}
|
|
|
|
|
- res, err := m.Insert(ctx, d)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- id, _ := res.LastInsertId()
|
|
|
|
|
- tbl := m.TableName()
|
|
|
|
|
- t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, id) })
|
|
|
|
|
-
|
|
|
|
|
- list, err := m.FindByPathPrefix(ctx, "%")
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- assert.Empty(t, list, "% 不应再作为通配符匹配所有记录")
|
|
|
|
|
-
|
|
|
|
|
- list2, err := m.FindByPathPrefix(ctx, "/test/")
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- assert.GreaterOrEqual(t, len(list2), 1, "正常前缀仍应匹配")
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// TC-0323: 事务内可见性
|
|
|
|
|
|
|
+// TC-0323: 事务内 FindOne
|
|
|
func TestSysDeptModel_FindOneWithTx_InsertThenFind(t *testing.T) {
|
|
func TestSysDeptModel_FindOneWithTx_InsertThenFind(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -724,7 +611,7 @@ func TestSysDeptModel_FindOneWithTx_InsertThenFind(t *testing.T) {
|
|
|
assert.Equal(t, insertedId, foundInTx.Id)
|
|
assert.Equal(t, insertedId, foundInTx.Id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// TC-0322: 事务内记录不存在
|
|
|
|
|
|
|
+// TC-0322: FindOneWithTx 不存在
|
|
|
func TestSysDeptModel_FindOneWithTx_NotFound(t *testing.T) {
|
|
func TestSysDeptModel_FindOneWithTx_NotFound(t *testing.T) {
|
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
conn := testutil.GetTestSqlConn()
|
|
conn := testutil.GetTestSqlConn()
|
|
@@ -736,31 +623,3 @@ func TestSysDeptModel_FindOneWithTx_NotFound(t *testing.T) {
|
|
|
})
|
|
})
|
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
require.ErrorIs(t, err, ErrNotFound)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// TC-0445: FindByParentId 无子部门
|
|
|
|
|
-func TestSysDeptModel_FindByParentId_NoChildren(t *testing.T) {
|
|
|
|
|
- ctx := context.Background()
|
|
|
|
|
- conn := testutil.GetTestSqlConn()
|
|
|
|
|
- m := NewSysDeptModel(conn, testutil.GetTestCacheConf(), testutil.GetTestCachePrefix())
|
|
|
|
|
-
|
|
|
|
|
- now := time.Now().Unix()
|
|
|
|
|
- parent := &SysDept{
|
|
|
|
|
- ParentId: 0,
|
|
|
|
|
- Name: "nochild_" + testutil.UniqueId(),
|
|
|
|
|
- Path: "/nochild/" + testutil.UniqueId() + "/",
|
|
|
|
|
- Sort: 1,
|
|
|
|
|
- Status: 1,
|
|
|
|
|
- CreateTime: now,
|
|
|
|
|
- UpdateTime: now,
|
|
|
|
|
- }
|
|
|
|
|
- res, err := m.Insert(ctx, parent)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- pid, err := res.LastInsertId()
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- tbl := m.TableName()
|
|
|
|
|
- t.Cleanup(func() { testutil.CleanTable(ctx, conn, tbl, pid) })
|
|
|
|
|
-
|
|
|
|
|
- list, err := m.FindByParentId(ctx, pid)
|
|
|
|
|
- require.NoError(t, err)
|
|
|
|
|
- require.Empty(t, list)
|
|
|
|
|
-}
|
|
|