1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-26 14:01:20 +00:00
go_helpers/which/which_test.go

31 lines
691 B
Go
Raw Normal View History

package which_test
import (
"testing"
. "github.com/Luzifer/go_helpers/v2/which"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
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)
}