Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce new type for a slice of dyn.Location #1611

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion bundle/config/generate/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ConvertJobToValue(job *jobs.Job) (dyn.Value, error) {
tasks = append(tasks, v)
}
// We're using location lines to define the order of keys in exported YAML.
value["tasks"] = dyn.NewValue(tasks, []dyn.Location{{Line: jobOrder.Get("tasks")}})
value["tasks"] = dyn.NewValue(tasks, dyn.Locations{{Line: jobOrder.Get("tasks")}})
}

return yamlsaver.ConvertToMapValue(job.Settings, jobOrder, []string{"format", "new_cluster", "existing_cluster_id"}, value)
Expand Down
12 changes: 6 additions & 6 deletions bundle/config/mutator/python/python_mutator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,36 +470,36 @@ func TestCreateOverrideVisitor_omitempty(t *testing.T) {
// this is not happening, but adding for completeness
name: "undo delete of empty variables",
path: dyn.MustPathFromString("variables"),
left: dyn.NewValue([]dyn.Value{}, []dyn.Location{location}),
left: dyn.NewValue([]dyn.Value{}, dyn.Locations{location}),
expectedErr: merge.ErrOverrideUndoDelete,
phases: allPhases,
},
{
name: "undo delete of empty job clusters",
path: dyn.MustPathFromString("resources.jobs.job0.job_clusters"),
left: dyn.NewValue([]dyn.Value{}, []dyn.Location{location}),
left: dyn.NewValue([]dyn.Value{}, dyn.Locations{location}),
expectedErr: merge.ErrOverrideUndoDelete,
phases: allPhases,
},
{
name: "allow delete of non-empty job clusters",
path: dyn.MustPathFromString("resources.jobs.job0.job_clusters"),
left: dyn.NewValue([]dyn.Value{dyn.NewValue("abc", []dyn.Location{location})}, []dyn.Location{location}),
left: dyn.NewValue([]dyn.Value{dyn.NewValue("abc", dyn.Locations{location})}, dyn.Locations{location}),
expectedErr: nil,
// deletions aren't allowed in 'load' phase
phases: []phase{PythonMutatorPhaseInit},
},
{
name: "undo delete of empty tags",
path: dyn.MustPathFromString("resources.jobs.job0.tags"),
left: dyn.NewValue(map[string]dyn.Value{}, []dyn.Location{location}),
left: dyn.NewValue(map[string]dyn.Value{}, dyn.Locations{location}),
expectedErr: merge.ErrOverrideUndoDelete,
phases: allPhases,
},
{
name: "allow delete of non-empty tags",
path: dyn.MustPathFromString("resources.jobs.job0.tags"),
left: dyn.NewValue(map[string]dyn.Value{"dev": dyn.NewValue("true", []dyn.Location{location})}, []dyn.Location{location}),
left: dyn.NewValue(map[string]dyn.Value{"dev": dyn.NewValue("true", dyn.Locations{location})}, dyn.Locations{location}),

expectedErr: nil,
// deletions aren't allowed in 'load' phase
Expand All @@ -508,7 +508,7 @@ func TestCreateOverrideVisitor_omitempty(t *testing.T) {
{
name: "undo delete of nil",
path: dyn.MustPathFromString("resources.jobs.job0.tags"),
left: dyn.NilValue.WithLocations([]dyn.Location{location}),
left: dyn.NilValue.WithLocations(dyn.Locations{location}),
expectedErr: merge.ErrOverrideUndoDelete,
phases: allPhases,
},
Expand Down
2 changes: 1 addition & 1 deletion bundle/internal/bundletest/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func SetLocation(b *bundle.Bundle, prefix string, filePath string) {
return dyn.Walk(root, func(p dyn.Path, v dyn.Value) (dyn.Value, error) {
// If the path has the given prefix, set the location.
if p.HasPrefix(start) {
return v.WithLocations([]dyn.Location{{
return v.WithLocations(dyn.Locations{{
File: filePath,
}}), nil
}
Expand Down
60 changes: 30 additions & 30 deletions libs/dyn/convert/from_typed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ func TestFromTypedStructSetFieldsRetainLocation(t *testing.T) {
}

ref := dyn.V(map[string]dyn.Value{
"foo": dyn.NewValue("bar", []dyn.Location{{File: "foo"}}),
"bar": dyn.NewValue("baz", []dyn.Location{{File: "bar"}}),
"foo": dyn.NewValue("bar", dyn.Locations{{File: "foo"}}),
"bar": dyn.NewValue("baz", dyn.Locations{{File: "bar"}}),
})

nv, err := FromTyped(src, ref)
require.NoError(t, err)

// Assert foo and bar have retained their location.
assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), nv.Get("foo"))
assert.Equal(t, dyn.NewValue("qux", []dyn.Location{{File: "bar"}}), nv.Get("bar"))
assert.Equal(t, dyn.NewValue("bar", dyn.Locations{{File: "foo"}}), nv.Get("foo"))
assert.Equal(t, dyn.NewValue("qux", dyn.Locations{{File: "bar"}}), nv.Get("bar"))
}

func TestFromTypedStringMapWithZeroValue(t *testing.T) {
Expand Down Expand Up @@ -359,16 +359,16 @@ func TestFromTypedMapNonEmptyRetainLocation(t *testing.T) {
}

ref := dyn.V(map[string]dyn.Value{
"foo": dyn.NewValue("bar", []dyn.Location{{File: "foo"}}),
"bar": dyn.NewValue("baz", []dyn.Location{{File: "bar"}}),
"foo": dyn.NewValue("bar", dyn.Locations{{File: "foo"}}),
"bar": dyn.NewValue("baz", dyn.Locations{{File: "bar"}}),
})

nv, err := FromTyped(src, ref)
require.NoError(t, err)

// Assert foo and bar have retained their locations.
assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), nv.Get("foo"))
assert.Equal(t, dyn.NewValue("qux", []dyn.Location{{File: "bar"}}), nv.Get("bar"))
assert.Equal(t, dyn.NewValue("bar", dyn.Locations{{File: "foo"}}), nv.Get("foo"))
assert.Equal(t, dyn.NewValue("qux", dyn.Locations{{File: "bar"}}), nv.Get("bar"))
}

func TestFromTypedMapFieldWithZeroValue(t *testing.T) {
Expand Down Expand Up @@ -432,16 +432,16 @@ func TestFromTypedSliceNonEmptyRetainLocation(t *testing.T) {
}

ref := dyn.V([]dyn.Value{
dyn.NewValue("foo", []dyn.Location{{File: "foo"}}),
dyn.NewValue("bar", []dyn.Location{{File: "bar"}}),
dyn.NewValue("foo", dyn.Locations{{File: "foo"}}),
dyn.NewValue("bar", dyn.Locations{{File: "bar"}}),
})

nv, err := FromTyped(src, ref)
require.NoError(t, err)

// Assert foo and bar have retained their locations.
assert.Equal(t, dyn.NewValue("foo", []dyn.Location{{File: "foo"}}), nv.Index(0))
assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "bar"}}), nv.Index(1))
assert.Equal(t, dyn.NewValue("foo", dyn.Locations{{File: "foo"}}), nv.Index(0))
assert.Equal(t, dyn.NewValue("bar", dyn.Locations{{File: "bar"}}), nv.Index(1))
}

