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.

Make native-agent test fixtures path-portable on Windows

rcourtmanebb08e0de20c
diff --git a/internal/dockeragent/registry_credentials_test.go b/internal/dockeragent/registry_credentials_test.go
index a24ab5cba9..9ee5531299 100644
--- a/internal/dockeragent/registry_credentials_test.go
+++ b/internal/dockeragent/registry_credentials_test.go
@@ -7,6 +7,7 @@ import (
"fmt"
"net/http"
"os"
+ "path/filepath"
"strings"
"testing"
"time"
@@ -35,18 +36,30 @@ func basicAuthValue(username, secret string) string {
}
func newTestCredentialStore(files map[string]string, env map[string]string) *dockerConfigCredentials {
+ nativeFiles := make(map[string]string, len(files))
+ for path, content := range files {
+ nativeFiles[filepath.FromSlash(path)] = content
+ }
+ nativeEnv := make(map[string]string, len(env))
+ for key, value := range env {
+ switch key {
+ case "HOME", "DOCKER_CONFIG", "REGISTRY_AUTH_FILE", "XDG_RUNTIME_DIR":
+ value = filepath.FromSlash(value)
+ }
+ nativeEnv[key] = value
+ }
c := &dockerConfigCredentials{
logger: zerolog.Nop(),
cache: map[string]credentialCacheEntry{},
- getenv: func(key string) string { return env[key] },
+ getenv: func(key string) string { return nativeEnv[key] },
homeDir: func() (string, error) {
- if home, ok := env["HOME"]; ok {
+ if home, ok := nativeEnv["HOME"]; ok {
return home, nil
}
return "", errors.New("no home")
},
readFile: func(path string) ([]byte, error) {
- if content, ok := files[path]; ok {
+ if content, ok := nativeFiles[path]; ok {
return []byte(content), nil
}
return nil, os.ErrNotExist
@@ -272,7 +285,7 @@ func TestDockerConfigCredentials_CacheAvoidsRepeatResolution(t *testing.T) {
store := newTestCredentialStore(nil, map[string]string{"HOME": "/home/agent"})
store.readFile = func(path string) ([]byte, error) {
reads++
- if path == "/home/agent/.docker/config.json" {
+ if path == filepath.FromSlash("/home/agent/.docker/config.json") {
return []byte(fmt.Sprintf(`{"auths":{"registry.example.com":{"auth":%q}}}`, auth)), nil
}
return nil, os.ErrNotExist
diff --git a/internal/hostagent/privilege_test.go b/internal/hostagent/privilege_test.go
index 36d9ad7265..4e999f33c1 100644
--- a/internal/hostagent/privilege_test.go
+++ b/internal/hostagent/privilege_test.go
@@ -2,6 +2,7 @@ package hostagent
import (
"os"
+ "path/filepath"
"testing"
)
@@ -35,7 +36,8 @@ func TestCollectPrivilegeStatusReportsHelperOverrides(t *testing.T) {
}
func TestResolvePctPathHonorsAbsoluteOverride(t *testing.T) {
- t.Setenv("PULSE_PCT_PATH", "/usr/local/lib/pulse-agent/pct-helper")
+ override := filepath.Join(t.TempDir(), "pct-helper")
+ t.Setenv("PULSE_PCT_PATH", override)
resolved, err := resolvePctPath(func(string) (string, error) {
t.Fatal("lookPath must not be consulted when the override is set")
@@ -44,7 +46,7 @@ func TestResolvePctPathHonorsAbsoluteOverride(t *testing.T) {
if err != nil {
t.Fatalf("resolvePctPath: %v", err)
}
- if resolved != "/usr/local/lib/pulse-agent/pct-helper" {
+ if resolved != override {
t.Fatalf("resolved = %q", resolved)
}
}