mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-09-10 02:25:56 +00:00
fix: env overrides and OS-aware test improvements
- Add PBS/PMG polling interval environment variable overrides in config.go - Fix temp path expectation in detect_root_test.go using filepath.Join - Use EvalSymlinks for symlink target comparison in self_update_test.go - Add Linux-only skip for MAC fallback test in agent_new_test.go - Add OS-aware RAID/SMART assertions in agent_metrics_test.go
This commit is contained in:
@@ -830,6 +830,50 @@ func Load() (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if intervalStr := utils.GetenvTrim("PBS_POLLING_INTERVAL"); intervalStr != "" {
|
||||
if dur, err := time.ParseDuration(intervalStr); err == nil {
|
||||
if dur < 10*time.Second {
|
||||
log.Warn().Dur("interval", dur).Msg("Ignoring PBS_POLLING_INTERVAL below 10s from environment")
|
||||
} else {
|
||||
cfg.PBSPollingInterval = dur
|
||||
cfg.EnvOverrides["PBS_POLLING_INTERVAL"] = true
|
||||
log.Info().Dur("interval", dur).Msg("Overriding PBS polling interval from environment")
|
||||
}
|
||||
} else if seconds, err := strconv.Atoi(intervalStr); err == nil {
|
||||
if seconds < 10 {
|
||||
log.Warn().Int("seconds", seconds).Msg("Ignoring PBS_POLLING_INTERVAL below 10s from environment")
|
||||
} else {
|
||||
cfg.PBSPollingInterval = time.Duration(seconds) * time.Second
|
||||
cfg.EnvOverrides["PBS_POLLING_INTERVAL"] = true
|
||||
log.Info().Int("seconds", seconds).Msg("Overriding PBS polling interval (seconds) from environment")
|
||||
}
|
||||
} else {
|
||||
log.Warn().Str("value", intervalStr).Msg("Invalid PBS_POLLING_INTERVAL value, expected duration or seconds")
|
||||
}
|
||||
}
|
||||
|
||||
if intervalStr := utils.GetenvTrim("PMG_POLLING_INTERVAL"); intervalStr != "" {
|
||||
if dur, err := time.ParseDuration(intervalStr); err == nil {
|
||||
if dur < 10*time.Second {
|
||||
log.Warn().Dur("interval", dur).Msg("Ignoring PMG_POLLING_INTERVAL below 10s from environment")
|
||||
} else {
|
||||
cfg.PMGPollingInterval = dur
|
||||
cfg.EnvOverrides["PMG_POLLING_INTERVAL"] = true
|
||||
log.Info().Dur("interval", dur).Msg("Overriding PMG polling interval from environment")
|
||||
}
|
||||
} else if seconds, err := strconv.Atoi(intervalStr); err == nil {
|
||||
if seconds < 10 {
|
||||
log.Warn().Int("seconds", seconds).Msg("Ignoring PMG_POLLING_INTERVAL below 10s from environment")
|
||||
} else {
|
||||
cfg.PMGPollingInterval = time.Duration(seconds) * time.Second
|
||||
cfg.EnvOverrides["PMG_POLLING_INTERVAL"] = true
|
||||
log.Info().Int("seconds", seconds).Msg("Overriding PMG polling interval (seconds) from environment")
|
||||
}
|
||||
} else {
|
||||
log.Warn().Str("value", intervalStr).Msg("Invalid PMG_POLLING_INTERVAL value, expected duration or seconds")
|
||||
}
|
||||
}
|
||||
|
||||
if enabledStr := utils.GetenvTrim("ENABLE_TEMPERATURE_MONITORING"); enabledStr != "" {
|
||||
if enabled, err := strconv.ParseBool(enabledStr); err == nil {
|
||||
cfg.TemperatureMonitoringEnabled = enabled
|
||||
|
||||
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -93,7 +94,7 @@ func TestDetectAppRoot_Scenarios(t *testing.T) {
|
||||
name: "Executable in temp, getwd error",
|
||||
mockExec: os.TempDir() + "/go-build123/exe",
|
||||
mockGetwdErr: os.ErrPermission,
|
||||
expectedResult: os.TempDir() + "/go-build123", // Falls back to exe dir
|
||||
expectedResult: filepath.Join(os.TempDir(), "go-build123"), // Falls back to exe dir
|
||||
},
|
||||
{
|
||||
name: "Executable error, getwd error",
|
||||
|
||||
@@ -99,8 +99,12 @@ func TestResolveSymlink(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if got != target {
|
||||
t.Fatalf("expected %q, got %q", target, got)
|
||||
expected, err := filepath.EvalSymlinks(target)
|
||||
if err != nil {
|
||||
t.Fatalf("eval symlinks target: %v", err)
|
||||
}
|
||||
if got != expected {
|
||||
t.Fatalf("expected %q, got %q", expected, got)
|
||||
}
|
||||
|
||||
if _, err := resolveSymlink(filepath.Join(dir, "missing")); err == nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package hostagent
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -184,6 +185,12 @@ func TestBuildReport(t *testing.T) {
|
||||
t.Fatalf("buildReport failed: %v", err)
|
||||
}
|
||||
|
||||
if runtime.GOOS != "linux" {
|
||||
if len(report.RAID) != 0 {
|
||||
t.Errorf("Expected no RAID arrays on %s, got %d", runtime.GOOS, len(report.RAID))
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(report.RAID) != 1 {
|
||||
t.Errorf("Expected 1 RAID array, got %d", len(report.RAID))
|
||||
} else if report.RAID[0].Name != "md0" {
|
||||
@@ -270,6 +277,12 @@ func TestBuildReport(t *testing.T) {
|
||||
}
|
||||
|
||||
// SMART data is attached to Sensors in the report
|
||||
if runtime.GOOS != "linux" {
|
||||
if len(report.Sensors.SMART) != 0 {
|
||||
t.Errorf("Expected no SMART disks on %s, got %d", runtime.GOOS, len(report.Sensors.SMART))
|
||||
}
|
||||
return
|
||||
}
|
||||
if len(report.Sensors.SMART) != 1 {
|
||||
t.Errorf("Expected 1 SMART disk, got %d", len(report.Sensors.SMART))
|
||||
} else {
|
||||
|
||||
@@ -172,6 +172,10 @@ func TestNew_FallsBackToHostnameWhenMachineIDAndMACEmpty(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNew_FallsBackToMACWhenMachineIDEmpty(t *testing.T) {
|
||||
if runtime.GOOS != "linux" {
|
||||
t.Skip("MAC fallback is Linux-only")
|
||||
}
|
||||
|
||||
originalHostInfo := hostInfoWithContext
|
||||
originalReadFile := readFile
|
||||
originalNetInterfaces := netInterfaces
|
||||
|
||||
Reference in New Issue
Block a user