From 943ea89728e18c068584aabb0abbcf351e4eba65 Mon Sep 17 00:00:00 2001 From: Andrew Nester Date: Tue, 10 Oct 2023 17:18:18 +0200 Subject: [PATCH] Allow target overrides for sync section (#856) ## Changes Allow target overrides for sync section ## Tests Added tests --- bundle/config/root.go | 7 +++ bundle/config/target.go | 2 + bundle/tests/override_sync/databricks.yml | 26 +++++++++++ .../override_sync_no_root/databricks.yml | 22 ++++++++++ bundle/tests/override_sync_test.go | 43 +++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 bundle/tests/override_sync/databricks.yml create mode 100644 bundle/tests/override_sync_no_root/databricks.yml create mode 100644 bundle/tests/override_sync_test.go diff --git a/bundle/config/root.go b/bundle/config/root.go index 3c79fb0b..bf203833 100644 --- a/bundle/config/root.go +++ b/bundle/config/root.go @@ -280,5 +280,12 @@ func (r *Root) MergeTargetOverrides(target *Target) error { git.OriginURL = target.Git.OriginURL } + if target.Sync != nil { + err = mergo.Merge(&r.Sync, target.Sync, mergo.WithAppendSlice) + if err != nil { + return err + } + } + return nil } diff --git a/bundle/config/target.go b/bundle/config/target.go index 2489efc3..fc776c7b 100644 --- a/bundle/config/target.go +++ b/bundle/config/target.go @@ -35,6 +35,8 @@ type Target struct { Git Git `json:"git,omitempty"` RunAs *jobs.JobRunAs `json:"run_as,omitempty"` + + Sync *Sync `json:"sync,omitempty"` } const ( diff --git a/bundle/tests/override_sync/databricks.yml b/bundle/tests/override_sync/databricks.yml new file mode 100644 index 00000000..1417b864 --- /dev/null +++ b/bundle/tests/override_sync/databricks.yml @@ -0,0 +1,26 @@ +bundle: + name: override_sync + +workspace: + host: https://acme.cloud.databricks.com/ + +sync: + include: + - src/* + +targets: + development: + sync: + include: + - tests/* + exclude: + - dist + + staging: + sync: + include: + - fixtures/* + + prod: + workspace: + host: https://acme-prod.cloud.databricks.com/ diff --git a/bundle/tests/override_sync_no_root/databricks.yml b/bundle/tests/override_sync_no_root/databricks.yml new file mode 100644 index 00000000..109d8da1 --- /dev/null +++ b/bundle/tests/override_sync_no_root/databricks.yml @@ -0,0 +1,22 @@ +bundle: + name: override_sync + +workspace: + host: https://acme.cloud.databricks.com/ + +targets: + development: + sync: + include: + - tests/* + exclude: + - dist + + staging: + sync: + include: + - fixtures/* + + prod: + workspace: + host: https://acme-prod.cloud.databricks.com/ diff --git a/bundle/tests/override_sync_test.go b/bundle/tests/override_sync_test.go new file mode 100644 index 00000000..a2d3a05f --- /dev/null +++ b/bundle/tests/override_sync_test.go @@ -0,0 +1,43 @@ +package config_tests + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestOverrideSyncTarget(t *testing.T) { + b := load(t, "./override_sync") + assert.ElementsMatch(t, []string{"src/*"}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude) + + b = loadTarget(t, "./override_sync", "development") + assert.ElementsMatch(t, []string{"src/*", "tests/*"}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{"dist"}, b.Config.Sync.Exclude) + + b = loadTarget(t, "./override_sync", "staging") + assert.ElementsMatch(t, []string{"src/*", "fixtures/*"}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude) + + b = loadTarget(t, "./override_sync", "prod") + assert.ElementsMatch(t, []string{"src/*"}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude) +} + +func TestOverrideSyncTargetNoRootSync(t *testing.T) { + b := load(t, "./override_sync_no_root") + assert.ElementsMatch(t, []string{}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude) + + b = loadTarget(t, "./override_sync_no_root", "development") + assert.ElementsMatch(t, []string{"tests/*"}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{"dist"}, b.Config.Sync.Exclude) + + b = loadTarget(t, "./override_sync_no_root", "staging") + assert.ElementsMatch(t, []string{"fixtures/*"}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude) + + b = loadTarget(t, "./override_sync_no_root", "prod") + assert.ElementsMatch(t, []string{}, b.Config.Sync.Include) + assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude) +}