mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-04-28 11:30:15 +00: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
78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
package updates
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestInstallShAdapter_PrepareUpdate(t *testing.T) {
|
|
adapter := NewInstallShAdapter(nil)
|
|
|
|
plan, err := adapter.PrepareUpdate(context.Background(), UpdateRequest{Version: "v1.2.3"})
|
|
if err != nil {
|
|
t.Fatalf("PrepareUpdate error: %v", err)
|
|
}
|
|
if !plan.CanAutoUpdate || !plan.RequiresRoot || !plan.RollbackSupport {
|
|
t.Fatalf("unexpected plan: %+v", plan)
|
|
}
|
|
if len(plan.Instructions) == 0 || len(plan.Prerequisites) == 0 {
|
|
t.Fatalf("expected instructions and prerequisites: %+v", plan)
|
|
}
|
|
}
|
|
|
|
func TestInstallShAdapter_RollbackErrors(t *testing.T) {
|
|
history, err := NewUpdateHistory(t.TempDir())
|
|
if err != nil {
|
|
t.Fatalf("NewUpdateHistory error: %v", err)
|
|
}
|
|
adapter := NewInstallShAdapter(history)
|
|
ctx := context.Background()
|
|
|
|
if err := adapter.Rollback(ctx, "missing"); err == nil {
|
|
t.Fatal("expected error for missing history entry")
|
|
}
|
|
|
|
eventNoBackup, err := history.CreateEntry(ctx, UpdateHistoryEntry{
|
|
Action: ActionUpdate,
|
|
Status: StatusSuccess,
|
|
VersionFrom: "v1.0.0",
|
|
VersionTo: "v1.1.0",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateEntry error: %v", err)
|
|
}
|
|
if err := adapter.Rollback(ctx, eventNoBackup); err == nil || !strings.Contains(err.Error(), "no backup path") {
|
|
t.Fatalf("expected backup path error, got %v", err)
|
|
}
|
|
|
|
eventMissingBackup, err := history.CreateEntry(ctx, UpdateHistoryEntry{
|
|
Action: ActionUpdate,
|
|
Status: StatusSuccess,
|
|
VersionFrom: "v1.0.0",
|
|
VersionTo: "v1.1.0",
|
|
BackupPath: filepath.Join(t.TempDir(), "missing"),
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateEntry error: %v", err)
|
|
}
|
|
if err := adapter.Rollback(ctx, eventMissingBackup); err == nil || !strings.Contains(err.Error(), "backup not found") {
|
|
t.Fatalf("expected backup not found error, got %v", err)
|
|
}
|
|
|
|
backupDir := t.TempDir()
|
|
eventNoTarget, err := history.CreateEntry(ctx, UpdateHistoryEntry{
|
|
Action: ActionUpdate,
|
|
Status: StatusSuccess,
|
|
VersionFrom: "",
|
|
VersionTo: "v1.1.0",
|
|
BackupPath: backupDir,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateEntry error: %v", err)
|
|
}
|
|
if err := adapter.Rollback(ctx, eventNoTarget); err == nil || !strings.Contains(err.Error(), "no target version") {
|
|
t.Fatalf("expected target version error, got %v", err)
|
|
}
|
|
}
|