sync: 同步 v1.0.4 开源代码并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 14:52:43 +08:00
parent 32e4316ee4
commit 6893e21f07
136 changed files with 9851 additions and 436 deletions
+56 -5
View File
@@ -74,7 +74,7 @@ func TestAllocateBatchSizesRemainBounded(t *testing.T) {
func TestBuildDetailUpdateStatementUsesBoundParameters(t *testing.T) {
task := &Task{Batch: Batch{BatchNo: "ALC-1", CreatedBy: 7}}
details := []*Detail{
{ID: 11, DetailStatus: consts.BatchDetailStatusPending, Reason: "unsafe ' reason"},
{ID: 11, DetailStatus: consts.BatchDetailStatusPending, Reason: atomicNotExecutedReason},
{ID: 12, DetailStatus: consts.BatchDetailStatusRunning, Reason: "second"},
}
statement, args := buildDetailUpdateStatement(task, details, gtime.Now())
@@ -84,8 +84,11 @@ func TestBuildDetailUpdateStatementUsesBoundParameters(t *testing.T) {
if !strings.Contains(statement, "CASE") || !strings.Contains(statement, "IN (?,?)") {
t.Fatalf("unexpected statement: %s", statement)
}
if len(args) != len(details)*7+9 {
t.Fatalf("argument count = %d, want %d", len(args), len(details)*7+9)
if len(args) != len(details)*7+10 {
t.Fatalf("argument count = %d, want %d", len(args), len(details)*7+10)
}
if args[1] != consts.BatchDetailStatusNotExecuted || args[3] != consts.BatchDetailStatusFailed {
t.Fatalf("status parameters = %v, %v; want not executed and failed", args[1], args[3])
}
}
@@ -96,20 +99,68 @@ func TestNormalizeAtomicParentResultRejectsPartialSuccess(t *testing.T) {
}}
successCount, failCount := normalizeAtomicParentResult(task)
if successCount != 0 || failCount != len(task.Details) {
t.Fatalf("normalizeAtomicParentResult() = %d, %d; want 0, %d", successCount, failCount, len(task.Details))
if successCount != 0 || failCount != 1 {
t.Fatalf("normalizeAtomicParentResult() = %d, %d; want 0, 1", successCount, failCount)
}
for _, detail := range task.Details {
if detail.Success() {
t.Fatalf("detail %s remained successful", detail.ICCID)
}
}
if allocationDetailStatus(task.Details[0]) != consts.BatchDetailStatusNotExecuted || allocationDetailStatus(task.Details[1]) != consts.BatchDetailStatusFailed {
t.Fatalf("wrong detail statuses: %+v", task.Details)
}
rows := task.ResultRows()
if rows[0].Status != "未执行" || rows[1].Status != "失败" {
t.Fatalf("wrong result file statuses: %+v", rows)
}
status, result, _ := parentBatchResult(successCount, failCount)
if status != consts.BatchAsyncStatusFailed || result != consts.BatchRunResultFailed {
t.Fatalf("parentBatchResult() = %d, %d; want failed, failed", status, result)
}
}
func TestAllocateChildValidationDoesNotReportExecutedSuccess(t *testing.T) {
task := &Task{Batch: Batch{BatchNo: "child", ParentBatchNo: "parent"}}
detail := &Detail{ID: 1, ICCID: "valid"}
_, args := buildDetailUpdateStatement(task, []*Detail{detail}, gtime.Now())
if args[1] != consts.BatchDetailStatusRunning {
t.Fatalf("validated child status = %v, want running until parent commits", args[1])
}
task.Batch.ParentBatchNo = ""
_, args = buildDetailUpdateStatement(task, []*Detail{detail}, gtime.Now())
if args[1] != consts.BatchDetailStatusSuccess {
t.Fatalf("committed parent status = %v, want success", args[1])
}
}
func TestValidateTaskCollectsAllCardFailuresBeforeBlockingBatch(t *testing.T) {
task := &Task{
Batch: Batch{CreatedDept: 100, TargetDeptID: 200},
TargetsByID: map[int64]*Target{200: {DeptID: 200, ParentID: 100}},
Details: []*Detail{
{ICCID: "missing"},
{ICCID: "valid", Card: &Card{ICCID: "valid", DeptID: 100}},
{ICCID: "stopped", Card: &Card{ICCID: "stopped", DeptID: 100, BossCardStatus: consts.SimBossCardStatusStopped, PackageStatus: consts.PackageStatusExpired}},
},
}
validateTask(task)
if task.Details[0].Reason != "ICCID不存在或不属于当前租户" {
t.Fatalf("first failure was lost: %q", task.Details[0].Reason)
}
if task.Details[1].Reason != atomicNotExecutedReason || allocationDetailStatus(task.Details[1]) != consts.BatchDetailStatusNotExecuted {
t.Fatalf("validated card was not blocked: %+v", task.Details[1])
}
for _, reason := range []string{"卡已停机,不能划拨", "套餐已过期,不能划拨"} {
if !strings.Contains(task.Details[2].Reason, reason) {
t.Fatalf("later card was not fully validated: %q", task.Details[2].Reason)
}
}
if successes, failures := normalizeAtomicParentResult(task); successes != 0 || failures != 2 {
t.Fatalf("got successes=%d failures=%d, want 0 and 2", successes, failures)
}
}
func TestValidateDetailAllowsCurrentHolderReallocation(t *testing.T) {
task := &Task{
Batch: Batch{