Compare commits

..

No commits in common. "279c19ebc05190ce9b259f5580bcad05975b9042" and "414c9fba1f1b4682d074f83c979881da7ac85a52" have entirely different histories.

4 changed files with 23 additions and 17 deletions

View File

@ -33,7 +33,12 @@ func createGlobError(v dyn.Value, p dyn.Path, message string) diag.Diagnostic {
Severity: diag.Error, Severity: diag.Error,
Summary: fmt.Sprintf("%s: %s", source, message), Summary: fmt.Sprintf("%s: %s", source, message),
Locations: []dyn.Location{v.Location()}, Locations: []dyn.Location{v.Location()},
Paths: []dyn.Path{p},
Paths: []dyn.Path{
// Hack to clone the path. This path copy is mutable.
// To be addressed in a later PR.
p.Append(),
},
} }
} }

View File

@ -18,8 +18,10 @@ func matchError(p dyn.Path, l []dyn.Location, message string) diag.Diagnostic {
return diag.Diagnostic{ return diag.Diagnostic{
Severity: diag.Error, Severity: diag.Error,
Summary: message, Summary: message,
Paths: []dyn.Path{
p.Append(),
},
Locations: l, Locations: l,
Paths: []dyn.Path{p},
} }
} }

View File

@ -76,7 +76,7 @@ func collectLocalLibraries(b *bundle.Bundle) (map[string][]configLocation, error
source = filepath.Join(b.RootPath, source) source = filepath.Join(b.RootPath, source)
libs[source] = append(libs[source], configLocation{ libs[source] = append(libs[source], configLocation{
configPath: p, configPath: p.Append(), // Hack to get the copy of path
location: v.Location(), location: v.Location(),
}) })

View File

@ -1,27 +1,26 @@
package dyn_test package dyn
import ( import (
"testing" "testing"
"github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert"
assert "github.com/databricks/cli/libs/dyn/dynassert"
) )
func TestVisitCallbackPathCopy(t *testing.T) { func TestVisitCallbackPathCopy(t *testing.T) {
vin := dyn.V(map[string]dyn.Value{ vin := V(map[string]Value{
"foo": dyn.V(42), "foo": V(42),
"bar": dyn.V(43), "bar": V(43),
}) })
var paths []dyn.Path var paths []Path
// The callback should receive a copy of the path. // The callback should receive a copy of the path.
// If the same underlying value is used, all collected paths will be the same. // If the same underlying value is used, all collected paths will be the same.
// This test uses `MapByPattern` to collect all paths in the map. _, _ = visit(vin, EmptyPath, NewPattern(AnyKey()), visitOptions{
// Visit itself doesn't have public functions and we exclusively use black-box testing for this package. fn: func(p Path, v Value) (Value, error) {
_, _ = dyn.MapByPattern(vin, dyn.NewPattern(dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
paths = append(paths, p) paths = append(paths, p)
return v, nil return v, nil
},
}) })
// Verify that the paths retained their original values. // Verify that the paths retained their original values.