mirror of https://github.com/databricks/cli.git
PythonMutator: allow insert 'resources' and 'resources.jobs' (#1555)
## Changes Allow insert 'resources' and 'resources.jobs' because they can be absent in incoming bundle. ## Tests Unit tests
This commit is contained in:
parent
b9e3c98723
commit
4787edba36
|
@ -309,6 +309,7 @@ func createOverrideVisitor(ctx context.Context, phase phase) (merge.OverrideVisi
|
|||
// During load, it's only possible to create new resources, and not modify or
|
||||
// delete existing ones.
|
||||
func createLoadOverrideVisitor(ctx context.Context) merge.OverrideVisitor {
|
||||
resourcesPath := dyn.NewPath(dyn.Key("resources"))
|
||||
jobsPath := dyn.NewPath(dyn.Key("resources"), dyn.Key("jobs"))
|
||||
|
||||
return merge.OverrideVisitor{
|
||||
|
@ -320,6 +321,11 @@ func createLoadOverrideVisitor(ctx context.Context) merge.OverrideVisitor {
|
|||
return fmt.Errorf("unexpected change at %q (delete)", valuePath.String())
|
||||
},
|
||||
VisitInsert: func(valuePath dyn.Path, right dyn.Value) (dyn.Value, error) {
|
||||
// insert 'resources' or 'resources.jobs' if it didn't exist before
|
||||
if valuePath.Equal(resourcesPath) || valuePath.Equal(jobsPath) {
|
||||
return right, nil
|
||||
}
|
||||
|
||||
if !valuePath.HasPrefix(jobsPath) {
|
||||
return dyn.InvalidValue, fmt.Errorf("unexpected change at %q (insert)", valuePath.String())
|
||||
}
|
||||
|
@ -346,6 +352,7 @@ func createLoadOverrideVisitor(ctx context.Context) merge.OverrideVisitor {
|
|||
// During the init phase it's possible to create new resources, modify existing
|
||||
// resources, but not delete existing resources.
|
||||
func createInitOverrideVisitor(ctx context.Context) merge.OverrideVisitor {
|
||||
resourcesPath := dyn.NewPath(dyn.Key("resources"))
|
||||
jobsPath := dyn.NewPath(dyn.Key("resources"), dyn.Key("jobs"))
|
||||
|
||||
return merge.OverrideVisitor{
|
||||
|
@ -370,6 +377,11 @@ func createInitOverrideVisitor(ctx context.Context) merge.OverrideVisitor {
|
|||
return nil
|
||||
},
|
||||
VisitInsert: func(valuePath dyn.Path, right dyn.Value) (dyn.Value, error) {
|
||||
// insert 'resources' or 'resources.jobs' if it didn't exist before
|
||||
if valuePath.Equal(resourcesPath) || valuePath.Equal(jobsPath) {
|
||||
return right, nil
|
||||
}
|
||||
|
||||
if !valuePath.HasPrefix(jobsPath) {
|
||||
return dyn.InvalidValue, fmt.Errorf("unexpected change at %q (insert)", valuePath.String())
|
||||
}
|
||||
|
|
|
@ -325,6 +325,18 @@ func TestCreateOverrideVisitor(t *testing.T) {
|
|||
deletePath: dyn.MustPathFromString("resources.jobs.job0"),
|
||||
deleteError: fmt.Errorf("unexpected change at \"resources.jobs.job0\" (delete)"),
|
||||
},
|
||||
{
|
||||
name: "load: can insert 'resources'",
|
||||
phase: PythonMutatorPhaseLoad,
|
||||
insertPath: dyn.MustPathFromString("resources"),
|
||||
insertError: nil,
|
||||
},
|
||||
{
|
||||
name: "load: can insert 'resources.jobs'",
|
||||
phase: PythonMutatorPhaseLoad,
|
||||
insertPath: dyn.MustPathFromString("resources.jobs"),
|
||||
insertError: nil,
|
||||
},
|
||||
{
|
||||
name: "load: can insert a job",
|
||||
phase: PythonMutatorPhaseLoad,
|
||||
|
@ -357,6 +369,18 @@ func TestCreateOverrideVisitor(t *testing.T) {
|
|||
deletePath: dyn.MustPathFromString("resources.jobs.job0"),
|
||||
deleteError: fmt.Errorf("unexpected change at \"resources.jobs.job0\" (delete)"),
|
||||
},
|
||||
{
|
||||
name: "init: can insert 'resources'",
|
||||
phase: PythonMutatorPhaseInit,
|
||||
insertPath: dyn.MustPathFromString("resources"),
|
||||
insertError: nil,
|
||||
},
|
||||
{
|
||||
name: "init: can insert 'resources.jobs'",
|
||||
phase: PythonMutatorPhaseInit,
|
||||
insertPath: dyn.MustPathFromString("resources.jobs"),
|
||||
insertError: nil,
|
||||
},
|
||||
{
|
||||
name: "init: can insert a job",
|
||||
phase: PythonMutatorPhaseInit,
|
||||
|
|
Loading…
Reference in New Issue