From 6107c3eb876896beced32316f5d76014565bdcce Mon Sep 17 00:00:00 2001 From: Denozordec Date: Thu, 9 Apr 2026 15:14:19 +0700 Subject: [PATCH] refactor: enhance job status checks in worker tests Updated the worker test cases to improve the handling of job status checks. Added nil checks for job instances and refined the logic to verify job statuses directly from snapshots, ensuring more robust test coverage and preventing potential nil pointer dereferences. --- internal/jobs/worker_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/internal/jobs/worker_test.go b/internal/jobs/worker_test.go index 05d398e..40323a9 100644 --- a/internal/jobs/worker_test.go +++ b/internal/jobs/worker_test.go @@ -58,10 +58,14 @@ func TestParallelModuleRefresh_CoalescesDeployApply(t *testing.T) { var deferred, withDeployID int refreshJobs, _, _ := reg.List(tenant, "", KindModuleRefresh, "", 100) for _, j := range refreshJobs { - if j.Status != StatusSucceeded { + if j == nil { continue } - meta := j.Snapshot()["meta"].(map[string]any) + snap := j.Snapshot() + if st, _ := snap["status"].(string); st != StatusSucceeded { + continue + } + meta, _ := snap["meta"].(map[string]any) if v, ok := meta["deploy_apply_deferred"].(bool); ok && v { deferred++ } @@ -89,10 +93,13 @@ func waitSucceededJobsByKindCount(t *testing.T, reg *Registry, tenant, kind stri } all, _, _ := reg.List(tenant, "", kind, "", 100) for _, j := range all { - if j == nil || j.Status != StatusFailed { + if j == nil { continue } snap := j.Snapshot() + if st, _ := snap["status"].(string); st != StatusFailed { + continue + } t.Fatalf("%s job failed: %#v", kind, snap["error"]) } time.Sleep(5 * time.Millisecond)