Skip to content

Commit

Permalink
Fixed path joining in FindFilesWithSuffixInPath (databricks#704)
Browse files Browse the repository at this point in the history
## Changes
Fixes databricks#693

## Tests
Newly added tests failed before the fix:
https://github.com/databricks/cli/actions/runs/6000754026/job/16273507998?pr=704

Signed-off-by: Arpit Jasapara <arpit.jasapara@databricks.com>
  • Loading branch information
andrewnester authored and arpitjasa-db committed Sep 7, 2023
1 parent a0cecc8 commit 2f885bd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
8 changes: 4 additions & 4 deletions python/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ package python
import (
"context"
"os"
"path"
"path/filepath"
"strings"

"github.com/databricks/cli/libs/log"
)

func CleanupWheelFolder(dir string) {
// there or not there - we don't care
os.RemoveAll(path.Join(dir, "__pycache__"))
os.RemoveAll(path.Join(dir, "build"))
os.RemoveAll(filepath.Join(dir, "__pycache__"))
os.RemoveAll(filepath.Join(dir, "build"))
eggInfo := FindFilesWithSuffixInPath(dir, ".egg-info")
if len(eggInfo) == 0 {
return
Expand Down Expand Up @@ -42,7 +42,7 @@ func FindFilesWithSuffixInPath(dir, suffix string) []string {
if !strings.HasSuffix(child.Name(), suffix) {
continue
}
files = append(files, path.Join(dir, child.Name()))
files = append(files, filepath.Join(dir, child.Name()))
}
return files
}
21 changes: 21 additions & 0 deletions python/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package python

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestFindFilesWithSuffixInPath(t *testing.T) {
dir, err := os.Getwd()
require.NoError(t, err)

files := FindFilesWithSuffixInPath(dir, "test.go")

matches, err := filepath.Glob(filepath.Join(dir, "*test.go"))
require.NoError(t, err)

require.ElementsMatch(t, files, matches)
}

0 comments on commit 2f885bd

Please sign in to comment.