mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-02-18 00:17:39 +01:00
New test files with expanded coverage: API tests: - ai_handler_test.go: AI handler unit tests with mocking - agent_profiles_tools_test.go: Profile management tests - alerts_endpoints_test.go: Alert API endpoint tests - alerts_test.go: Updated for interface changes - audit_handlers_test.go: Audit handler tests - frontend_embed_test.go: Frontend embedding tests - metadata_handlers_test.go, metadata_provider_test.go: Metadata tests - notifications_test.go: Updated for interface changes - profile_suggestions_test.go: Profile suggestion tests - saml_service_test.go: SAML authentication tests - sensor_proxy_gate_test.go: Sensor proxy tests - updates_test.go: Updated for interface changes Agent tests: - dockeragent/signature_test.go: Docker agent signature tests - hostagent/agent_metrics_test.go: Host agent metrics tests - hostagent/commands_test.go: Command execution tests - hostagent/network_helpers_test.go: Network helper tests - hostagent/proxmox_setup_test.go: Updated setup tests - kubernetesagent/*_test.go: Kubernetes agent tests Core package tests: - monitoring/kubernetes_agents_test.go, reload_test.go - remoteconfig/client_test.go, signature_test.go - sensors/collector_test.go - updates/adapter_installsh_*_test.go: Install adapter tests - updates/manager_*_test.go: Update manager tests - websocket/hub_*_test.go: WebSocket hub tests Library tests: - pkg/audit/export_test.go: Audit export tests - pkg/metrics/store_test.go: Metrics store tests - pkg/proxmox/*_test.go: Proxmox client tests - pkg/reporting/reporting_test.go: Reporting tests - pkg/server/*_test.go: Server tests - pkg/tlsutil/extra_test.go: TLS utility tests Total: ~8000 lines of new test code
113 lines
3.0 KiB
Go
113 lines
3.0 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/config"
|
|
"github.com/rcourtman/pulse-go-rewrite/internal/models"
|
|
)
|
|
|
|
func newTestProfileManager(t *testing.T) *MCPAgentProfileManager {
|
|
t.Helper()
|
|
persistence := config.NewConfigPersistence(t.TempDir())
|
|
return NewMCPAgentProfileManager(persistence, nil)
|
|
}
|
|
|
|
func TestMCPAgentProfileManagerApplyAndGetScope(t *testing.T) {
|
|
manager := newTestProfileManager(t)
|
|
ctx := context.Background()
|
|
|
|
settings := map[string]interface{}{
|
|
"enable_host": true,
|
|
}
|
|
|
|
profileID, profileName, created, err := manager.ApplyAgentScope(ctx, "agent-1", "Alpha", settings)
|
|
if err != nil {
|
|
t.Fatalf("ApplyAgentScope error: %v", err)
|
|
}
|
|
if !created || profileID == "" || profileName == "" {
|
|
t.Fatalf("unexpected apply result: id=%q name=%q created=%v", profileID, profileName, created)
|
|
}
|
|
|
|
scope, err := manager.GetAgentScope(ctx, "agent-1")
|
|
if err != nil {
|
|
t.Fatalf("GetAgentScope error: %v", err)
|
|
}
|
|
if scope == nil || scope.ProfileID != profileID || scope.ProfileVersion != 1 {
|
|
t.Fatalf("unexpected scope: %+v", scope)
|
|
}
|
|
if scope.Settings["enable_host"] != true {
|
|
t.Fatalf("unexpected settings: %+v", scope.Settings)
|
|
}
|
|
|
|
updatedSettings := map[string]interface{}{
|
|
"enable_host": false,
|
|
}
|
|
_, _, created, err = manager.ApplyAgentScope(ctx, "agent-1", "Alpha", updatedSettings)
|
|
if err != nil {
|
|
t.Fatalf("ApplyAgentScope update error: %v", err)
|
|
}
|
|
if created {
|
|
t.Fatal("expected update to reuse profile")
|
|
}
|
|
|
|
scope, err = manager.GetAgentScope(ctx, "agent-1")
|
|
if err != nil {
|
|
t.Fatalf("GetAgentScope error: %v", err)
|
|
}
|
|
if scope.ProfileVersion != 2 {
|
|
t.Fatalf("expected profile version 2, got %d", scope.ProfileVersion)
|
|
}
|
|
if scope.Settings["enable_host"] != false {
|
|
t.Fatalf("unexpected updated settings: %+v", scope.Settings)
|
|
}
|
|
}
|
|
|
|
func TestMCPAgentProfileManagerAssignProfile(t *testing.T) {
|
|
manager := newTestProfileManager(t)
|
|
ctx := context.Background()
|
|
|
|
profile := models.AgentProfile{
|
|
ID: "profile-1",
|
|
Name: "Default",
|
|
Description: "default",
|
|
Config: map[string]interface{}{
|
|
"enable_host": true,
|
|
},
|
|
Version: 1,
|
|
}
|
|
|
|
if err := manager.persistence.SaveAgentProfiles([]models.AgentProfile{profile}); err != nil {
|
|
t.Fatalf("SaveAgentProfiles error: %v", err)
|
|
}
|
|
|
|
name, err := manager.AssignProfile(ctx, "agent-2", profile.ID)
|
|
if err != nil {
|
|
t.Fatalf("AssignProfile error: %v", err)
|
|
}
|
|
if name != profile.Name {
|
|
t.Fatalf("unexpected profile name: %q", name)
|
|
}
|
|
|
|
scope, err := manager.GetAgentScope(ctx, "agent-2")
|
|
if err != nil {
|
|
t.Fatalf("GetAgentScope error: %v", err)
|
|
}
|
|
if scope == nil || scope.ProfileID != profile.ID || scope.ProfileName != profile.Name {
|
|
t.Fatalf("unexpected scope: %+v", scope)
|
|
}
|
|
}
|
|
|
|
func TestMCPAgentProfileManagerGetScopeMissing(t *testing.T) {
|
|
manager := newTestProfileManager(t)
|
|
|
|
scope, err := manager.GetAgentScope(context.Background(), "missing")
|
|
if err != nil {
|
|
t.Fatalf("GetAgentScope error: %v", err)
|
|
}
|
|
if scope != nil {
|
|
t.Fatalf("expected nil scope, got %+v", scope)
|
|
}
|
|
}
|