Skip to content

Commit

Permalink
Allow target overrides for sync section (#856)
Browse files Browse the repository at this point in the history
## Changes
Allow target overrides for sync section

## Tests
Added tests
  • Loading branch information
andrewnester authored Oct 10, 2023
1 parent 803ecb5 commit 943ea89
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bundle/config/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions bundle/config/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
26 changes: 26 additions & 0 deletions bundle/tests/override_sync/databricks.yml
Original file line number Diff line number Diff line change
@@ -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/
22 changes: 22 additions & 0 deletions bundle/tests/override_sync_no_root/databricks.yml
Original file line number Diff line number Diff line change
@@ -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/
43 changes: 43 additions & 0 deletions bundle/tests/override_sync_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 943ea89

Please sign in to comment.