Files
iotlcm/internal/archive/model_test.go
T
MiFaZhan 5732bf3384 chore: 初始开源发布
iotlcm-bot:独立飞书应用机器人(读取 Worker 终态 Run JSON,渲染并发送全量同步结果卡片)。

- Go module:git.5iot.com/iotlcm/iotlcm-bot → git.5iot.com/iotlcm-public/iotlcm-bot
- 飞书凭据占位:appId/appSecret/chatId → ${FEISHU_APP_ID}/${FEISHU_APP_SECRET}/${FEISHU_CHAT_ID}
- 移除内部资产:CI 触发器
- Dockerfile 改用公共基础镜像(golang:1.25-alpine → scratch)
- README 重写(命令/配置/挂载契约/常见问题),去掉内部环境路径
- 补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes
2026-10-22 16:14:24 +08:00

49 lines
2.2 KiB
Go

package archive
import "testing"
func validArchive() RunArchive {
return RunArchive{Version: 1, Run: RunSummary{RunID: "run-1", Operation: "sim_status_queue_full_sync", Status: "completed_with_failures", SuccessCount: 175893, FailedCount: 10504, CreatedAt: "2026-09-22T11:42:33Z", CompletedAt: "2026-09-22T12:32:01Z"}, Rounds: []RoundStats{
{RunID: "run-1", Round: 1, EnqueuedCount: 186397, ActiveCount: 0, NextRoundCount: 9023, SuccessCount: 175870, FailedCount: 1504, UpstreamAttemptCount: 0, BatchCount: 1872, StartedAt: "2026-09-22T11:42:34Z", CompletedAt: "2026-09-22T12:21:49Z"},
{RunID: "run-1", Round: 2, EnqueuedCount: 9023, ActiveCount: 0, NextRoundCount: 9000, SuccessCount: 23, FailedCount: 0, UpstreamAttemptCount: 0, BatchCount: 92, StartedAt: "2026-09-22T12:21:51Z", CompletedAt: "2026-09-22T12:26:55Z"},
{RunID: "run-1", Round: 3, EnqueuedCount: 9000, ActiveCount: 0, NextRoundCount: 0, SuccessCount: 0, FailedCount: 9000, UpstreamAttemptCount: 0, BatchCount: 90, StartedAt: "2026-09-22T12:26:56Z", CompletedAt: "2026-09-22T12:32:01Z"},
}}
}
func TestValidateThreeRounds(t *testing.T) {
a := validArchive()
if err := a.Validate(); err != nil {
t.Fatal(err)
}
if len(a.Rounds) != 3 || a.Run.FailedCount != 10504 {
t.Fatalf("unexpected archive: %+v", a)
}
}
func TestValidateRejectsEmptyRounds(t *testing.T) {
a := RunArchive{Version: 1, Run: RunSummary{RunID: "run-1", Operation: "sim_status_queue_full_sync", Status: "completed"}}
if err := a.Validate(); err == nil {
t.Fatal("expected empty rounds to be rejected")
}
}
func TestValidateRejectsUnclosedRound(t *testing.T) {
a := validArchive()
a.Rounds[0].NextRoundCount++
if err := a.Validate(); err == nil {
t.Fatal("expected count closure error")
}
}
func TestValidateFilenameRequiresExactRunID(t *testing.T) {
if err := ValidateFilename(`/archive/run-full-run-id.json`, "full-run-id"); err != nil {
t.Fatal(err)
}
if err := ValidateFilename(`/archive/run-other-id.json`, "full-run-id"); err == nil {
t.Fatal("expected mismatched filename to be rejected")
}
if err := ValidateFilename(`/archive/action-full-run-id.json`, "full-run-id"); err == nil {
t.Fatal("expected non-run filename to be rejected")
}
}