Add extra tests for the sync block (#1548)

## Changes

Issue #1545 describes how a nil entry in the sync block caused an error.

The fix for this issue is in #1547. This change adds end-to-end test
coverage.

## Tests

New test passes on top of #1547.
This commit is contained in:
Pieter Noordhuis 2024-07-01 15:08:50 +02:00 committed by GitHub
parent da603c6ead
commit a0df54ac41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 105 additions and 45 deletions

View File

@ -1,41 +0,0 @@
package config_tests
import (
"path/filepath"
"testing"
"github.com/databricks/cli/bundle"
"github.com/stretchr/testify/assert"
)
func TestOverrideSyncTarget(t *testing.T) {
var b *bundle.Bundle
b = loadTarget(t, "./override_sync", "development")
assert.ElementsMatch(t, []string{filepath.FromSlash("src/*"), filepath.FromSlash("tests/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{filepath.FromSlash("dist")}, b.Config.Sync.Exclude)
b = loadTarget(t, "./override_sync", "staging")
assert.ElementsMatch(t, []string{filepath.FromSlash("src/*"), filepath.FromSlash("fixtures/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude)
b = loadTarget(t, "./override_sync", "prod")
assert.ElementsMatch(t, []string{filepath.FromSlash("src/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude)
}
func TestOverrideSyncTargetNoRootSync(t *testing.T) {
var b *bundle.Bundle
b = loadTarget(t, "./override_sync_no_root", "development")
assert.ElementsMatch(t, []string{filepath.FromSlash("tests/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{filepath.FromSlash("dist")}, b.Config.Sync.Exclude)
b = loadTarget(t, "./override_sync_no_root", "staging")
assert.ElementsMatch(t, []string{filepath.FromSlash("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)
}

View File

@ -0,0 +1,19 @@
bundle:
name: sync_nil
workspace:
host: https://acme.cloud.databricks.com/
sync:
include: ~
exclude: ~
targets:
development:
staging:
sync:
include:
- tests/*
exclude:
- dist

View File

@ -0,0 +1,17 @@
bundle:
name: sync_nil_root
workspace:
host: https://acme.cloud.databricks.com/
sync: ~
targets:
development:
staging:
sync:
include:
- tests/*
exclude:
- dist

View File

@ -1,5 +1,5 @@
bundle: bundle:
name: override_sync name: sync_override
workspace: workspace:
host: https://acme.cloud.databricks.com/ host: https://acme.cloud.databricks.com/

View File

@ -1,5 +1,5 @@
bundle: bundle:
name: override_sync name: sync_override_no_root
workspace: workspace:
host: https://acme.cloud.databricks.com/ host: https://acme.cloud.databricks.com/

View File

@ -13,7 +13,7 @@ import (
) )
func TestSyncIncludeExcludeNoMatchesTest(t *testing.T) { func TestSyncIncludeExcludeNoMatchesTest(t *testing.T) {
b := loadTarget(t, "./override_sync", "development") b := loadTarget(t, "./sync/override", "development")
diags := bundle.ApplyReadOnly(context.Background(), bundle.ReadOnly(b), validate.ValidateSyncPatterns()) diags := bundle.ApplyReadOnly(context.Background(), bundle.ReadOnly(b), validate.ValidateSyncPatterns())
require.Len(t, diags, 3) require.Len(t, diags, 3)
@ -21,7 +21,7 @@ func TestSyncIncludeExcludeNoMatchesTest(t *testing.T) {
require.Equal(t, diags[0].Severity, diag.Warning) require.Equal(t, diags[0].Severity, diag.Warning)
require.Equal(t, diags[0].Summary, "Pattern dist does not match any files") require.Equal(t, diags[0].Summary, "Pattern dist does not match any files")
require.Equal(t, diags[0].Location.File, filepath.Join("override_sync", "databricks.yml")) require.Equal(t, diags[0].Location.File, filepath.Join("sync", "override", "databricks.yml"))
require.Equal(t, diags[0].Location.Line, 17) require.Equal(t, diags[0].Location.Line, 17)
require.Equal(t, diags[0].Location.Column, 11) require.Equal(t, diags[0].Location.Column, 11)
require.Equal(t, diags[0].Path.String(), "sync.exclude[0]") require.Equal(t, diags[0].Path.String(), "sync.exclude[0]")

65
bundle/tests/sync_test.go Normal file
View File

@ -0,0 +1,65 @@
package config_tests
import (
"path/filepath"
"testing"
"github.com/databricks/cli/bundle"
"github.com/stretchr/testify/assert"
)
func TestSyncOverride(t *testing.T) {
var b *bundle.Bundle
b = loadTarget(t, "./sync/override", "development")
assert.ElementsMatch(t, []string{filepath.FromSlash("src/*"), filepath.FromSlash("tests/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{filepath.FromSlash("dist")}, b.Config.Sync.Exclude)
b = loadTarget(t, "./sync/override", "staging")
assert.ElementsMatch(t, []string{filepath.FromSlash("src/*"), filepath.FromSlash("fixtures/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude)
b = loadTarget(t, "./sync/override", "prod")
assert.ElementsMatch(t, []string{filepath.FromSlash("src/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude)
}
func TestSyncOverrideNoRootSync(t *testing.T) {
var b *bundle.Bundle
b = loadTarget(t, "./sync/override_no_root", "development")
assert.ElementsMatch(t, []string{filepath.FromSlash("tests/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{filepath.FromSlash("dist")}, b.Config.Sync.Exclude)
b = loadTarget(t, "./sync/override_no_root", "staging")
assert.ElementsMatch(t, []string{filepath.FromSlash("fixtures/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude)
b = loadTarget(t, "./sync/override_no_root", "prod")
assert.ElementsMatch(t, []string{}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{}, b.Config.Sync.Exclude)
}
func TestSyncNil(t *testing.T) {
var b *bundle.Bundle
b = loadTarget(t, "./sync/nil", "development")
assert.Nil(t, b.Config.Sync.Include)
assert.Nil(t, b.Config.Sync.Exclude)
b = loadTarget(t, "./sync/nil", "staging")
assert.ElementsMatch(t, []string{filepath.FromSlash("tests/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{filepath.FromSlash("dist")}, b.Config.Sync.Exclude)
}
func TestSyncNilRoot(t *testing.T) {
var b *bundle.Bundle
b = loadTarget(t, "./sync/nil_root", "development")
assert.Nil(t, b.Config.Sync.Include)
assert.Nil(t, b.Config.Sync.Exclude)
b = loadTarget(t, "./sync/nil_root", "staging")
assert.ElementsMatch(t, []string{filepath.FromSlash("tests/*")}, b.Config.Sync.Include)
assert.ElementsMatch(t, []string{filepath.FromSlash("dist")}, b.Config.Sync.Exclude)
}