2023-07-07 10:22:58 +00:00
|
|
|
package config_tests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
2024-03-27 10:49:05 +00:00
|
|
|
"github.com/databricks/cli/bundle/phases"
|
2023-07-07 10:22:58 +00:00
|
|
|
"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)
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(ctx, b, phases.Load())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.Error(t, diags.Error())
|
|
|
|
assert.ErrorContains(t, diags.Error(), "notexists.yml defined in 'include' section does not match any files")
|
2023-07-07 10:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
2024-08-13 12:50:15 +00:00
|
|
|
l := b.Config.GetLocation("resources.jobs.my_job")
|
|
|
|
assert.Equal(t, "include_with_glob/job.yml", filepath.ToSlash(l.File))
|
2023-07-07 10:22:58 +00:00
|
|
|
}
|
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)
|
2024-08-13 12:50:15 +00:00
|
|
|
fl := b.Config.GetLocation("resources.jobs.my_first_job")
|
|
|
|
assert.Equal(t, "include_multiple/my_first_job/resource.yml", filepath.ToSlash(fl.File))
|
2023-07-25 08:00:46 +00:00
|
|
|
|
|
|
|
second := b.Config.Resources.Jobs["my_second_job"]
|
|
|
|
assert.Equal(t, "2", second.ID)
|
2024-08-13 12:50:15 +00:00
|
|
|
sl := b.Config.GetLocation("resources.jobs.my_second_job")
|
|
|
|
assert.Equal(t, "include_multiple/my_second_job/resource.yml", filepath.ToSlash(sl.File))
|
2023-07-25 08:00:46 +00:00
|
|
|
}
|