Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions bundle/apps/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/databricks/cli/bundle/internal/bundletest"
"github.com/databricks/cli/internal/testutil"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/vfs"
"github.com/databricks/databricks-sdk-go/service/apps"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -48,7 +47,7 @@ func TestAppsValidateSameSourcePath(t *testing.T) {
},
}

bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})
bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})

diags := bundle.ApplySeq(t.Context(), b, mutator.TranslatePaths(), Validate())
require.Len(t, diags, 1)
Expand Down Expand Up @@ -205,7 +204,7 @@ func TestAppsValidateResourcePermissionsWarning(t *testing.T) {
},
}

bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})
bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})

diags := bundle.ApplySeq(t.Context(), b, Validate())
warnings := diags.Filter(diag.Warning)
Expand Down Expand Up @@ -249,7 +248,7 @@ func TestAppsValidateBothSourceCodePathAndGitSource(t *testing.T) {
},
}

bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})
bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(tmpDir, "databricks.yml")}})

diags := bundle.ApplySeq(t.Context(), b, mutator.TranslatePaths(), Validate())
require.Len(t, diags, 1)
Expand Down
2 changes: 1 addition & 1 deletion bundle/artifacts/expand_globs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func createGlobError(v dyn.Value, p dyn.Path, message string) diag.Diagnostic {
return diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("%s: %s", source, message),
Locations: []dyn.Location{v.Location()},
Locations: []diag.Location{v.Location()},
Paths: dyn.ToStructPaths(p),
}
}
Expand Down
3 changes: 1 addition & 2 deletions bundle/artifacts/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/databricks/cli/bundle/libraries"
"github.com/databricks/cli/bundle/metrics"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/log"
"github.com/databricks/cli/libs/logdiag"
"github.com/databricks/cli/libs/python"
Expand Down Expand Up @@ -44,7 +43,7 @@ func (m *prepare) Apply(ctx context.Context, b *bundle.Bundle) diag.Diagnostics
Severity: diag.Error,
Summary: "Artifact not properly configured",
Detail: "please specify artifact properties",
Locations: []dyn.Location{l},
Locations: []diag.Location{l},
})
continue
}
Expand Down
4 changes: 2 additions & 2 deletions bundle/config/loader/process_include.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ func validateSingleResourceDefined(configRoot dyn.Value, ext, typ string) diag.D
detail.WriteString(l)
}

