2016-05-15 22:12:55 +00:00
|
|
|
package which_test
|
|
|
|
|
|
|
|
import (
|
2023-10-12 11:34:50 +00:00
|
|
|
"testing"
|
2016-05-15 22:12:55 +00:00
|
|
|
|
2023-10-12 11:34:50 +00:00
|
|
|
. "github.com/Luzifer/go_helpers/v2/which"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2016-05-15 22:12:55 +00:00
|
|
|
)
|
|
|
|
|
2023-10-12 11:34:50 +00:00
|
|
|
func TestFindInDirectory(t *testing.T) {
|
|
|
|
found, err := FindInDirectory("bash", "/bin")
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.True(t, found)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFindInPath(t *testing.T) {
|
|
|
|
// Searching bash on the system
|
|
|
|
result, err := FindInPath("bash")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Greater(t, len(result), 0)
|
|
|
|
|
|
|
|
// Searching a non existent file
|
|
|
|
_, err = FindInPath("dfqoiwurgtqi3uegrds")
|
|
|
|
assert.ErrorIs(t, err, ErrBinaryNotFound)
|
|
|
|
|
|
|
|
// Searching an empty file
|
|
|
|
_, err = FindInPath("")
|
|
|
|
assert.ErrorIs(t, err, ErrNoSearchSpecified)
|
|
|
|
}
|