mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-02-18 00:17:39 +01:00
Add tests for AI intelligence, Docker/K8s agents, log redaction, and general router helper functions.
97 lines
2.9 KiB
Go
97 lines
2.9 KiB
Go
package api
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/ai/memory"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/alerts"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/monitoring"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/notifications"
|
|
)
|
|
|
|
func TestNewAlertMonitorWrapper_Nil(t *testing.T) {
|
|
if NewAlertMonitorWrapper(nil) != nil {
|
|
t.Fatalf("expected nil wrapper for nil monitor")
|
|
}
|
|
}
|
|
|
|
func TestNewNotificationMonitorWrapper_Nil(t *testing.T) {
|
|
if NewNotificationMonitorWrapper(nil) != nil {
|
|
t.Fatalf("expected nil wrapper for nil monitor")
|
|
}
|
|
}
|
|
|
|
func TestAlertMonitorWrapper_Delegates(t *testing.T) {
|
|
monitor := &monitoring.Monitor{}
|
|
state := models.NewState()
|
|
alertManager := &alerts.Manager{}
|
|
incidentStore := &memory.IncidentStore{}
|
|
notificationMgr := ¬ifications.NotificationManager{}
|
|
configPersist := &config.ConfigPersistence{}
|
|
|
|
setUnexportedField(t, monitor, "state", state)
|
|
setUnexportedField(t, monitor, "alertManager", alertManager)
|
|
setUnexportedField(t, monitor, "incidentStore", incidentStore)
|
|
setUnexportedField(t, monitor, "notificationMgr", notificationMgr)
|
|
setUnexportedField(t, monitor, "configPersist", configPersist)
|
|
|
|
wrapper := NewAlertMonitorWrapper(monitor)
|
|
if wrapper == nil {
|
|
t.Fatalf("expected wrapper for non-nil monitor")
|
|
}
|
|
|
|
if wrapper.GetAlertManager() != alertManager {
|
|
t.Fatalf("unexpected alert manager")
|
|
}
|
|
if wrapper.GetIncidentStore() != incidentStore {
|
|
t.Fatalf("unexpected incident store")
|
|
}
|
|
if wrapper.GetNotificationManager() != notificationMgr {
|
|
t.Fatalf("unexpected notification manager")
|
|
}
|
|
if wrapper.GetConfigPersistence() != configPersist {
|
|
t.Fatalf("unexpected config persistence")
|
|
}
|
|
|
|
expected := state.GetSnapshot()
|
|
if got := wrapper.GetState(); !reflect.DeepEqual(got, expected) {
|
|
t.Fatalf("unexpected state snapshot")
|
|
}
|
|
|
|
wrapper.SyncAlertState()
|
|
if state.ActiveAlerts == nil {
|
|
t.Fatalf("expected active alerts to be initialized")
|
|
}
|
|
}
|
|
|
|
func TestNotificationMonitorWrapper_Delegates(t *testing.T) {
|
|
monitor := &monitoring.Monitor{}
|
|
state := models.NewState()
|
|
notificationMgr := ¬ifications.NotificationManager{}
|
|
configPersist := &config.ConfigPersistence{}
|
|
|
|
setUnexportedField(t, monitor, "state", state)
|
|
setUnexportedField(t, monitor, "notificationMgr", notificationMgr)
|
|
setUnexportedField(t, monitor, "configPersist", configPersist)
|
|
|
|
wrapper := NewNotificationMonitorWrapper(monitor)
|
|
if wrapper == nil {
|
|
t.Fatalf("expected wrapper for non-nil monitor")
|
|
}
|
|
|
|
if wrapper.GetNotificationManager() != notificationMgr {
|
|
t.Fatalf("unexpected notification manager")
|
|
}
|
|
if wrapper.GetConfigPersistence() != configPersist {
|
|
t.Fatalf("unexpected config persistence")
|
|
}
|
|
|
|
expected := state.GetSnapshot()
|
|
if got := wrapper.GetState(); !reflect.DeepEqual(got, expected) {
|
|
t.Fatalf("unexpected state snapshot")
|
|
}
|
|
}
|