Files
iotlcm/bot/internal/archive/model_test.go

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")
}
}