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.

Test that mock mode records no history-read day

rcourtmanfb61c2a94395
diff --git a/internal/api/agent_activity_telemetry_test.go b/internal/api/agent_activity_telemetry_test.go
index 1f2f612e20..7f461cea3a 100644
--- a/internal/api/agent_activity_telemetry_test.go
+++ b/internal/api/agent_activity_telemetry_test.go
@@ -10,6 +10,7 @@ import (
"github.com/rcourtman/pulse-go-rewrite/internal/agentcapabilities"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
+ "github.com/rcourtman/pulse-go-rewrite/internal/mock"
)
func TestRecordExternalAgentCapabilityActivityUsesCapabilityScope(t *testing.T) {
@@ -272,6 +273,34 @@ func TestHistoryReadDayRecordedOnlyAfterSuccessfulRead(t *testing.T) {
}
}
+// Mock and demo installs serve generated fleets, so their history reads say
+// nothing about whether a real fleet's history was useful.
+func TestHistoryReadDayNotRecordedInMockMode(t *testing.T) {
+ previous := mock.IsMockEnabled()
+ if err := mock.SetEnabled(true); err != nil {
+ t.Fatalf("enable mock mode: %v", err)
+ }
+ t.Cleanup(func() { _ = mock.SetEnabled(previous) })
+
+ persistence := config.NewConfigPersistence(t.TempDir())
+ handler := (&Router{persistence: persistence}).withExternalAgentCapabilityActivity(agentcapabilities.ListRecentChangesCapabilityName, func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ })
+ req := httptest.NewRequest(http.MethodGet, "/api/agent/changes", nil)
+ attachAPITokenRecord(req, &config.APITokenRecord{Scopes: []string{config.ScopeMonitoringRead}})
+ handler(httptest.NewRecorder(), req)
+
+ history, err := persistence.LoadExternalAgentActivityHistory()
+ if err != nil {
+ t.Fatalf("LoadExternalAgentActivityHistory: %v", err)
+ }
+ for _, event := range history.Events {
+ if event.Activity == config.ExternalAgentActivityHistoryRead {
+ t.Fatalf("mock mode recorded a history-read marker: %+v", event)
+ }
+ }
+}
+
// Install telemetry reads only the root persistence, so a history read served
// for another organization must still leave its day marker there.
func TestHistoryReadDayFromAnotherOrganizationReachesInstallTelemetry(t *testing.T) {