@@ -148,71 +148,47 @@ func TestSectionError(t *testing.T) {
148148}
149149
150150func TestRunAllMixedResults (t * testing.T ) {
151- okCheck := & fakeCheck {name : "passing" , data : map [string ]any {"healthy" : true }}
152- failCheck := & fakeCheck {name : "failing" , err : errors .New ("something broke" )}
153- partialCheck := & fakeCheck {name : "partial" , data : map [string ]any {"partial" : true }, err : errors .New ("partial failure" )}
154-
155- origAllChecks := AllChecks
156- // We can't override AllChecks directly since it's a function, so test RunAll
157- // indirectly through the real checks. Instead, test the orchestration logic
158- // by running checks manually and verifying the output structure.
159-
160- _ = origAllChecks // satisfy usage
161-
162- // Simulate RunAll behavior manually with our fake checks
163- checks := []Check {okCheck , failCheck , partialCheck }
164- results := make (map [string ]CheckResult , len (checks ))
165- ok := 0
166- errored := 0
167-
168- for _ , ch := range checks {
169- data , err := ch .Run (context .Background (), nil , "4.21.5" , "4.21.8" )
170- result := CheckResult {Elapsed : 0.1 }
171- if err != nil {
172- result .Status = "error"
173- result .Error = err .Error ()
174- if data != nil {
175- result .Data = data
176- } else {
177- result .Data = map [string ]any {}
178- }
179- errored ++
180- } else {
181- result .Status = "ok"
182- result .Data = data
183- ok ++
151+ orig := AllChecks
152+ defer func () { AllChecks = orig }()
153+
154+ AllChecks = func () []Check {
155+ return []Check {
156+ & fakeCheck {name : "passing" , data : map [string ]any {"healthy" : true }},
157+ & fakeCheck {name : "failing" , err : errors .New ("something broke" )},
158+ & fakeCheck {name : "partial" , data : map [string ]any {"partial" : true }, err : errors .New ("partial failure" )},
184159 }
185- results [ch .Name ()] = result
186160 }
187161
188- if ok != 1 {
189- t .Errorf ("ok count = %d, want 1" , ok )
162+ output := RunAll (context .Background (), nil , "4.21.5" , "4.21.8" )
163+
164+ if output .Meta .TotalChecks != 3 {
165+ t .Errorf ("TotalChecks = %d, want 3" , output .Meta .TotalChecks )
166+ }
167+ if output .Meta .ChecksOK != 1 {
168+ t .Errorf ("ChecksOK = %d, want 1" , output .Meta .ChecksOK )
190169 }
191- if errored != 2 {
192- t .Errorf ("errored count = %d, want 2" , errored )
170+ if output . Meta . ChecksErrored != 2 {
171+ t .Errorf ("ChecksErrored = %d, want 2" , output . Meta . ChecksErrored )
193172 }
194173
195- // Verify passing check
196- passing := results ["passing" ]
197- if passing .Status != "ok" {
174+ passing := output .Checks ["passing" ]
175+ if passing .Status != StatusOK {
198176 t .Errorf ("passing.Status = %q, want ok" , passing .Status )
199177 }
200178 if passing .Data ["healthy" ] != true {
201179 t .Errorf ("passing.Data[healthy] = %v" , passing .Data ["healthy" ])
202180 }
203181
204- // Verify failing check
205- failing := results ["failing" ]
206- if failing .Status != "error" {
182+ failing := output .Checks ["failing" ]
183+ if failing .Status != StatusError {
207184 t .Errorf ("failing.Status = %q, want error" , failing .Status )
208185 }
209186 if failing .Error != "something broke" {
210187 t .Errorf ("failing.Error = %q" , failing .Error )
211188 }
212189
213- // Verify partial failure preserves data
214- partial := results ["partial" ]
215- if partial .Status != "error" {
190+ partial := output .Checks ["partial" ]
191+ if partial .Status != StatusError {
216192 t .Errorf ("partial.Status = %q, want error" , partial .Status )
217193 }
218194 if partial .Data ["partial" ] != true {
0 commit comments