var locations []dyn.Location
var locations []diag.Location
var paths []*structpath.PathNode
for _, rr := range resources {
locations = append(locations, rr.value.Locations()...)
paths = append(paths, dyn.ToStructPath(rr.path))
}
// Sort the locations and paths to make the output deterministic.
slices.SortFunc(locations, func(a, b dyn.Location) int {
slices.SortFunc(locations, func(a, b diag.Location) int {
return cmp.Compare(a.String(), b.String())
})
slices.SortFunc(paths, func(a, b *structpath.PathNode) int {
Expand Down
15 changes: 7 additions & 8 deletions bundle/config/loader/process_include_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/loader"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/structs/structpath"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -68,7 +67,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
Severity: diag.Recommendation,
Summary: "define a single pipeline in a file with the .pipeline.yaml extension.",
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n",
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/single_job.pipeline.yaml", Line: 11, Column: 11},
{File: "testdata/format_not_match/single_job.pipeline.yaml", Line: 4, Column: 7},
},
Expand All @@ -83,7 +82,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
Severity: diag.Recommendation,
Summary: "define a single job in a file with the .job.yml extension.",
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - pipeline1 (pipeline)\n",
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/job_and_pipeline.job.yml", Line: 11, Column: 11},
{File: "testdata/format_not_match/job_and_pipeline.job.yml", Line: 4, Column: 7},
},
Expand All @@ -98,7 +97,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
Severity: diag.Recommendation,
Summary: "define a single experiment in a file with the .experiment.yml extension.",
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - pipeline1 (pipeline)\n",
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/job_and_pipeline.experiment.yml", Line: 11, Column: 11},
{File: "testdata/format_not_match/job_and_pipeline.experiment.yml", Line: 4, Column: 7},
},
Expand All @@ -113,7 +112,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
Severity: diag.Recommendation,
Summary: "define a single job in a file with the .job.yml extension.",
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n",
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/two_jobs.job.yml", Line: 4, Column: 7},
{File: "testdata/format_not_match/two_jobs.job.yml", Line: 7, Column: 7},
},
Expand All @@ -128,7 +127,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
Severity: diag.Recommendation,
Summary: "define a single job in a file with the .job.yml extension.",
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n",
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/second_job_in_target.job.yml", Line: 11, Column: 11},
{File: "testdata/format_not_match/second_job_in_target.job.yml", Line: 4, Column: 7},
},
Expand All @@ -143,7 +142,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
Severity: diag.Recommendation,
Summary: "define a single job in a file with the .job.yml extension.",
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n",
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/two_jobs_in_target.job.yml", Line: 6, Column: 11},
{File: "testdata/format_not_match/two_jobs_in_target.job.yml", Line: 8, Column: 11},
},
Expand All @@ -170,7 +169,7 @@ func TestProcessIncludeFormatNotMatch(t *testing.T) {
- registered_model1 (registered_model)
- schema1 (schema)
`,
Locations: []dyn.Location{
Locations: []diag.Location{
{File: "testdata/format_not_match/multiple_resources.model_serving_endpoint.yml", Line: 12, Column: 7},
{File: "testdata/format_not_match/multiple_resources.model_serving_endpoint.yml", Line: 14, Column: 7},
{File: "testdata/format_not_match/multiple_resources.model_serving_endpoint.yml", Line: 18, Column: 7},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/internal/bundletest"
"github.com/databricks/cli/libs/dbr"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/diag"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -128,8 +128,8 @@ func TestApplyPresetsSourceLinkedDeployment(t *testing.T) {
tt.mutateBundle(b)
}

bundletest.SetLocation(b, "presets.source_linked_deployment", []dyn.Location{{File: "databricks.yml"}})
bundletest.SetLocation(b, "workspace.file_path", []dyn.Location{{File: "databricks.yml"}})
bundletest.SetLocation(b, "presets.source_linked_deployment", []diag.Location{{File: "databricks.yml"}})
bundletest.SetLocation(b, "workspace.file_path", []diag.Location{{File: "databricks.yml"}})

diags := bundle.Apply(tt.ctx, b, mutator.ApplySourceLinkedDeploymentPreset())
if diags.HasError() && tt.expectedError == "" {
Expand Down
6 changes: 3 additions & 3 deletions bundle/config/mutator/load_dbalert_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/databricks/cli/bundle/config/mutator"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/bundle/internal/bundletest"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/databricks-sdk-go/service/sql"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestLoadDBAlertFiles(t *testing.T) {
},
}

bundletest.SetLocation(b, "resources.alerts.my_alert", []dyn.Location{{
bundletest.SetLocation(b, "resources.alerts.my_alert", []diag.Location{{
File: filepath.Join(dir, "databricks.yml"),
}})

Expand Down Expand Up @@ -109,7 +109,7 @@ func TestLoadDBAlertFilesRelativeToBundleRoot(t *testing.T) {
},
}

bundletest.SetLocation(b, "resources.alerts.my_alert", []dyn.Location{{
bundletest.SetLocation(b, "resources.alerts.my_alert", []diag.Location{{
File: filepath.Join(dir, "databricks.yml"),
}})

Expand Down
4 changes: 2 additions & 2 deletions bundle/config/mutator/normalize_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func collectGitSourcePaths(b *bundle.Bundle) []dyn.Path {
return jobs
}

func normalizePath(path string, location dyn.Location, bundleRootPath string) (string, error) {
func normalizePath(path string, location diag.Location, bundleRootPath string) (string, error) {
// Handle local file paths used inside pip flags
for _, flag := range libraries.PipFlagsWithLocalPaths {
reqPath, ok := strings.CutPrefix(path, flag+" ")
Expand Down Expand Up @@ -134,7 +134,7 @@ func normalizePath(path string, location dyn.Location, bundleRootPath string) (s
return filepath.ToSlash(filepath.Join(relDir, path)), nil
}

func locationDirectory(l dyn.Location) (string, error) {
func locationDirectory(l diag.Location) (string, error) {
if l.File == "" {
return "", errors.New("no file in location")
}
Expand Down
21 changes: 11 additions & 10 deletions bundle/config/mutator/normalize_paths_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/config/resources"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/databricks-sdk-go/service/jobs"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -36,11 +37,11 @@ func TestNormalizePaths(t *testing.T) {
}

// update config as if 'notebook_path' property is defined in resources/job_1.yml
location := dyn.Location{File: filepath.Join(tmpDir, "resources", "job_1.yml")}
location := diag.Location{File: filepath.Join(tmpDir, "resources", "job_1.yml")}
path := dyn.MustPathFromString("resources.jobs.job1.tasks[0].notebook_task.notebook_path")
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
return dyn.MapByPath(v, path, func(path dyn.Path, value dyn.Value) (dyn.Value, error) {
return dyn.NewValue(value.MustString(), []dyn.Location{location}), nil
return dyn.NewValue(value.MustString(), []diag.Location{location}), nil
})
})
require.NoError(t, err)
Expand Down Expand Up @@ -75,11 +76,11 @@ func TestNormalizePaths_jobRunOnFileChange(t *testing.T) {
BundleRootPath: tmpDir,
}

location := dyn.Location{File: filepath.Join(tmpDir, "resources", "run.yml")}
location := diag.Location{File: filepath.Join(tmpDir, "resources", "run.yml")}
path := dyn.MustPathFromString("resources.job_runs.run1.lifecycle.triggers[0].on_file_change")
err := b.Config.Mutate(func(v dyn.Value) (dyn.Value, error) {
return dyn.MapByPath(v, path, func(path dyn.Path, value dyn.Value) (dyn.Value, error) {
return dyn.NewValue(value.MustString(), []dyn.Location{location}), nil
return dyn.NewValue(value.MustString(), []diag.Location{location}), nil
})
})
require.NoError(t, err)
Expand All @@ -93,20 +94,20 @@ func TestNormalizePaths_jobRunOnFileChange(t *testing.T) {
}

func TestNormalizePath_absolutePath(t *testing.T) {
value, err := normalizePath("/notebook.py", dyn.Location{}, "/tmp")
value, err := normalizePath("/notebook.py", diag.Location{}, "/tmp")
assert.NoError(t, err)
assert.Equal(t, "/notebook.py", value)
}

func TestNormalizePath_url(t *testing.T) {
value, err := normalizePath("s3:///path/to/notebook.py", dyn.Location{}, "/tmp")
value, err := normalizePath("s3:///path/to/notebook.py", diag.Location{}, "/tmp")
assert.NoError(t, err)
assert.Equal(t, "s3:///path/to/notebook.py", value)
}

func TestNormalizePath_requirementsFile(t *testing.T) {
tmpDir := t.TempDir()
location := dyn.Location{File: filepath.Join(tmpDir, "resources", "job_1.yml")}
location := diag.Location{File: filepath.Join(tmpDir, "resources", "job_1.yml")}
value, err := normalizePath("-r ../requirements.txt", location, tmpDir)
assert.NoError(t, err)
assert.Equal(t, "-r requirements.txt", value)
Expand All @@ -118,21 +119,21 @@ func TestNormalizePath_requirementsFile(t *testing.T) {

func TestNormalizePath_environmentDependency(t *testing.T) {
tmpDir := t.TempDir()
location := dyn.Location{File: filepath.Join(tmpDir, "resources", "job_1.yml")}
location := diag.Location{File: filepath.Join(tmpDir, "resources", "job_1.yml")}
value, err := normalizePath("-e ../file.py", location, tmpDir)
assert.NoError(t, err)
assert.Equal(t, "-e file.py", value)
}

func TestLocationDirectory(t *testing.T) {
loc := dyn.Location{File: "file", Line: 1, Column: 2}
loc := diag.Location{File: "file", Line: 1, Column: 2}
dir, err := locationDirectory(loc)
assert.NoError(t, err)
assert.Equal(t, ".", dir)
}

func TestLocationDirectoryNoFile(t *testing.T) {
loc := dyn.Location{}
loc := diag.Location{}
_, err := locationDirectory(loc)
assert.Error(t, err)
}
4 changes: 2 additions & 2 deletions bundle/config/mutator/prepend_workspace_prefix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/databricks/cli/bundle"
"github.com/databricks/cli/bundle/config"
"github.com/databricks/cli/bundle/internal/bundletest"
"github.com/databricks/cli/libs/dyn"
"github.com/databricks/cli/libs/diag"
"github.com/databricks/databricks-sdk-go/service/iam"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestPrependWorkspacePrefixPreservesLocations(t *testing.T) {
},
},
}
locations := []dyn.Location{{File: "databricks.yml", Line: 42, Column: 5}}
locations := []diag.Location{{File: "databricks.yml", Line: 42, Column: 5}}
bundletest.SetLocation(b, "workspace.root_path", locations)

diags := bundle.Apply(t.Context(), b, PrependWorkspacePrefix())
Expand Down
15 changes: 8 additions & 7 deletions bundle/config/mutator/python/apply_python_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/databricks/cli/bundle/config/mutator/resourcemutator"

"github.com/databricks/cli/libs/diag"
"github.com/databricks/cli/libs/dyn/merge"

"github.com/databricks/cli/libs/dyn"
Expand Down Expand Up @@ -196,7 +197,7 @@ func TestCreateOverrideVisitor_omitempty(t *testing.T) {
// there is no semantic difference between empty and missing, so we keep them as they were before
// Python code deleted them.

location := dyn.Location{
location := diag.Location{
File: "databricks.yml",
Line: 10,
Column: 20,
Expand All @@ -206,38 +207,38 @@ func TestCreateOverrideVisitor_omitempty(t *testing.T) {
{
name: "undo delete of empty variables",
path: dyn.MustPathFromString("variables"),
left: dyn.NewValue([]dyn.Value{}, []dyn.Location{location}),
left: dyn.NewValue([]dyn.Value{}, []diag.Location{location}),
expectedErr: merge.ErrOverrideUndoDelete,
},
{
name: "undo delete of empty job clusters",
path: dyn.MustPathFromString("resources.jobs.job0.job_clusters"),
left: dyn.NewValue([]dyn.Value{}, []dyn.Location{location}),
left: dyn.NewValue([]dyn.Value{}, []diag.Location{location}),
expectedErr: merge.ErrOverrideUndoDelete,
},
{
name: "allow delete of non-empty job clusters",
path: dyn.MustPathFromString("resources.jobs.job0.job_clusters"),
left: dyn.NewValue([]dyn.Value{dyn.NewValue("abc", []dyn.Location{location})}, []dyn.Location{location}),
left: dyn.NewValue([]dyn.Value{dyn.NewValue("abc", []diag.Location{location})}, []diag.Location{location}),
expectedErr: nil,
},
{
name: "undo delete of empty tags",
path: dyn.MustPathFromString("resources.jobs.job0.tags"),
left: dyn.NewValue(map[string]dyn.Value{}, []dyn.Location{location}),
left: dyn.NewValue(map[string]dyn.Value{}, []diag.Location{location}),
expectedErr: merge.ErrOverrideUndoDelete,
},
{
name: "allow delete of non-empty tags",
path: dyn.MustPathFromString("resources.jobs.job0.tags"),
left: dyn.NewValue(map[string]dyn.Value{"dev": dyn.NewValue("true", []dyn.Location{location})}, []dyn.Location{location}),
left: dyn.NewValue(map[string]dyn.Value{"dev": dyn.NewValue("true", []diag.Location{location})}, []diag.Location{location}),

expectedErr: nil,
},
{
name: "undo delete of nil",
path: dyn.MustPathFromString("resources.jobs.job0.tags"),
left: dyn.NilValue.WithLocations([]dyn.Location{location}),
left: dyn.NilValue.WithLocations([]diag.Location{location}),
expectedErr: merge.ErrOverrideUndoDelete,
},
}
Expand Down
Loading
Loading