github.com/databricks/cli@v0.203.0/folders/folders_test.go (about)

     1  package folders
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/stretchr/testify/assert"
     9  	"github.com/stretchr/testify/require"
    10  )
    11  
    12  func TestFindDirWithLeaf(t *testing.T) {
    13  	wd, err := os.Getwd()
    14  	require.NoError(t, err)
    15  
    16  	root := filepath.Join(wd, "..")
    17  
    18  	// Find from working directory should work.
    19  	{
    20  		out, err := FindDirWithLeaf(wd, ".git")
    21  		assert.NoError(t, err)
    22  		assert.Equal(t, out, root)
    23  	}
    24  
    25  	// Find from project root itself should work.
    26  	{
    27  		out, err := FindDirWithLeaf(root, ".git")
    28  		assert.NoError(t, err)
    29  		assert.Equal(t, out, root)
    30  	}
    31  
    32  	// Find for something that doesn't exist should work.
    33  	{
    34  		out, err := FindDirWithLeaf(root, "this-leaf-doesnt-exist-anywhere")
    35  		assert.ErrorIs(t, err, os.ErrNotExist)
    36  		assert.Equal(t, out, "")
    37  	}
    38  }