mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-02 13:30:13 +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
100 lines
2.5 KiB
Go
100 lines
2.5 KiB
Go
package proxmox
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestGetCephStatus(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/cluster/ceph/status" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
resp := map[string]interface{}{
|
|
"data": map[string]interface{}{
|
|
"fsid": "fsid-1",
|
|
"health": map[string]interface{}{
|
|
"status": "HEALTH_OK",
|
|
"summary": []map[string]interface{}{
|
|
{"severity": "info", "summary": "ok"},
|
|
},
|
|
"checks": map[string]interface{}{},
|
|
},
|
|
"servicemap": map[string]interface{}{
|
|
"services": map[string]interface{}{},
|
|
},
|
|
"osdmap": map[string]interface{}{
|
|
"num_osds": 1,
|
|
"num_up_osds": 1,
|
|
"num_in_osds": 1,
|
|
},
|
|
"pgmap": map[string]interface{}{
|
|
"num_pgs": 5,
|
|
},
|
|
},
|
|
}
|
|
_ = json.NewEncoder(w).Encode(resp)
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := &Client{baseURL: server.URL, httpClient: server.Client()}
|
|
status, err := client.GetCephStatus(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if status.FSID != "fsid-1" || status.Health.Status != "HEALTH_OK" {
|
|
t.Fatalf("unexpected status: %+v", status)
|
|
}
|
|
}
|
|
|
|
func TestGetCephDF(t *testing.T) {
|
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/cluster/ceph/df" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
resp := map[string]interface{}{
|
|
"data": map[string]interface{}{
|
|
"data": map[string]interface{}{
|
|
"stats": map[string]interface{}{
|
|
"total_bytes": 100,
|
|
"total_used_bytes": 40,
|
|
"total_avail_bytes": 60,
|
|
"total_used_raw_bytes": 45,
|
|
"percent_used": 40.0,
|
|
},
|
|
"pools": []map[string]interface{}{
|
|
{
|
|
"id": 1,
|
|
"name": "pool1",
|
|
"stats": map[string]interface{}{
|
|
"bytes_used": 10,
|
|
"kb_used": 20,
|
|
"max_avail": 30,
|
|
"objects": 40,
|
|
"percent_used": 10.0,
|
|
"dirty": 0,
|
|
"stored_raw": 50,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
_ = json.NewEncoder(w).Encode(resp)
|
|
}))
|
|
defer server.Close()
|
|
|
|
client := &Client{baseURL: server.URL, httpClient: server.Client()}
|
|
df, err := client.GetCephDF(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if df.Data.Stats.TotalBytes != 100 || len(df.Data.Pools) != 1 {
|
|
t.Fatalf("unexpected df: %+v", df)
|
|
}
|
|
}
|