Files
pulse/internal/monitoring/mock_mode_config_test.go
T
pulse-triage[bot] 13984070ff Keep Proxmox recovery authentication within its caller budget
Carry cancellation through PVE/PBS construction, cluster probes and retained sessions, startup retries and port fallback. Preserve prior health/errors on caller termination; accepted clients retain independent ordinary reads and full timeouts. Cover real pinned HTTPS cancellation, deadlines, form fallback and first-poll publication.

Contract-Neutral: Restore existing caller cancellation and usable-session guarantees; no wire/API schema, agent lifecycle, TLS trust, guest safety, polling cadence or History contract delta.
Change-source: pulse-maintainer
2026-10-14 03:18:40 +01:00

103 lines
2.7 KiB
Go

package monitoring
import (
"context"
"testing"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
"github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"
)
func TestKeepRealPollingInMockMode(t *testing.T) {
t.Run("default_false", func(t *testing.T) {
t.Setenv(mockKeepRealPollingEnv, "")
if keepRealPollingInMockMode() {
t.Fatal("expected default behavior to disable real polling in mock mode")
}
})
t.Run("explicit_false", func(t *testing.T) {
t.Setenv(mockKeepRealPollingEnv, "false")
if keepRealPollingInMockMode() {
t.Fatal("expected false override to disable real polling in mock mode")
}
})
t.Run("explicit_true", func(t *testing.T) {
t.Setenv(mockKeepRealPollingEnv, "true")
if !keepRealPollingInMockMode() {
t.Fatal("expected true override to keep real polling in mock mode")
}
})
}
func TestNew_MockModeClientInitializationRespectsKeepRealPollingSetting(t *testing.T) {
makeConfig := func(dataPath string) *config.Config {
return &config.Config{
DataPath: dataPath,
PVEInstances: []config.PVEInstance{
{
Name: "pve-test",
Host: "https://127.0.0.1:8006",
User: "root@pam",
Password: "secret",
},
},
}
}
withClientStub := func(t *testing.T, fn func(called *bool)) {
t.Helper()
orig := newProxmoxClientFunc
t.Cleanup(func() { newProxmoxClientFunc = orig })
called := false
newProxmoxClientFunc = func(_ context.Context, cfg proxmox.ClientConfig) (PVEClientInterface, error) {
called = true
return &mockPVEClient{}, nil
}
fn(&called)
}
t.Run("disabled_by_default", func(t *testing.T) {
t.Setenv(mockKeepRealPollingEnv, "")
mustSetMockEnabled(t, true)
t.Cleanup(func() { mustSetMockEnabled(t, false) })
withClientStub(t, func(called *bool) {
monitor, err := New(makeConfig(t.TempDir()))
if err != nil {
t.Fatalf("New() returned error: %v", err)
}
t.Cleanup(func() { monitor.Stop() })
if *called {
t.Fatal("expected PVE client initialization to be skipped in mock mode by default")
}
if len(monitor.pveClients) != 0 {
t.Fatalf("expected 0 initialized PVE clients, got %d", len(monitor.pveClients))
}
})
})
t.Run("disabled_via_env", func(t *testing.T) {
t.Setenv(mockKeepRealPollingEnv, "false")
mustSetMockEnabled(t, true)
t.Cleanup(func() { mustSetMockEnabled(t, false) })
withClientStub(t, func(called *bool) {
monitor, err := New(makeConfig(t.TempDir()))
if err != nil {
t.Fatalf("New() returned error: %v", err)
}
t.Cleanup(func() { monitor.Stop() })
if *called {
t.Fatal("expected PVE client initialization to be skipped when override is false")
}
if len(monitor.pveClients) != 0 {
t.Fatalf("expected 0 initialized PVE clients, got %d", len(monitor.pveClients))
}
})
})
}