Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont
tmpDir = t.TempDir()
}

repls.Set("/private"+tmpDir, "$TMPDIR")
repls.Set("/private"+filepath.Dir(tmpDir), "$TMPPARENT")
repls.Set("/private"+filepath.Dir(filepath.Dir(tmpDir)), "$TMPGPARENT")
repls.Set(tmpDir, "$TMPDIR")
repls.Set(filepath.Dir(tmpDir), "$TMPPARENT")
repls.Set(filepath.Dir(filepath.Dir(tmpDir)), "$TMPGPARENT")
// Converts C:\Users\DENIS~1.BIL -> C:\Users\denis.bilenko
tmpDirEvalled, err1 := filepath.EvalSymlinks(tmpDir)
if err1 == nil && tmpDirEvalled != tmpDir {
repls.SetPathWithParents(tmpDirEvalled, "$TMPDIR")
}
repls.SetPathWithParents(tmpDir, "$TMPDIR")

scriptContents := readMergedScriptContents(t, dir)
testutil.WriteFile(t, filepath.Join(tmpDir, EntryPointScript), scriptContents)
Expand Down
1 change: 0 additions & 1 deletion acceptance/bundle/sync-paths-dotdot/script

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Target: default
Expand Down
6 changes: 6 additions & 0 deletions acceptance/bundle/syncroot/dotdot-git/script
Original file line number Diff line number Diff line change
@@ -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'
5 changes: 5 additions & 0 deletions acceptance/bundle/syncroot/dotdot-nogit/databricks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bundle:
name: test-bundle
sync:
paths:
- ..
11 changes: 11 additions & 0 deletions acceptance/bundle/syncroot/dotdot-nogit/output.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions acceptance/bundle/syncroot/dotdot-nogit/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This should not error, syncroot can be outside bundle root.
$CLI bundle validate
39 changes: 38 additions & 1 deletion libs/testdiff/replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package testdiff
import (
"encoding/json"
"fmt"
"path/filepath"
"regexp"
"runtime"
"slices"
"strings"

Expand Down Expand Up @@ -74,13 +76,48 @@ func (r *ReplacementsContext) Set(old, new string) {
if err == nil {
encodedOld, err := json.Marshal(old)
if err == nil {
r.appendLiteral(string(encodedOld), string(encodedNew))
r.appendLiteral(trimQuotes(string(encodedOld)), trimQuotes(string(encodedNew)))
}
}

r.appendLiteral(old, new)
}

func trimQuotes(s string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

If we only care about quoting strings, you can look at fmt.Sprintf with %q.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I care about strings inside JSON that might have been concatenated with others, e.g. xy becomes "XY" in json. Now I need to replace x -> X.

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) {
t.Helper()
// in some clouds (gcp) w.Config.Host includes "https://" prefix in others it's really just a host (azure)
Expand Down