2023-07-07 10:22:58 +00:00
|
|
|
package config_tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config/mutator"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"golang.org/x/exp/maps"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestIncludeInvalid(t *testing.T) {
|
2023-08-11 12:28:05 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
b, err := bundle.Load(ctx, "./include_invalid")
|
2023-07-07 10:22:58 +00:00
|
|
|
require.NoError(t, err)
|
2023-08-11 12:28:05 +00:00
|
|
|
err = bundle.Apply(ctx, b, bundle.Seq(mutator.DefaultMutators()...))
|
2023-07-07 10:22:58 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
assert.Contains(t, err.Error(), "notexists.yml defined in 'include' section does not match any files")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIncludeWithGlob(t *testing.T) {
|
|
|
|
b := load(t, "./include_with_glob")
|
|
|
|
|
|
|
|
keys := maps.Keys(b.Config.Resources.Jobs)
|
|
|
|
sort.Strings(keys)
|
|
|
|
assert.Equal(t, []string{"my_job"}, keys)
|
|
|
|
|
|
|
|
job := b.Config.Resources.Jobs["my_job"]
|
|
|
|
assert.Equal(t, "1", job.ID)
|
|
|
|
assert.Equal(t, "include_with_glob/job.yml", filepath.ToSlash(job.ConfigFilePath))
|
|
|
|
}
|
2023-07-25 08:00:46 +00:00
|
|
|
|
|
|
|
func TestIncludeDefault(t *testing.T) {
|
|
|
|
b := load(t, "./include_default")
|
|
|
|
|
|
|
|
// No jobs should have been loaded
|
|
|
|
assert.Empty(t, b.Config.Resources.Jobs)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestIncludeForMultipleMatches(t *testing.T) {
|
|
|
|
b := load(t, "./include_multiple")
|
|
|
|
|
|
|
|
// Test that both jobs were loaded.
|
|
|
|
keys := maps.Keys(b.Config.Resources.Jobs)
|
|
|
|
sort.Strings(keys)
|
|
|
|
assert.Equal(t, []string{"my_first_job", "my_second_job"}, keys)
|
|
|
|
|
|
|
|
first := b.Config.Resources.Jobs["my_first_job"]
|
|
|
|
assert.Equal(t, "1", first.ID)
|
|
|
|
assert.Equal(t, "include_multiple/my_first_job/resource.yml", filepath.ToSlash(first.ConfigFilePath))
|
|
|
|
|
|
|
|
second := b.Config.Resources.Jobs["my_second_job"]
|
|
|
|
assert.Equal(t, "2", second.ID)
|
|
|
|
assert.Equal(t, "include_multiple/my_second_job/resource.yml", filepath.ToSlash(second.ConfigFilePath))
|
|
|
|
}
|