mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-02-19 07:50:43 +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
103 lines
2.8 KiB
Go
103 lines
2.8 KiB
Go
package proxmox
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestClientNodeStatusAndRRD(t *testing.T) {
|
|
client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/api2/json/nodes/node1/status":
|
|
writeJSON(t, w, map[string]interface{}{
|
|
"data": NodeStatus{CPU: 0.5, KernelVersion: "6.1"},
|
|
})
|
|
case "/api2/json/nodes/node1/rrddata":
|
|
if !strings.Contains(r.URL.RawQuery, "timeframe=hour") || !strings.Contains(r.URL.RawQuery, "cf=AVERAGE") {
|
|
http.Error(w, "bad query", http.StatusBadRequest)
|
|
return
|
|
}
|
|
writeJSON(t, w, map[string]interface{}{
|
|
"data": []NodeRRDPoint{{Time: 123}},
|
|
})
|
|
case "/api2/json/nodes/node1/lxc/101/rrddata":
|
|
if !strings.Contains(r.URL.RawQuery, "ds=memused") {
|
|
http.Error(w, "bad query", http.StatusBadRequest)
|
|
return
|
|
}
|
|
writeJSON(t, w, map[string]interface{}{
|
|
"data": []GuestRRDPoint{{Time: 456}},
|
|
})
|
|
case "/api2/json/nodes/node1/disks/list":
|
|
writeJSON(t, w, map[string]interface{}{
|
|
"data": []Disk{{DevPath: "/dev/sda", Model: "Disk"}},
|
|
})
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
|
|
ctx := context.Background()
|
|
status, err := client.GetNodeStatus(ctx, "node1")
|
|
if err != nil {
|
|
t.Fatalf("GetNodeStatus error: %v", err)
|
|
}
|
|
if status.KernelVersion != "6.1" {
|
|
t.Fatalf("unexpected node status: %+v", status)
|
|
}
|
|
|
|
rrd, err := client.GetNodeRRDData(ctx, "node1", "", "", []string{"cpu"})
|
|
if err != nil {
|
|
t.Fatalf("GetNodeRRDData error: %v", err)
|
|
}
|
|
if len(rrd) != 1 || rrd[0].Time != 123 {
|
|
t.Fatalf("unexpected node rrd: %+v", rrd)
|
|
}
|
|
|
|
guestRRD, err := client.GetLXCRRDData(ctx, "node1", 101, "", "", []string{"memused"})
|
|
if err != nil {
|
|
t.Fatalf("GetLXCRRDData error: %v", err)
|
|
}
|
|
if len(guestRRD) != 1 || guestRRD[0].Time != 456 {
|
|
t.Fatalf("unexpected guest rrd: %+v", guestRRD)
|
|
}
|
|
|
|
disks, err := client.GetDisks(ctx, "node1")
|
|
if err != nil {
|
|
t.Fatalf("GetDisks error: %v", err)
|
|
}
|
|
if len(disks) != 1 || disks[0].DevPath != "/dev/sda" {
|
|
t.Fatalf("unexpected disks: %+v", disks)
|
|
}
|
|
}
|
|
|
|
func TestClientNodeNetworkInterfaces(t *testing.T) {
|
|
client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
|
|
switch r.URL.Path {
|
|
case "/api2/json/nodes/node1/network":
|
|
writeJSON(t, w, map[string]interface{}{
|
|
"data": []NodeNetworkInterface{{Iface: "eth0", Active: 1}},
|
|
})
|
|
case "/api2/json/nodes/bad/network":
|
|
http.Error(w, "boom", http.StatusInternalServerError)
|
|
default:
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
|
|
ctx := context.Background()
|
|
ifaces, err := client.GetNodeNetworkInterfaces(ctx, "node1")
|
|
if err != nil {
|
|
t.Fatalf("GetNodeNetworkInterfaces error: %v", err)
|
|
}
|
|
if len(ifaces) != 1 || ifaces[0].Iface != "eth0" {
|
|
t.Fatalf("unexpected interfaces: %+v", ifaces)
|
|
}
|
|
|
|
if _, err := client.GetNodeNetworkInterfaces(ctx, "bad"); err == nil {
|
|
t.Fatal("expected error for non-200 response")
|
|
}
|
|
}
|