From 7fd49fb54a3f37f71b99c3f6b7124f7516f47b8b Mon Sep 17 00:00:00 2001 From: rcourtman Date: Wed, 26 Nov 2025 14:37:01 +0000 Subject: [PATCH] test: add additional tests for internal/agentupdate Add 6 tests covering: - Config struct zero value defaults - NewUpdater with InsecureSkipVerify option - NewUpdater with Disabled option - determineArch format validation - verifyBinaryMagic on directories - Package constants validation --- internal/agentupdate/update_test.go | 110 ++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/internal/agentupdate/update_test.go b/internal/agentupdate/update_test.go index 06b32ad..6f09879 100644 --- a/internal/agentupdate/update_test.go +++ b/internal/agentupdate/update_test.go @@ -230,3 +230,113 @@ func TestIsUnraid(t *testing.T) { result := isUnraid() t.Logf("isUnraid() = %v (depends on test environment)", result) } + +func TestConfig_Defaults(t *testing.T) { + cfg := Config{} + + // Verify zero values + if cfg.PulseURL != "" { + t.Error("PulseURL should be empty by default") + } + if cfg.APIToken != "" { + t.Error("APIToken should be empty by default") + } + if cfg.AgentName != "" { + t.Error("AgentName should be empty by default") + } + if cfg.CurrentVersion != "" { + t.Error("CurrentVersion should be empty by default") + } + if cfg.CheckInterval != 0 { + t.Error("CheckInterval should be 0 by default") + } + if cfg.InsecureSkipVerify { + t.Error("InsecureSkipVerify should be false by default") + } + if cfg.Logger != nil { + t.Error("Logger should be nil by default") + } + if cfg.Disabled { + t.Error("Disabled should be false by default") + } +} + +func TestNewUpdater_InsecureSkipVerify(t *testing.T) { + cfg := Config{ + PulseURL: "https://pulse.example.com", + APIToken: "test-token", + AgentName: "pulse-agent", + CurrentVersion: "1.0.0", + InsecureSkipVerify: true, + } + + updater := New(cfg) + + if updater == nil { + t.Fatal("New() returned nil") + } + + if !updater.cfg.InsecureSkipVerify { + t.Error("InsecureSkipVerify should be true") + } +} + +func TestNewUpdater_Disabled(t *testing.T) { + cfg := Config{ + PulseURL: "https://pulse.example.com", + APIToken: "test-token", + AgentName: "pulse-agent", + CurrentVersion: "1.0.0", + Disabled: true, + } + + updater := New(cfg) + + if updater == nil { + t.Fatal("New() returned nil") + } + + if !updater.cfg.Disabled { + t.Error("Disabled should be true") + } +} + +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 TestVerifyBinaryMagic_DirectoryFails(t *testing.T) { + tmpDir := t.TempDir() + + // Trying to verify a directory should fail + err := verifyBinaryMagic(tmpDir) + if err == nil { + t.Error("verifyBinaryMagic() should fail for directories") + } +} + +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") + } +}