func TestFromTypedStringEmpty(t *testing.T) {
Expand Down Expand Up @@ -477,19 +477,19 @@ func TestFromTypedStringNonEmptyOverwrite(t *testing.T) {
}

func TestFromTypedStringRetainsLocations(t *testing.T) {
var ref = dyn.NewValue("foo", []dyn.Location{{File: "foo"}})
var ref = dyn.NewValue("foo", dyn.Locations{{File: "foo"}})

// case: value has not been changed
var src string = "foo"
nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue("foo", []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue("foo", dyn.Locations{{File: "foo"}}), nv)

// case: value has been changed
src = "bar"
nv, err = FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue("bar", dyn.Locations{{File: "foo"}}), nv)
}

func TestFromTypedStringTypeError(t *testing.T) {
Expand Down Expand Up @@ -532,19 +532,19 @@ func TestFromTypedBoolNonEmptyOverwrite(t *testing.T) {
}

func TestFromTypedBoolRetainsLocations(t *testing.T) {
var ref = dyn.NewValue(true, []dyn.Location{{File: "foo"}})
var ref = dyn.NewValue(true, dyn.Locations{{File: "foo"}})

// case: value has not been changed
var src bool = true
nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(true, []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue(true, dyn.Locations{{File: "foo"}}), nv)

// case: value has been changed
src = false
nv, err = FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(false, []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue(false, dyn.Locations{{File: "foo"}}), nv)
}

func TestFromTypedBoolVariableReference(t *testing.T) {
Expand Down Expand Up @@ -595,19 +595,19 @@ func TestFromTypedIntNonEmptyOverwrite(t *testing.T) {
}

func TestFromTypedIntRetainsLocations(t *testing.T) {
var ref = dyn.NewValue(1234, []dyn.Location{{File: "foo"}})
var ref = dyn.NewValue(1234, dyn.Locations{{File: "foo"}})

// case: value has not been changed
var src int = 1234
nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(1234, []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue(1234, dyn.Locations{{File: "foo"}}), nv)

// case: value has been changed
src = 1235
nv, err = FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(int64(1235), []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue(int64(1235), dyn.Locations{{File: "foo"}}), nv)
}

func TestFromTypedIntVariableReference(t *testing.T) {
Expand Down Expand Up @@ -659,19 +659,19 @@ func TestFromTypedFloatNonEmptyOverwrite(t *testing.T) {

func TestFromTypedFloatRetainsLocations(t *testing.T) {
var src float64
var ref = dyn.NewValue(1.23, []dyn.Location{{File: "foo"}})
var ref = dyn.NewValue(1.23, dyn.Locations{{File: "foo"}})

// case: value has not been changed
src = 1.23
nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(1.23, []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue(1.23, dyn.Locations{{File: "foo"}}), nv)

// case: value has been changed
src = 1.24
nv, err = FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(1.24, []dyn.Location{{File: "foo"}}), nv)
assert.Equal(t, dyn.NewValue(1.24, dyn.Locations{{File: "foo"}}), nv)
}

func TestFromTypedFloatVariableReference(t *testing.T) {
Expand Down Expand Up @@ -740,27 +740,27 @@ func TestFromTypedNilPointerRetainsLocations(t *testing.T) {
}

var src *Tmp
ref := dyn.NewValue(nil, []dyn.Location{{File: "foobar"}})
ref := dyn.NewValue(nil, dyn.Locations{{File: "foobar"}})

nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}), nv)
assert.Equal(t, dyn.NewValue(nil, dyn.Locations{{File: "foobar"}}), nv)
}

func TestFromTypedNilMapRetainsLocation(t *testing.T) {
var src map[string]string
ref := dyn.NewValue(nil, []dyn.Location{{File: "foobar"}})
ref := dyn.NewValue(nil, dyn.Locations{{File: "foobar"}})

nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}), nv)
assert.Equal(t, dyn.NewValue(nil, dyn.Locations{{File: "foobar"}}), nv)
}

func TestFromTypedNilSliceRetainsLocation(t *testing.T) {
var src []string
ref := dyn.NewValue(nil, []dyn.Location{{File: "foobar"}})
ref := dyn.NewValue(nil, dyn.Locations{{File: "foobar"}})

nv, err := FromTyped(src, ref)
require.NoError(t, err)
assert.Equal(t, dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}), nv)
assert.Equal(t, dyn.NewValue(nil, dyn.Locations{{File: "foobar"}}), nv)
}
Loading
Loading