From 8b5bb37019f13d191a8aee5b1e584824c40fe48f Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Mon, 9 Dec 2024 17:43:36 +0100 Subject: [PATCH] move leaf_test.go to info_test.go --- libs/git/info_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 libs/git/info_test.go diff --git a/libs/git/info_test.go b/libs/git/info_test.go new file mode 100644 index 000000000..129493587 --- /dev/null +++ b/libs/git/info_test.go @@ -0,0 +1,38 @@ +package git + +import ( + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestFindLeafInTree(t *testing.T) { + wd, err := os.Getwd() + require.NoError(t, err) + + root := filepath.Join(wd, "..", "..") + + // Find from working directory should work. + { + out, err := FindLeafInTree(wd, ".git") + assert.NoError(t, err) + assert.Equal(t, root, out) + } + + // Find from project root itself should work. + { + out, err := FindLeafInTree(root, ".git") + assert.NoError(t, err) + assert.Equal(t, root, out) + } + + // Find for something that doesn't exist should work. + { + out, err := FindLeafInTree(root, "this-leaf-doesnt-exist-anywhere") + assert.NoError(t, err) + assert.Equal(t, "", out) + } +}