Add a test for sync root outside of git root (#2202)

- Move acceptance/bundle/sync-paths-dotdot test to
acceptance/bundle/syncroot/dotdot-notgit
- Add new test acceptance/bundle/syncroot/dotdot-git

Fix replacer to work with this test and on Windows:
- Make PATH work on Windows by using EvalSymlinks.
- Make concatenated path match within JSON but stripping quotes.
This commit is contained in:
Denis Bilenko 2025-01-22 11:17:45 +01:00 committed by GitHub
parent 3a32c63919
commit fde30ff1ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 69 additions and 9 deletions

View File

@ -188,12 +188,12 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
tmpDir = t.TempDir() tmpDir = t.TempDir()
} }
repls.Set("/private"+tmpDir, "$TMPDIR") // Converts C:\Users\DENIS~1.BIL -> C:\Users\denis.bilenko
repls.Set("/private"+filepath.Dir(tmpDir), "$TMPPARENT") tmpDirEvalled, err1 := filepath.EvalSymlinks(tmpDir)
repls.Set("/private"+filepath.Dir(filepath.Dir(tmpDir)), "$TMPGPARENT") if err1 == nil && tmpDirEvalled != tmpDir {
repls.Set(tmpDir, "$TMPDIR") repls.SetPathWithParents(tmpDirEvalled, "$TMPDIR")
repls.Set(filepath.Dir(tmpDir), "$TMPPARENT") }
repls.Set(filepath.Dir(filepath.Dir(tmpDir)), "$TMPGPARENT") repls.SetPathWithParents(tmpDir, "$TMPDIR")
scriptContents := readMergedScriptContents(t, dir) scriptContents := readMergedScriptContents(t, dir)
testutil.WriteFile(t, filepath.Join(tmpDir, EntryPointScript), scriptContents) testutil.WriteFile(t, filepath.Join(tmpDir, EntryPointScript), scriptContents)

View File

@ -1 +0,0 @@
$CLI bundle validate

View File

@ -1,4 +1,4 @@
Error: path "$TMPPARENT" is not within repository root "$TMPDIR" Error: path "$TMPDIR" is not within repository root "$TMPDIR/myrepo"
Name: test-bundle Name: test-bundle
Target: default Target: default

View File

@ -0,0 +1,6 @@
# This should error, we do not allow syncroot outside of git repo.
mkdir myrepo
cd myrepo
cp ../databricks.yml .
git-repo-init
$CLI bundle validate | sed 's/\\\\/\//g'

View File

@ -0,0 +1,5 @@
bundle:
name: test-bundle
sync:
paths:
- ..

View File

@ -0,0 +1,11 @@
Error: path "$TMPDIR_PARENT" is not within repository root "$TMPDIR"
Name: test-bundle
Target: default
Workspace:
User: $USERNAME
Path: /Workspace/Users/$USERNAME/.bundle/test-bundle/default
Found 1 error
Exit code: 1

View File

@ -0,0 +1,2 @@
# This should not error, syncroot can be outside bundle root.
$CLI bundle validate

View File

@ -3,7 +3,9 @@ package testdiff
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"path/filepath"
"regexp" "regexp"
"runtime"
"slices" "slices"
"strings" "strings"
@ -74,13 +76,48 @@ func (r *ReplacementsContext) Set(old, new string) {
if err == nil { if err == nil {
encodedOld, err := json.Marshal(old) encodedOld, err := json.Marshal(old)
if err == nil { if err == nil {
r.appendLiteral(string(encodedOld), string(encodedNew)) r.appendLiteral(trimQuotes(string(encodedOld)), trimQuotes(string(encodedNew)))
} }
} }
r.appendLiteral(old, new) r.appendLiteral(old, new)
} }
func trimQuotes(s string) string {
if len(s) > 0 && s[0] == '"' {
s = s[1:]
}
if len(s) > 0 && s[len(s)-1] == '"' {
s = s[:len(s)-1]
}
return s
}
func (r *ReplacementsContext) SetPath(old, new string) {
r.Set(old, new)
if runtime.GOOS != "windows" {
return
}
// Support both forward and backward slashes
m1 := strings.ReplaceAll(old, "\\", "/")
if m1 != old {
r.Set(m1, new)
}
m2 := strings.ReplaceAll(old, "/", "\\")
if m2 != old && m2 != m1 {
r.Set(m2, new)
}
}
func (r *ReplacementsContext) SetPathWithParents(old, new string) {
r.SetPath(old, new)
r.SetPath(filepath.Dir(old), new+"_PARENT")
r.SetPath(filepath.Dir(filepath.Dir(old)), new+"_GPARENT")
}
func PrepareReplacementsWorkspaceClient(t testutil.TestingT, r *ReplacementsContext, w *databricks.WorkspaceClient) { func PrepareReplacementsWorkspaceClient(t testutil.TestingT, r *ReplacementsContext, w *databricks.WorkspaceClient) {
t.Helper() t.Helper()
// in some clouds (gcp) w.Config.Host includes "https://" prefix in others it's really just a host (azure) // in some clouds (gcp) w.Config.Host includes "https://" prefix in others it's really just a host (azure)