Break out all the executable-finding guff and add some tests

This commit is contained in:
2023-11-28 20:07:17 +10:30
parent aa64e000ee
commit 73833a1a14
2 changed files with 55 additions and 3 deletions

View File

@@ -1,11 +1,13 @@
package download
import (
"os"
"strings"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/tardisx/gropple/config"
)
@@ -360,3 +362,32 @@ Deleting original file The Greatest Shot In Television [2WoDQBhJCVQ].f140.m4a (p
}
}
func TestLookForExecutable(t *testing.T) {
cmd := "sleep"
path, err := absPathToExecutable(cmd)
if assert.NoError(t, err) {
assert.Equal(t, path, "/bin/sleep")
}
cmd = "/bin/sleep"
path, err = absPathToExecutable(cmd)
if assert.NoError(t, err) {
assert.Equal(t, path, "/bin/sleep")
}
cmd = "../../../../../bin/sleep"
path, err = absPathToExecutable(cmd)
if assert.NoError(t, err) {
assert.Equal(t, path, "/bin/sleep")
}
cmd = "./sleep"
_, err = absPathToExecutable(cmd)
assert.Error(t, err)
os.Chdir("/bin")
cmd = "./sleep"
path, err = absPathToExecutable(cmd)
if assert.NoError(t, err) {
assert.Equal(t, path, "/bin/sleep")
}
}