Allow target overrides for sync section (#856)

## Changes
Allow target overrides for sync section

## Tests
Added tests
This commit is contained in:
Andrew Nester 2023-10-10 17:18:18 +02:00 committed by GitHub
parent 803ecb5efd
commit 943ea89728
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 100 additions and 0 deletions

View File

@ -280,5 +280,12 @@ func (r *Root) MergeTargetOverrides(target *Target) error {
git.OriginURL = target.Git.OriginURL 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 return nil
} }

View File

@ -35,6 +35,8 @@ type Target struct {
Git Git `json:"git,omitempty"` Git Git `json:"git,omitempty"`
RunAs *jobs.JobRunAs `json:"run_as,omitempty"` RunAs *jobs.JobRunAs `json:"run_as,omitempty"`
Sync *Sync `json:"sync,omitempty"`
} }
const ( const (

View File

@ -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/

View File

@ -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/

View File

@ -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)
}