Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
pietern committed Sep 4, 2024
1 parent 414c9fb commit 5a9847b
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions libs/dyn/visit_test.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package dyn
package dyn_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/databricks/cli/libs/dyn"
assert "github.com/databricks/cli/libs/dyn/dynassert"
)

func TestVisitCallbackPathCopy(t *testing.T) {
vin := V(map[string]Value{
"foo": V(42),
"bar": V(43),
vin := dyn.V(map[string]dyn.Value{
"foo": dyn.V(42),
"bar": dyn.V(43),
})

var paths []Path
var paths []dyn.Path

// The callback should receive a copy of the path.
// If the same underlying value is used, all collected paths will be the same.
_, _ = visit(vin, EmptyPath, NewPattern(AnyKey()), visitOptions{
fn: func(p Path, v Value) (Value, error) {
paths = append(paths, p)
return v, nil
},
// This test uses `MapByPattern` to collect all paths in the map.
// Visit itself doesn't have public functions and we exclusively use black-box testing for this package.
_, _ = dyn.MapByPattern(vin, dyn.NewPattern(dyn.AnyKey()), func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
paths = append(paths, p)
return v, nil
})

// Verify that the paths retained their original values.
Expand Down

0 comments on commit 5a9847b

Please sign in to comment.