Merge artifacts and resources block with overrides enabled (#660)

## Changes

Originally, these blocks were merged with overrides. This was
(inadvertently) disabled in #94. This change re-enables merging these
blocks with overrides, such that any field set in an environment
override always takes precedence over the field set in the base
definition.

## Tests

New unit test passes.
This commit is contained in:
Pieter Noordhuis 2023-08-15 11:58:54 +02:00 committed by GitHub
parent 5b819cd982
commit 8dc6936581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 9 deletions

View File

@ -166,7 +166,7 @@ func (r *Root) Merge(other *Root) error {
} }
// TODO: define and test semantics for merging. // TODO: define and test semantics for merging.
return mergo.MergeWithOverwrite(r, other) return mergo.Merge(r, other, mergo.WithOverride)
} }
func (r *Root) MergeEnvironment(env *Environment) error { func (r *Root) MergeEnvironment(env *Environment) error {
@ -178,28 +178,28 @@ func (r *Root) MergeEnvironment(env *Environment) error {
} }
if env.Bundle != nil { if env.Bundle != nil {
err = mergo.MergeWithOverwrite(&r.Bundle, env.Bundle) err = mergo.Merge(&r.Bundle, env.Bundle, mergo.WithOverride)
if err != nil { if err != nil {
return err return err
} }
} }
if env.Workspace != nil { if env.Workspace != nil {
err = mergo.MergeWithOverwrite(&r.Workspace, env.Workspace) err = mergo.Merge(&r.Workspace, env.Workspace, mergo.WithOverride)
if err != nil { if err != nil {
return err return err
} }
} }
if env.Artifacts != nil { if env.Artifacts != nil {
err = mergo.Merge(&r.Artifacts, env.Artifacts, mergo.WithAppendSlice) err = mergo.Merge(&r.Artifacts, env.Artifacts, mergo.WithOverride, mergo.WithAppendSlice)
if err != nil { if err != nil {
return err return err
} }
} }
if env.Resources != nil { if env.Resources != nil {
err = mergo.Merge(&r.Resources, env.Resources, mergo.WithAppendSlice) err = mergo.Merge(&r.Resources, env.Resources, mergo.WithOverride, mergo.WithAppendSlice)
if err != nil { if err != nil {
return err return err
} }

View File

@ -0,0 +1,20 @@
bundle:
name: environment_overrides
workspace:
host: https://acme.cloud.databricks.com/
resources:
jobs:
job1:
name: "base job"
environments:
development:
default: true
staging:
resources:
jobs:
job1:
name: "staging job"

View File

@ -6,12 +6,22 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestEnvironmentOverridesDev(t *testing.T) { func TestEnvironmentOverridesWorkspaceDev(t *testing.T) {
b := loadEnvironment(t, "./environment_overrides", "development") b := loadEnvironment(t, "./environment_overrides/workspace", "development")
assert.Equal(t, "https://development.acme.cloud.databricks.com/", b.Config.Workspace.Host) assert.Equal(t, "https://development.acme.cloud.databricks.com/", b.Config.Workspace.Host)
} }
func TestEnvironmentOverridesStaging(t *testing.T) { func TestEnvironmentOverridesWorkspaceStaging(t *testing.T) {
b := loadEnvironment(t, "./environment_overrides", "staging") b := loadEnvironment(t, "./environment_overrides/workspace", "staging")
assert.Equal(t, "https://staging.acme.cloud.databricks.com/", b.Config.Workspace.Host) assert.Equal(t, "https://staging.acme.cloud.databricks.com/", b.Config.Workspace.Host)
} }
func TestEnvironmentOverridesResourcesDev(t *testing.T) {
b := loadEnvironment(t, "./environment_overrides/resources", "development")
assert.Equal(t, "base job", b.Config.Resources.Jobs["job1"].Name)
}
func TestEnvironmentOverridesResourcesStaging(t *testing.T) {
b := loadEnvironment(t, "./environment_overrides/resources", "staging")
assert.Equal(t, "staging job", b.Config.Resources.Jobs["job1"].Name)
}