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.
This commit is contained in:
Murat Topcu
2026-09-08 17:16:06 +01:00
committed by Nick Craig-Wood
parent 03783be7a5
commit 89fc14059e
+7 -1
View File
@@ -56,6 +56,12 @@ func TestInstallOnLinux(t *testing.T) {
testDir := t.TempDir() testDir := t.TempDir()
path := filepath.Join(testDir, "rclone") 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+`) regexVer := regexp.MustCompile(`v[0-9]\S+`)
betaVer, _, err := GetVersion(ctx, true, "") betaVer, _, err := GetVersion(ctx, true, "")
@@ -71,7 +77,7 @@ func TestInstallOnLinux(t *testing.T) {
_ = os.Chmod(path, 0644) _ = os.Chmod(path, 0644)
}() }()
err = (InstallUpdate(ctx, &Options{Beta: true, Output: path})) 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") assert.Contains(t, err.Error(), "run self-update as root")
// Must keep non-standard permissions // Must keep non-standard permissions