chore: 并入 iotlcm-worker-svr 历史到 worker-svr/(原提交 96f0f4e)
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package allocate
|
||||
|
||||
import (
|
||||
"github.com/gogf/gf/v2/encoding/gjson"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnitSnapshotSurvivesRenameAndWriteback(t *testing.T) {
|
||||
detail := &Detail{OriginalSnapshot: gjson.New(map[string]any{"sourceDeptName": "划拨旧名称", "sourceDeptKey": "source", "auditMarker": "keep"}), TargetDeptID: 2, TargetDeptName: "接收旧名称", TargetDeptKey: "target", Target: &Target{DeptID: 2, DeptName: "接收新名称", DeptKey: "new"}}
|
||||
info := detail.Snapshot(Batch{CreatedDept: 1})
|
||||
if info.Get("sourceDeptName").String() != "划拨旧名称" || info.Get("targetDeptName").String() != "接收旧名称" || info.Get("targetDeptKey").String() != "target" || info.Get("auditMarker").String() != "keep" {
|
||||
t.Fatal(info)
|
||||
}
|
||||
task := &Task{Details: []*Detail{detail}}
|
||||
if task.ResultRows()[0].TargetDeptName != "接收旧名称" {
|
||||
t.Fatal("结果文件覆盖历史名称")
|
||||
}
|
||||
parent := mergeAllocateParentInfo(gjson.New(map[string]any{"sourceDeptName": "划拨旧名称", "targetDeptName": "接收旧名称"}), nil)
|
||||
if parent.Get("sourceDeptName").String() != "划拨旧名称" {
|
||||
t.Fatal(parent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnitTargetUsesStableIDAfterRename(t *testing.T) {
|
||||
target := &Target{DeptID: 2, DeptName: "接收单位新名称", DeptKey: "new-key"}
|
||||
detail := &Detail{OriginalSnapshot: gjson.New(map[string]any{"sourceDeptId": 9}), TargetDeptID: 2, TargetDeptName: "接收单位旧名称"}
|
||||
task := &Task{TargetsByID: map[int64]*Target{2: target}}
|
||||
if resolveTarget(task, detail) != target {
|
||||
t.Fatal("单位改名后未优先使用稳定 ID")
|
||||
}
|
||||
if detail.Snapshot(Batch{CreatedDept: 1}).Get("sourceDeptId").Int64() != 9 {
|
||||
t.Fatal("执行写回覆盖原划拨单位 ID")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user