Fixed path joining in FindFilesWithSuffixInPath (#704)

## Changes
Fixes #693 

## Tests
Newly added tests failed before the fix:
https://github.com/databricks/cli/actions/runs/6000754026/job/16273507998?pr=704
This commit is contained in:
Andrew Nester 2023-08-29 10:26:26 +02:00 committed by GitHub
parent 842cd8b7ae
commit 3f2cf3c6b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View File

@ -5,7 +5,7 @@ package python
import ( import (
"context" "context"
"os" "os"
"path" "path/filepath"
"strings" "strings"
"github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/log"
@ -13,8 +13,8 @@ import (
func CleanupWheelFolder(dir string) { func CleanupWheelFolder(dir string) {
// there or not there - we don't care // there or not there - we don't care
os.RemoveAll(path.Join(dir, "__pycache__")) os.RemoveAll(filepath.Join(dir, "__pycache__"))
os.RemoveAll(path.Join(dir, "build")) os.RemoveAll(filepath.Join(dir, "build"))
eggInfo := FindFilesWithSuffixInPath(dir, ".egg-info") eggInfo := FindFilesWithSuffixInPath(dir, ".egg-info")
if len(eggInfo) == 0 { if len(eggInfo) == 0 {
return return
@ -42,7 +42,7 @@ func FindFilesWithSuffixInPath(dir, suffix string) []string {
if !strings.HasSuffix(child.Name(), suffix) { if !strings.HasSuffix(child.Name(), suffix) {
continue continue
} }
files = append(files, path.Join(dir, child.Name())) files = append(files, filepath.Join(dir, child.Name()))
} }
return files return files
} }

21
python/utils_test.go Normal file
View File

@ -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)
}