@@ -202,145 +202,6 @@ func TestProblemDetector_StatusProcessing(t *testing.T) {
202202 }
203203}
204204
205- func TestStatusToProblems_Events (t * testing.T ) {
206- helper := NewTestHelper ()
207- config := helper .CreateTestConfig ()
208- factory := NewMockMonitorFactory ()
209- detector , _ := NewProblemDetector (config , []types.Monitor {}, []types.Exporter {NewMockExporter ("test" )}, "/tmp/test-config.yaml" , factory )
210-
211- tests := []struct {
212- name string
213- status * types.Status
214- expectedCount int
215- containsTypes []string // Check for presence, not order
216- containsSeverities []types.ProblemSeverity
217- }{
218- {
219- name : "error event" ,
220- status : func () * types.Status {
221- status := types .NewStatus ("test-source" )
222- status .AddEvent (types .NewEvent (types .EventError , "CriticalError" , "Critical error occurred" ))
223- status .AddCondition (types .NewCondition ("SystemHealth" , types .ConditionFalse , "HealthCheck" , "System not healthy" ))
224- return status
225- }(),
226- expectedCount : 2 , // 1 error event + 1 false condition
227- containsTypes : []string {"event-CriticalError" , "condition-SystemHealth" },
228- containsSeverities : []types.ProblemSeverity {types .ProblemCritical }, // Both error events and false conditions are Critical
229- },
230- {
231- name : "warning event" ,
232- status : func () * types.Status {
233- status := types .NewStatus ("test-source" )
234- status .AddEvent (types .NewEvent (types .EventWarning , "PerformanceWarning" , "Warning occurred" ))
235- return status
236- }(),
237- expectedCount : 1 ,
238- containsTypes : []string {"event-PerformanceWarning" },
239- containsSeverities : []types.ProblemSeverity {types .ProblemWarning },
240- },
241- {
242- name : "healthy status" ,
243- status : func () * types.Status {
244- status := types .NewStatus ("test-source" )
245- status .AddCondition (types .NewCondition ("Ready" , types .ConditionTrue , "Ready" , "Ready" ))
246- return status
247- }(),
248- expectedCount : 0 , // Info events and true conditions are ignored
249- },
250- {
251- name : "empty status" ,
252- status : types .NewStatus ("test-source" ),
253- expectedCount : 0 ,
254- },
255- }
256-
257- for _ , tt := range tests {
258- t .Run (tt .name , func (t * testing.T ) {
259- problems := detector .statusToProblems (tt .status )
260-
261- if len (problems ) != tt .expectedCount {
262- t .Errorf ("statusToProblems() problem count = %d, want %d" , len (problems ), tt .expectedCount )
263- }
264-
265- // Check that all expected types are present
266- if tt .expectedCount > 0 {
267- problemTypes := make (map [string ]bool )
268- problemSeverities := make (map [types.ProblemSeverity ]bool )
269-
270- for _ , problem := range problems {
271- problemTypes [problem .Type ] = true
272- problemSeverities [problem .Severity ] = true
273- }
274-
275- for _ , expectedType := range tt .containsTypes {
276- if ! problemTypes [expectedType ] {
277- t .Errorf ("statusToProblems() missing expected problem type: %s" , expectedType )
278- }
279- }
280-
281- for _ , expectedSeverity := range tt .containsSeverities {
282- if ! problemSeverities [expectedSeverity ] {
283- t .Errorf ("statusToProblems() missing expected problem severity: %s" , expectedSeverity )
284- }
285- }
286- }
287- })
288- }
289- }
290-
291- func TestStatusToProblems_Conditions (t * testing.T ) {
292- helper := NewTestHelper ()
293- config := helper .CreateTestConfig ()
294- factory := NewMockMonitorFactory ()
295- detector , _ := NewProblemDetector (config , []types.Monitor {}, []types.Exporter {NewMockExporter ("test" )}, "/tmp/test-config.yaml" , factory )
296-
297- status := types .NewStatus ("test-source" )
298- status .AddCondition (types .NewCondition ("DiskPressure" , types .ConditionFalse , "DiskFull" , "Disk is full" ))
299- status .AddCondition (types .NewCondition ("NetworkReady" , types .ConditionTrue , "NetworkOK" , "Network is ready" ))
300- status .AddCondition (types .NewCondition ("UnknownCondition" , types .ConditionUnknown , "Unknown" , "Status unknown" ))
301-
302- problems := detector .statusToProblems (status )
303-
304- // Should only create problem for False condition
305- if len (problems ) != 1 {
306- t .Errorf ("statusToProblems() problem count = %d, want 1" , len (problems ))
307- }
308-
309- if problems [0 ].Type != "condition-DiskPressure" {
310- t .Errorf ("statusToProblems() problem type = %s, want condition-DiskPressure" , problems [0 ].Type )
311- }
312- }
313-
314- func TestDeduplicateProblems (t * testing.T ) {
315- helper := NewTestHelper ()
316- config := helper .CreateTestConfig ()
317- factory := NewMockMonitorFactory ()
318- detector , _ := NewProblemDetector (config , []types.Monitor {}, []types.Exporter {NewMockExporter ("test" )}, "/tmp/test-config.yaml" , factory )
319-
320- // First set of problems
321- problem1 := types .NewProblem ("disk-full" , "node1" , types .ProblemCritical , "Disk is full" )
322- problem2 := types .NewProblem ("memory-pressure" , "node1" , types .ProblemWarning , "Memory pressure detected" )
323-
324- newProblems := detector .deduplicateProblems ([]* types.Problem {problem1 , problem2 })
325- if len (newProblems ) != 2 {
326- t .Errorf ("First deduplication expected 2 new problems, got %d" , len (newProblems ))
327- }
328-
329- // Same problems again (should be deduplicated)
330- problem1Dup := types .NewProblem ("disk-full" , "node1" , types .ProblemCritical , "Disk is full" )
331- newProblems = detector .deduplicateProblems ([]* types.Problem {problem1Dup })
332- if len (newProblems ) != 0 {
333- t .Errorf ("Second deduplication expected 0 new problems, got %d" , len (newProblems ))
334- }
335-
336- // Same type/resource but different severity (should be reported)
337- problem1Updated := types .NewProblem ("disk-full" , "node1" , types .ProblemWarning , "Disk pressure reduced" )
338- newProblems = detector .deduplicateProblems ([]* types.Problem {problem1Updated })
339- if len (newProblems ) != 1 {
340- t .Errorf ("Third deduplication expected 1 new problem, got %d" , len (newProblems ))
341- }
342- }
343-
344205func TestExportDistribution (t * testing.T ) {
345206 helper := NewTestHelper ()
346207 config := helper .CreateTestConfig ()
@@ -556,17 +417,17 @@ func TestExportFailureIsolation(t *testing.T) {
556417 config := helper .CreateTestConfig ()
557418
558419 // Create exporters with different failure behaviors
420+ // Note: We only test status export failures since ExportProblem is no longer called (issue #7 fix)
559421 successExporter := NewMockExporter ("success-exporter" )
560422 failStatusExporter := NewMockExporter ("fail-status" ).SetStatusExportError (fmt .Errorf ("status export failed" ))
561- failProblemExporter := NewMockExporter ("fail-problem" ).SetProblemExportError (fmt .Errorf ("problem export failed" ))
562423
563424 factory := NewMockMonitorFactory ().SetCreateFunc (func (config types.MonitorConfig ) (types.Monitor , error ) {
564425 status := types .NewStatus (config .Name )
565426 status .AddEvent (types .NewEvent (types .EventError , "CriticalError" , "Critical error occurred" ))
566427 return NewMockMonitor (config .Name ).AddStatusUpdate (status ), nil
567428 })
568429
569- detector , err := NewProblemDetector (config , []types.Monitor {}, []types.Exporter {successExporter , failStatusExporter , failProblemExporter }, "/tmp/test-config.yaml" , factory )
430+ detector , err := NewProblemDetector (config , []types.Monitor {}, []types.Exporter {successExporter , failStatusExporter }, "/tmp/test-config.yaml" , factory )
570431 if err != nil {
571432 t .Fatalf ("NewProblemDetector() error = %v" , err )
572433 }
@@ -650,7 +511,7 @@ func TestStatisticsTracking(t *testing.T) {
650511 })
651512
652513 successExporter := NewMockExporter ("success-exp" )
653- failExporter := NewMockExporter ("fail-exp" ).SetProblemExportError (fmt .Errorf ("export failed" ))
514+ failExporter := NewMockExporter ("fail-exp" ).SetStatusExportError (fmt .Errorf ("export failed" ))
654515
655516 detector , err := NewProblemDetector (config , []types.Monitor {}, []types.Exporter {successExporter , failExporter }, "/tmp/test-config.yaml" , factory )
656517 if err != nil {
@@ -679,9 +540,6 @@ func TestStatisticsTracking(t *testing.T) {
679540 if stats .GetStatusesReceived () == 0 {
680541 t .Errorf ("Expected statuses to be received" )
681542 }
682- if stats .GetProblemsDetected () == 0 {
683- t .Errorf ("Expected problems to be detected" )
684- }
685543
686544 // Verify export statistics
687545 if stats .GetExportsSucceeded () == 0 {
0 commit comments