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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Add unit tests for agentupdate utility functions
rcourtman28140707b153
diff --git a/internal/agentupdate/update_test.go b/internal/agentupdate/update_test.goindex c73a31a97e..3d0d09dc93 100644--- a/internal/agentupdate/update_test.go+++ b/internal/agentupdate/update_test.go@@ -5,232 +5,326 @@ import ("path/filepath""runtime""testing"+ "time"- "github.com/rcourtman/pulse-go-rewrite/internal/utils"+ "github.com/rs/zerolog")func TestDetermineArch(t *testing.T) {- arch := determineArch()+ // Test that determineArch returns a non-empty string on common platforms+ result := determineArch()- // Should return a non-empty string on known platforms- if runtime.GOOS == "linux" || runtime.GOOS == "darwin" || runtime.GOOS == "windows" {- if arch == "" {- t.Error("determineArch() returned empty string on known platform")+ // On known platforms, should return os-arch format+ switch runtime.GOOS {+ case "linux", "darwin", "windows":+ if result == "" {+ t.Errorf("determineArch() returned empty string on %s/%s", runtime.GOOS, runtime.GOARCH)}- // Should be in format "os-arch"- expected := runtime.GOOS + "-" + runtime.GOARCH- // Handle arm normalization- if runtime.GOARCH == "arm" {- expected = runtime.GOOS + "-armv7"+ // Should contain the OS+ if len(result) < len(runtime.GOOS) {+ t.Errorf("determineArch() = %q, expected to start with %s", result, runtime.GOOS)}- if arch != expected {- t.Logf("determineArch() = %q (expected %q, but platform-specific normalization may apply)", arch, expected)++ // Should be in format "os-arch"+ expectedPrefix := runtime.GOOS + "-"+ if result[:len(expectedPrefix)] != expectedPrefix {+ t.Errorf("determineArch() = %q, expected to start with %q", result, expectedPrefix)}}}-func TestVerifyBinaryMagic_ELF(t *testing.T) {- if runtime.GOOS != "linux" {- t.Skip("ELF test only runs on Linux")+func TestDetermineArch_Format(t *testing.T) {+ result := determineArch()+ if result == "" {+ t.Skip("determineArch returned empty string on this platform")}- // Create a temp file with valid ELF magic- tmpDir := t.TempDir()- validELF := filepath.Join(tmpDir, "valid-elf")- // ELF magic: 0x7f 'E' 'L' 'F' followed by some padding- err := os.WriteFile(validELF, []byte{0x7f, 'E', 'L', 'F', 0, 0, 0, 0}, 0644)- if err != nil {- t.Fatalf("failed to create test file: %v", err)+ // Result should contain a dash separating OS and arch+ found := false+ for i := 0; i < len(result); i++ {+ if result[i] == '-' {+ found = true+ break+ }}-- if err := verifyBinaryMagic(validELF); err != nil {- t.Errorf("verifyBinaryMagic() rejected valid ELF: %v", err)+ if !found {+ t.Errorf("determineArch() = %q, expected format os-arch with dash separator", result)}+}- // Create invalid file- invalidFile := filepath.Join(tmpDir, "invalid")- err = os.WriteFile(invalidFile, []byte("not an elf binary"), 0644)- if err != nil {- t.Fatalf("failed to create test file: %v", err)+func TestUnraidPersistentPath(t *testing.T) {+ tests := []struct {+ agentName string+ expected string+ }{+ {+ agentName: "pulse-agent",+ expected: "/boot/config/plugins/pulse-agent/pulse-agent",+ },+ {+ agentName: "pulse-docker-agent",+ expected: "/boot/config/plugins/pulse-docker-agent/pulse-docker-agent",+ },+ {+ agentName: "pulse-host-agent",+ expected: "/boot/config/plugins/pulse-host-agent/pulse-host-agent",+ },+ {+ agentName: "custom-agent",+ expected: "/boot/config/plugins/custom-agent/custom-agent",+ },+ {+ agentName: "",+ expected: "/boot/config/plugins//",+ },}- if err := verifyBinaryMagic(invalidFile); err == nil {- t.Error("verifyBinaryMagic() accepted invalid file")+ for _, tc := range tests {+ t.Run(tc.agentName, func(t *testing.T) {+ result := unraidPersistentPath(tc.agentName)+ if result != tc.expected {+ t.Errorf("unraidPersistentPath(%q) = %q, want %q", tc.agentName, result, tc.expected)+ }+ })}}-func TestVerifyBinaryMagic_PE(t *testing.T) {- if runtime.GOOS != "windows" {- t.Skip("PE test only runs on Windows")+func TestVerifyBinaryMagic_ELF(t *testing.T) {+ if runtime.GOOS != "linux" {+ t.Skip("ELF verification test only runs on Linux")}+ // Create a temp file with ELF magic bytestmpDir := t.TempDir()+ elfPath := filepath.Join(tmpDir, "test_elf")- // Create a temp file with valid PE magic (MZ)- validPE := filepath.Join(tmpDir, "valid.exe")- err := os.WriteFile(validPE, []byte{'M', 'Z', 0, 0, 0, 0, 0, 0}, 0644)+ // ELF magic: 0x7f 'E' 'L' 'F' followed by some data+ elfData := []byte{0x7f, 'E', 'L', 'F', 0x02, 0x01, 0x01, 0x00}+ if err := os.WriteFile(elfPath, elfData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)+ }++ err := verifyBinaryMagic(elfPath)if err != nil {- t.Fatalf("failed to create test file: %v", err)+ t.Errorf("verifyBinaryMagic() error = %v for valid ELF", err)}+}- if err := verifyBinaryMagic(validPE); err != nil {- t.Errorf("verifyBinaryMagic() rejected valid PE: %v", err)+func TestVerifyBinaryMagic_InvalidELF(t *testing.T) {+ if runtime.GOOS != "linux" {+ t.Skip("ELF verification test only runs on Linux")}- // Create invalid file- invalidFile := filepath.Join(tmpDir, "invalid.exe")- err = os.WriteFile(invalidFile, []byte("not a pe binary!"), 0644)- if err != nil {- t.Fatalf("failed to create test file: %v", err)+ tmpDir := t.TempDir()+ invalidPath := filepath.Join(tmpDir, "invalid")++ // Write invalid magic bytes+ invalidData := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}+ if err := os.WriteFile(invalidPath, invalidData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)}- if err := verifyBinaryMagic(invalidFile); err == nil {- t.Error("verifyBinaryMagic() accepted invalid file")+ err := verifyBinaryMagic(invalidPath)+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for invalid binary")}}-func TestVerifyBinaryMagic_MachO(t *testing.T) {+func TestVerifyBinaryMagic_MachO64(t *testing.T) {if runtime.GOOS != "darwin" {- t.Skip("Mach-O test only runs on macOS")+ t.Skip("Mach-O verification test only runs on macOS")}tmpDir := t.TempDir()+ machoPath := filepath.Join(tmpDir, "test_macho")++ // Mach-O 64-bit magic (little-endian): 0xcf 0xfa 0xed 0xfe+ machoData := []byte{0xcf, 0xfa, 0xed, 0xfe, 0x07, 0x00, 0x00, 0x01}+ if err := os.WriteFile(machoPath, machoData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)+ }- // Create a temp file with valid Mach-O 64-bit magic (little-endian)- validMachO := filepath.Join(tmpDir, "valid-macho")- err := os.WriteFile(validMachO, []byte{0xcf, 0xfa, 0xed, 0xfe, 0, 0, 0, 0}, 0644)+ err := verifyBinaryMagic(machoPath)if err != nil {- t.Fatalf("failed to create test file: %v", err)+ t.Errorf("verifyBinaryMagic() error = %v for valid Mach-O", err)+ }+}++func TestVerifyBinaryMagic_MachO32(t *testing.T) {+ if runtime.GOOS != "darwin" {+ t.Skip("Mach-O verification test only runs on macOS")}- if err := verifyBinaryMagic(validMachO); err != nil {- t.Errorf("verifyBinaryMagic() rejected valid Mach-O: %v", err)+ tmpDir := t.TempDir()+ machoPath := filepath.Join(tmpDir, "test_macho32")++ // Mach-O 32-bit magic (little-endian): 0xce 0xfa 0xed 0xfe+ machoData := []byte{0xce, 0xfa, 0xed, 0xfe, 0x07, 0x00, 0x00, 0x01}+ if err := os.WriteFile(machoPath, machoData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)}- // Test universal binary magic- universalMachO := filepath.Join(tmpDir, "universal-macho")- err = os.WriteFile(universalMachO, []byte{0xca, 0xfe, 0xba, 0xbe, 0, 0, 0, 0}, 0644)+ err := verifyBinaryMagic(machoPath)if err != nil {- t.Fatalf("failed to create test file: %v", err)+ t.Errorf("verifyBinaryMagic() error = %v for valid Mach-O 32-bit", err)}+}- if err := verifyBinaryMagic(universalMachO); err != nil {- t.Errorf("verifyBinaryMagic() rejected valid universal Mach-O: %v", err)+func TestVerifyBinaryMagic_MachOUniversal(t *testing.T) {+ if runtime.GOOS != "darwin" {+ t.Skip("Mach-O verification test only runs on macOS")}- // Create invalid file- invalidFile := filepath.Join(tmpDir, "invalid")- err = os.WriteFile(invalidFile, []byte("not a macho binary"), 0644)- if err != nil {- t.Fatalf("failed to create test file: %v", err)+ tmpDir := t.TempDir()+ machoPath := filepath.Join(tmpDir, "test_macho_fat")++ // Mach-O universal/fat binary magic: 0xca 0xfe 0xba 0xbe+ machoData := []byte{0xca, 0xfe, 0xba, 0xbe, 0x00, 0x00, 0x00, 0x02}+ if err := os.WriteFile(machoPath, machoData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)}- if err := verifyBinaryMagic(invalidFile); err == nil {- t.Error("verifyBinaryMagic() accepted invalid file")+ err := verifyBinaryMagic(machoPath)+ if err != nil {+ t.Errorf("verifyBinaryMagic() error = %v for valid Mach-O universal", err)}}-func TestVerifyBinaryMagic_TooShort(t *testing.T) {+func TestVerifyBinaryMagic_InvalidMachO(t *testing.T) {+ if runtime.GOOS != "darwin" {+ t.Skip("Mach-O verification test only runs on macOS")+ }+tmpDir := t.TempDir()+ invalidPath := filepath.Join(tmpDir, "invalid")- // Create a file that's too short to have magic bytes- shortFile := filepath.Join(tmpDir, "short")- err := os.WriteFile(shortFile, []byte{0x7f}, 0644)- if err != nil {- t.Fatalf("failed to create test file: %v", err)+ // Write invalid magic bytes+ invalidData := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}+ if err := os.WriteFile(invalidPath, invalidData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)}- if err := verifyBinaryMagic(shortFile); err == nil {- t.Error("verifyBinaryMagic() accepted file that's too short")+ err := verifyBinaryMagic(invalidPath)+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for invalid Mach-O binary")}}-func TestVerifyBinaryMagic_NonExistent(t *testing.T) {- if err := verifyBinaryMagic("/nonexistent/path/to/file"); err == nil {- t.Error("verifyBinaryMagic() accepted non-existent file")+func TestVerifyBinaryMagic_PE(t *testing.T) {+ if runtime.GOOS != "windows" {+ t.Skip("PE verification test only runs on Windows")}-}-func TestVerifyBinaryMagic_EmptyFile(t *testing.T) {tmpDir := t.TempDir()+ pePath := filepath.Join(tmpDir, "test_pe.exe")- emptyFile := filepath.Join(tmpDir, "empty")- err := os.WriteFile(emptyFile, []byte{}, 0644)- if err != nil {- t.Fatalf("failed to create test file: %v", err)+ // PE magic: 'M' 'Z'+ peData := []byte{'M', 'Z', 0x90, 0x00, 0x03, 0x00, 0x00, 0x00}+ if err := os.WriteFile(pePath, peData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)}- if err := verifyBinaryMagic(emptyFile); err == nil {- t.Error("verifyBinaryMagic() accepted empty file")+ err := verifyBinaryMagic(pePath)+ if err != nil {+ t.Errorf("verifyBinaryMagic() error = %v for valid PE", err)}}-func TestUnraidPersistentPath(t *testing.T) {- tests := []struct {- agentName string- expected string- }{- {"pulse-agent", "/boot/config/plugins/pulse-agent/pulse-agent"},- {"pulse-docker-agent", "/boot/config/plugins/pulse-docker-agent/pulse-docker-agent"},- {"custom-agent", "/boot/config/plugins/custom-agent/custom-agent"},+func TestVerifyBinaryMagic_InvalidPE(t *testing.T) {+ if runtime.GOOS != "windows" {+ t.Skip("PE verification test only runs on Windows")}- for _, tc := range tests {- t.Run(tc.agentName, func(t *testing.T) {- result := unraidPersistentPath(tc.agentName)- if result != tc.expected {- t.Errorf("unraidPersistentPath(%q) = %q, want %q", tc.agentName, result, tc.expected)- }- })+ tmpDir := t.TempDir()+ invalidPath := filepath.Join(tmpDir, "invalid.exe")++ // Write invalid magic bytes (not MZ)+ invalidData := []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}+ if err := os.WriteFile(invalidPath, invalidData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)+ }++ err := verifyBinaryMagic(invalidPath)+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for invalid PE binary")}}-func TestNewUpdater_Defaults(t *testing.T) {- cfg := Config{- PulseURL: "https://pulse.example.com",- APIToken: "test-token",- AgentName: "pulse-agent",- CurrentVersion: "1.0.0",+func TestVerifyBinaryMagic_NonexistentFile(t *testing.T) {+ err := verifyBinaryMagic("/nonexistent/path/to/binary")+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for nonexistent file")}+}- updater := New(cfg)+func TestVerifyBinaryMagic_TooShort(t *testing.T) {+ tmpDir := t.TempDir()+ shortPath := filepath.Join(tmpDir, "short")- if updater == nil {- t.Fatal("New() returned nil")+ // Write only 2 bytes (less than 4 required for magic)+ shortData := []byte{0x7f, 'E'}+ if err := os.WriteFile(shortPath, shortData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)+ }++ err := verifyBinaryMagic(shortPath)+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for file too short to read magic")}+}++func TestVerifyBinaryMagic_EmptyFile(t *testing.T) {+ tmpDir := t.TempDir()+ emptyPath := filepath.Join(tmpDir, "empty")- // Check default check interval is applied- if updater.cfg.CheckInterval != 1*60*60*1000000000 { // 1 hour in nanoseconds- t.Errorf("default CheckInterval not applied, got %v", updater.cfg.CheckInterval)+ // Write empty file+ if err := os.WriteFile(emptyPath, []byte{}, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)}- if updater.client == nil {- t.Error("http client is nil")+ err := verifyBinaryMagic(emptyPath)+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for empty file")}}-func TestNewUpdater_CustomInterval(t *testing.T) {- cfg := Config{- PulseURL: "https://pulse.example.com",- APIToken: "test-token",- AgentName: "pulse-agent",- CurrentVersion: "1.0.0",- CheckInterval: 30 * 60 * 1000000000, // 30 minutes in nanoseconds+func TestVerifyBinaryMagic_TextFile(t *testing.T) {+ // Skip on unknown platforms where verification is skipped+ switch runtime.GOOS {+ case "linux", "darwin", "windows":+ // continue with test+ default:+ t.Skip("Platform verification skipped on unknown OS")}- updater := New(cfg)+ tmpDir := t.TempDir()+ textPath := filepath.Join(tmpDir, "script.sh")++ // Write a shell script (not a binary)+ textData := []byte("#!/bin/bash\necho hello\n")+ if err := os.WriteFile(textPath, textData, 0644); err != nil {+ t.Fatalf("Failed to create test file: %v", err)+ }- if updater.cfg.CheckInterval != cfg.CheckInterval {- t.Errorf("custom CheckInterval not preserved, got %v", updater.cfg.CheckInterval)+ err := verifyBinaryMagic(textPath)+ if err == nil {+ t.Error("verifyBinaryMagic() expected error for text file")}}func TestIsUnraid(t *testing.T) {- // This test verifies the function doesn't panic- // Actual result depends on the system+ // isUnraid checks for /etc/unraid-version+ // On non-Unraid systems, this should return falseresult := isUnraid()- t.Logf("isUnraid() = %v (depends on test environment)", result)++ // Check if /etc/unraid-version exists+ _, err := os.Stat("/etc/unraid-version")+ expected := err == nil++ if result != expected {+ t.Errorf("isUnraid() = %v, want %v", result, expected)+ }}func TestConfig_Defaults(t *testing.T) {@@ -250,7 +344,7 @@ func TestConfig_Defaults(t *testing.T) {t.Error("CurrentVersion should be empty by default")}if cfg.CheckInterval != 0 {- t.Error("CheckInterval should be 0 by default")+ t.Error("CheckInterval should be zero by default")}if cfg.InsecureSkipVerify {t.Error("InsecureSkipVerify should be false by default")@@ -263,147 +357,114 @@ func TestConfig_Defaults(t *testing.T) {}}-func TestNewUpdater_InsecureSkipVerify(t *testing.T) {+func TestNew_DefaultCheckInterval(t *testing.T) {cfg := Config{- PulseURL: "https://pulse.example.com",- APIToken: "test-token",- AgentName: "pulse-agent",- CurrentVersion: "1.0.0",- InsecureSkipVerify: true,+ PulseURL: "https://pulse.example.com",+ APIToken: "test-token",+ AgentName: "pulse-agent",+ CurrentVersion: "1.0.0",+ // CheckInterval not set}updater := New(cfg)- if updater == nil {- t.Fatal("New() returned nil")- }-- if !updater.cfg.InsecureSkipVerify {- t.Error("InsecureSkipVerify should be true")+ // Should have defaulted to 1 hour+ if updater.cfg.CheckInterval != 1*time.Hour {+ t.Errorf("CheckInterval = %v, want 1h", updater.cfg.CheckInterval)}}-func TestNewUpdater_Disabled(t *testing.T) {+func TestNew_CustomCheckInterval(t *testing.T) {cfg := Config{PulseURL: "https://pulse.example.com",APIToken: "test-token",AgentName: "pulse-agent",CurrentVersion: "1.0.0",- Disabled: true,+ CheckInterval: 30 * time.Minute,}updater := New(cfg)- if updater == nil {- t.Fatal("New() returned nil")- }-- if !updater.cfg.Disabled {- t.Error("Disabled should be true")+ // Should preserve custom interval+ if updater.cfg.CheckInterval != 30*time.Minute {+ t.Errorf("CheckInterval = %v, want 30m", updater.cfg.CheckInterval)}}-func TestDetermineArch_KnownPlatforms(t *testing.T) {- arch := determineArch()-- // On known platforms, should return os-arch format- switch runtime.GOOS {- case "linux", "darwin", "windows":- if arch == "" {- t.Error("determineArch() should return non-empty string on known platforms")- }- // Should contain hyphen separating OS and arch- if len(arch) < 3 || arch[0] == '-' || arch[len(arch)-1] == '-' {- t.Errorf("determineArch() = %q, invalid format", arch)- }+func TestNew_WithLogger(t *testing.T) {+ logger := zerolog.Nop()+ cfg := Config{+ PulseURL: "https://pulse.example.com",+ APIToken: "test-token",+ AgentName: "pulse-agent",+ CurrentVersion: "1.0.0",+ Logger: &logger,}-}-func TestVerifyBinaryMagic_DirectoryFails(t *testing.T) {- tmpDir := t.TempDir()+ updater := New(cfg)- // Trying to verify a directory should fail- err := verifyBinaryMagic(tmpDir)- if err == nil {- t.Error("verifyBinaryMagic() should fail for directories")+ // Should not panic and should create valid updater+ if updater == nil {+ t.Error("New() returned nil")}}-func TestConstants(t *testing.T) {- // Verify constants are sensible- if maxBinarySize <= 0 {- t.Error("maxBinarySize should be positive")- }- if maxBinarySize < 1024*1024 {- t.Error("maxBinarySize should be at least 1MB")- }-- if downloadTimeout <= 0 {- t.Error("downloadTimeout should be positive")+func TestNew_NilLogger(t *testing.T) {+ cfg := Config{+ PulseURL: "https://pulse.example.com",+ APIToken: "test-token",+ AgentName: "pulse-agent",+ CurrentVersion: "1.0.0",+ Logger: nil,}-}-func TestSymlinkResolution(t *testing.T) {- // Test that filepath.EvalSymlinks works as expected for our use case- tmpDir := t.TempDir()+ updater := New(cfg)- // Create a real file- realFile := filepath.Join(tmpDir, "real", "binary")- if err := os.MkdirAll(filepath.Dir(realFile), 0755); err != nil {- t.Fatalf("failed to create dir: %v", err)- }- if err := os.WriteFile(realFile, []byte("test"), 0755); err != nil {- t.Fatalf("failed to create file: %v", err)+ // Should not panic and should create valid updater with nop logger+ if updater == nil {+ t.Error("New() returned nil")}+}- // Create a symlink to it- linkFile := filepath.Join(tmpDir, "link", "binary")- if err := os.MkdirAll(filepath.Dir(linkFile), 0755); err != nil {- t.Fatalf("failed to create link dir: %v", err)- }- if err := os.Symlink(realFile, linkFile); err != nil {- t.Fatalf("failed to create symlink: %v", err)+func TestNew_InsecureSkipVerify(t *testing.T) {+ cfg := Config{+ PulseURL: "https://pulse.example.com",+ APIToken: "test-token",+ AgentName: "pulse-agent",+ CurrentVersion: "1.0.0",+ InsecureSkipVerify: true,}- // EvalSymlinks should resolve to the real path- resolved, err := filepath.EvalSymlinks(linkFile)- if err != nil {- t.Fatalf("EvalSymlinks failed: %v", err)- }+ updater := New(cfg)- // Normalize realFile in case tmpDir itself contains symlinks (e.g. /var -> /private/var on macOS)- realFileResolved, err := filepath.EvalSymlinks(realFile)- if err != nil {- t.Fatalf("EvalSymlinks on realFile failed: %v", err)+ if !updater.cfg.InsecureSkipVerify {+ t.Error("InsecureSkipVerify should be true")}+}- if resolved != realFileResolved {- t.Errorf("EvalSymlinks(%q) = %q, want %q", linkFile, resolved, realFileResolved)+func TestNew_ClientNotNil(t *testing.T) {+ cfg := Config{+ PulseURL: "https://pulse.example.com",+ APIToken: "test-token",+ AgentName: "pulse-agent",+ CurrentVersion: "1.0.0",}- // Verify temp file in same dir as resolved path allows rename- targetDir := filepath.Dir(resolved)- tmpFile, err := os.CreateTemp(targetDir, "test-*.tmp")- if err != nil {- t.Fatalf("failed to create temp file: %v", err)- }- tmpPath := tmpFile.Name()- tmpFile.Close()- defer os.Remove(tmpPath)+ updater := New(cfg)- // Rename should work since both files are on the same filesystem- newPath := filepath.Join(targetDir, "renamed")- if err := os.Rename(tmpPath, newPath); err != nil {- t.Errorf("Rename failed (same filesystem): %v", err)+ if updater.client == nil {+ t.Error("client should not be nil")}- os.Remove(newPath)}-func TestNormalizeVersion(t *testing.T) {- if got := utils.NormalizeVersion("v4.33.1"); got != "4.33.1" {- t.Errorf("NormalizeVersion(%q) = %q, want %q", "v4.33.1", got, "4.33.1")+func TestConstants(t *testing.T) {+ // Verify maxBinarySize is reasonable (100 MB)+ if maxBinarySize != 100*1024*1024 {+ t.Errorf("maxBinarySize = %d, want %d", maxBinarySize, 100*1024*1024)}- if got := utils.NormalizeVersion("4.33.1"); got != "4.33.1" {- t.Errorf("NormalizeVersion(%q) = %q, want %q", "4.33.1", got, "4.33.1")++ // Verify downloadTimeout is reasonable (5 minutes)+ if downloadTimeout != 5*time.Minute {+ t.Errorf("downloadTimeout = %v, want 5m", downloadTimeout)}}