2022-09-14 13:08:55 +00:00
|
|
|
package folders
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFindDirWithLeaf(t *testing.T) {
|
|
|
|
wd, err := os.Getwd()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-02-07 16:33:18 +00:00
|
|
|
root := filepath.Join(wd, "..", "..")
|
2022-09-14 13:08:55 +00:00
|
|
|
|
|
|
|
// Find from working directory should work.
|
|
|
|
{
|
|
|
|
out, err := FindDirWithLeaf(wd, ".git")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, out, root)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find from project root itself should work.
|
|
|
|
{
|
|
|
|
out, err := FindDirWithLeaf(root, ".git")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, out, root)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find for something that doesn't exist should work.
|
|
|
|
{
|
|
|
|
out, err := FindDirWithLeaf(root, "this-leaf-doesnt-exist-anywhere")
|
|
|
|
assert.ErrorIs(t, err, os.ErrNotExist)
|
|
|
|
assert.Equal(t, out, "")
|
|
|
|
}
|
|
|
|
}
|