From 89fc14059e256895442ff88ac64c916995bcd7a0 Mon Sep 17 00:00:00 2001 From: Murat Topcu Date: Sun, 6 Sep 2026 12:30:47 +0300 Subject: [PATCH] selfupdate: fix TestInstallOnLinux panicking when the build is the latest beta The test asks InstallUpdate to install the latest beta into an unwritable file and expects an error. When the binary under test reports exactly the latest beta version (as make quicktest does right after a beta is published from the same commit), InstallUpdate correctly decides there is nothing to do and returns nil, and the test then dereferences the nil error and panics. Pin fs.Version to a fixed old value for the duration of the test so an update is always attempted, and use require.Error so a missing error fails the test instead of crashing it. --- cmd/selfupdate/selfupdate_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/selfupdate/selfupdate_test.go b/cmd/selfupdate/selfupdate_test.go index 263f8049c..3c22ee6ef 100644 --- a/cmd/selfupdate/selfupdate_test.go +++ b/cmd/selfupdate/selfupdate_test.go @@ -56,6 +56,12 @@ func TestInstallOnLinux(t *testing.T) { testDir := t.TempDir() path := filepath.Join(testDir, "rclone") + // Pin the running version so the checks below do not depend on + // whether this build happens to be the latest beta. + oldVersion := fs.Version + fs.Version = "v1.0.0" + t.Cleanup(func() { fs.Version = oldVersion }) + regexVer := regexp.MustCompile(`v[0-9]\S+`) betaVer, _, err := GetVersion(ctx, true, "") @@ -71,7 +77,7 @@ func TestInstallOnLinux(t *testing.T) { _ = os.Chmod(path, 0644) }() err = (InstallUpdate(ctx, &Options{Beta: true, Output: path})) - assert.Error(t, err) + require.Error(t, err) assert.Contains(t, err.Error(), "run self-update as root") // Must keep non-standard permissions