Maybe this

This commit is contained in:
Justin Hawkins 2023-11-28 20:24:18 +10:30
parent b0048a5764
commit a66ab08431

View File

@ -2,6 +2,7 @@ package download
import ( import (
"os" "os"
"os/exec"
"strings" "strings"
"sync" "sync"
"testing" "testing"
@ -364,26 +365,28 @@ Deleting original file The Greatest Shot In Television [2WoDQBhJCVQ].f140.m4a (p
} }
func TestLookForExecutable(t *testing.T) { func TestLookForExecutable(t *testing.T) {
cmdPath, err := exec.LookPath("sleep")
if err != nil {
t.Errorf("cannot run this test without knowing about sleep: %s", err)
t.FailNow()
}
cmd := "sleep" cmd := "sleep"
path, err := absPathToExecutable(cmd) path, err := absPathToExecutable(cmd)
if assert.NoError(t, err) { if assert.NoError(t, err) {
if path != "/bin/sleep" && path != "/usr/bin/sleep" { assert.Equal(t, cmdPath, path)
t.Errorf("bad path: %s", path)
}
} }
cmd = "/bin/sleep" cmd = "/bin/sleep"
path, err = absPathToExecutable(cmd) path, err = absPathToExecutable(cmd)
if assert.NoError(t, err) { if assert.NoError(t, err) {
if path != "/bin/sleep" && path != "/usr/bin/sleep" { assert.Equal(t, cmdPath, path)
t.Errorf("bad path: %s", path)
} }
}
cmd = "../../../../../bin/sleep" cmd = "../../../../.." + cmdPath
path, err = absPathToExecutable(cmd) path, err = absPathToExecutable(cmd)
if assert.NoError(t, err) { if assert.NoError(t, err) {
if path != "/bin/sleep" && path != "/usr/bin/sleep" { assert.Equal(t, cmdPath, path)
t.Errorf("bad path: %s", path)
}
} }
cmd = "./sleep" cmd = "./sleep"
_, err = absPathToExecutable(cmd) _, err = absPathToExecutable(cmd)
@ -393,9 +396,7 @@ func TestLookForExecutable(t *testing.T) {
cmd = "./sleep" cmd = "./sleep"
path, err = absPathToExecutable(cmd) path, err = absPathToExecutable(cmd)
if assert.NoError(t, err) { if assert.NoError(t, err) {
if path != "/bin/sleep" && path != "/usr/bin/sleep" { assert.Equal(t, cmdPath, path)
t.Errorf("bad path: %s", path)
}
} }
} }