Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Decouple WebSocket contract tests from monitor workload

rcourtman17a1c2096de3
diff --git a/internal/api/router_integration_test.go b/internal/api/router_integration_test.go
index b05f97fc04..8835f1febe 100644
--- a/internal/api/router_integration_test.go
+++ b/internal/api/router_integration_test.go
@@ -84,6 +84,42 @@ func readWebSocketMessageOfType(t *testing.T, conn *gorillaws.Conn, expected str
}
}
+func websocketContractState() models.StateFrontend {
+ return models.StateFrontend{
+ Resources: []models.ResourceFrontend{
+ {
+ ID: "resource-1",
+ Type: "node",
+ Name: "node-1",
+ DisplayName: "Node 1",
+ PlatformID: "platform-1",
+ PlatformType: "proxmox",
+ SourceType: "pve",
+ Status: "online",
+ LastSeen: 1,
+ },
+ },
+ ConnectedInfrastructure: []models.ConnectedInfrastructureItemFrontend{
+ {
+ ID: "resource-1",
+ Name: "Node 1",
+ Status: "active",
+ Surfaces: []models.ConnectedInfrastructureSurfaceFrontend{
+ {ID: "agent:host-1", Kind: "agent", Label: "Host telemetry"},
+ },
+ },
+ },
+ }
+}
+
+func useWebSocketContractState(srv *integrationServer) models.StateFrontend {
+ state := websocketContractState()
+ srv.hub.SetStateGetter(func(string) interface{} {
+ return state
+ })
+ return state
+}
+
func newIntegrationServer(t *testing.T) *integrationServer {
return newIntegrationServerWithConfig(t, nil)
}
@@ -1553,6 +1589,7 @@ func TestRecoveryEndpointRequiresDirectLoopback(t *testing.T) {
func TestWebSocketSendsInitialState(t *testing.T) {
srv := newIntegrationServer(t)
+ state := useWebSocketContractState(srv)
wsURL := "ws" + strings.TrimPrefix(srv.server.URL, "http") + "/ws?org_id=default"
@@ -1580,7 +1617,6 @@ func TestWebSocketSendsInitialState(t *testing.T) {
}
// Broadcast an additional state update and ensure clients receive it
- state := srv.monitor.BuildFrontendState()
srv.hub.BroadcastState(state)
payload = readWebSocketMessageOfType(t, conn, "rawData")
@@ -1593,6 +1629,7 @@ func TestWebSocketSendsInitialState(t *testing.T) {
func TestWebsocketPayloadContractShape(t *testing.T) {
srv := newIntegrationServer(t)
+ contractState := useWebSocketContractState(srv)
wsURL := "ws" + strings.TrimPrefix(srv.server.URL, "http") + "/ws?org_id=default"
@@ -1605,32 +1642,6 @@ func TestWebsocketPayloadContractShape(t *testing.T) {
readWebSocketMessageOfType(t, conn, "welcome")
readWebSocketMessageOfType(t, conn, "initialState")
- contractState := models.StateFrontend{
- Resources: []models.ResourceFrontend{
- {
- ID: "resource-1",
- Type: "node",
- Name: "node-1",
- DisplayName: "Node 1",
- PlatformID: "platform-1",
- PlatformType: "proxmox",
- SourceType: "pve",
- Status: "online",
- LastSeen: 1,
- },
- },
- ConnectedInfrastructure: []models.ConnectedInfrastructureItemFrontend{
- {
- ID: "resource-1",
- Name: "Node 1",
- Status: "active",
- Surfaces: []models.ConnectedInfrastructureSurfaceFrontend{
- {ID: "agent:host-1", Kind: "agent", Label: "Host telemetry"},
- },
- },
- },
- }
-
srv.hub.BroadcastState(contractState)
payload := readWebSocketMessageOfType(t, conn, "rawData")
@@ -1669,6 +1680,7 @@ func TestWebsocketPayloadContractShape(t *testing.T) {
func TestWebsocketPayloadUsesCanonicalStateContract(t *testing.T) {
srv := newIntegrationServer(t)
+ testState := useWebSocketContractState(srv)
wsURL := "ws" + strings.TrimPrefix(srv.server.URL, "http") + "/ws?org_id=default"
@@ -1681,32 +1693,6 @@ func TestWebsocketPayloadUsesCanonicalStateContract(t *testing.T) {
readWebSocketMessageOfType(t, conn, "welcome")
readWebSocketMessageOfType(t, conn, "initialState")
- testState := models.StateFrontend{
- Resources: []models.ResourceFrontend{
- {
- ID: "resource-1",
- Type: "node",
- Name: "node-1",
- DisplayName: "Node 1",
- PlatformID: "platform-1",
- PlatformType: "proxmox",
- SourceType: "pve",
- Status: "online",
- LastSeen: 1,
- },
- },
- ConnectedInfrastructure: []models.ConnectedInfrastructureItemFrontend{
- {
- ID: "resource-1",
- Name: "Node 1",
- Status: "active",
- Surfaces: []models.ConnectedInfrastructureSurfaceFrontend{
- {ID: "agent:host-1", Kind: "agent", Label: "Host telemetry"},
- },
- },
- },
- }
-
srv.hub.BroadcastState(testState)
canonicalPayload := readWebSocketMessageOfType(t, conn, "rawData")