2024-03-27 10:49:05 +00:00
|
|
|
package loader_test
|
2022-11-18 09:57:31 +00:00
|
|
|
|
|
|
|
import (
|
2022-11-28 09:59:43 +00:00
|
|
|
"context"
|
2022-11-28 10:34:25 +00:00
|
|
|
"runtime"
|
2022-11-18 09:57:31 +00:00
|
|
|
"testing"
|
|
|
|
|
2023-05-16 16:35:39 +00:00
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
2024-03-27 10:49:05 +00:00
|
|
|
"github.com/databricks/cli/bundle/config/loader"
|
2024-03-18 14:41:58 +00:00
|
|
|
"github.com/databricks/cli/internal/testutil"
|
2022-11-18 09:57:31 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestProcessRootIncludesEmpty(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: ".",
|
2022-11-28 09:59:43 +00:00
|
|
|
}
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, loader.ProcessRootIncludes())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessRootIncludesAbs(t *testing.T) {
|
2022-11-28 10:34:25 +00:00
|
|
|
// remove this once equivalent tests for windows have been set up
|
|
|
|
// or this test has been fixed for windows
|
|
|
|
// date: 28 Nov 2022
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
t.Skip("skipping temperorilty to make windows unit tests green")
|
|
|
|
}
|
|
|
|
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: ".",
|
2022-11-28 09:59:43 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Include: []string{
|
|
|
|
"/tmp/*.yml",
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, loader.ProcessRootIncludes())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.True(t, diags.HasError())
|
|
|
|
assert.ErrorContains(t, diags.Error(), "must be relative paths")
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessRootIncludesSingleGlob(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: t.TempDir(),
|
2022-11-28 09:59:43 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Include: []string{
|
|
|
|
"*.yml",
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 10:03:05 +00:00
|
|
|
testutil.Touch(t, b.BundleRootPath, "databricks.yml")
|
|
|
|
testutil.Touch(t, b.BundleRootPath, "a.yml")
|
|
|
|
testutil.Touch(t, b.BundleRootPath, "b.yml")
|
2022-11-18 09:57:31 +00:00
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, loader.ProcessRootIncludes())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-11-15 14:03:36 +00:00
|
|
|
assert.Equal(t, []string{"a.yml", "b.yml"}, b.Config.Include)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessRootIncludesMultiGlob(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: t.TempDir(),
|
2022-11-28 09:59:43 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Include: []string{
|
|
|
|
"a*.yml",
|
|
|
|
"b*.yml",
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 10:03:05 +00:00
|
|
|
testutil.Touch(t, b.BundleRootPath, "a1.yml")
|
|
|
|
testutil.Touch(t, b.BundleRootPath, "b1.yml")
|
2022-11-18 09:57:31 +00:00
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, loader.ProcessRootIncludes())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-11-15 14:03:36 +00:00
|
|
|
assert.Equal(t, []string{"a1.yml", "b1.yml"}, b.Config.Include)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestProcessRootIncludesRemoveDups(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: t.TempDir(),
|
2022-11-28 09:59:43 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Include: []string{
|
|
|
|
"*.yml",
|
|
|
|
"*.yml",
|
|
|
|
},
|
2022-11-18 09:57:31 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-09-27 10:03:05 +00:00
|
|
|
testutil.Touch(t, b.BundleRootPath, "a.yml")
|
2022-11-18 09:57:31 +00:00
|
|
|
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, loader.ProcessRootIncludes())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.NoError(t, diags.Error())
|
2023-11-15 14:03:36 +00:00
|
|
|
assert.Equal(t, []string{"a.yml"}, b.Config.Include)
|
2022-11-18 09:57:31 +00:00
|
|
|
}
|
2023-07-07 10:22:58 +00:00
|
|
|
|
|
|
|
func TestProcessRootIncludesNotExists(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2024-09-27 10:03:05 +00:00
|
|
|
BundleRootPath: t.TempDir(),
|
2023-07-07 10:22:58 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Include: []string{
|
|
|
|
"notexist.yml",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2024-03-27 10:49:05 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, loader.ProcessRootIncludes())
|
2024-03-25 14:18:47 +00:00
|
|
|
require.True(t, diags.HasError())
|
|
|
|
assert.ErrorContains(t, diags.Error(), "notexist.yml defined in 'include' section does not match any files")
|
2023-07-07 10:22:58 +00:00
|
|
|
}
|