diff --git a/bundle/apps/validate_test.go b/bundle/apps/validate_test.go index 3285851ce91..89b4e1d5907 100644 --- a/bundle/apps/validate_test.go +++ b/bundle/apps/validate_test.go @@ -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" @@ -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) @@ -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) @@ -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) diff --git a/bundle/artifacts/expand_globs.go b/bundle/artifacts/expand_globs.go index e7cd5cc1308..cc5d1f3fb60 100644 --- a/bundle/artifacts/expand_globs.go +++ b/bundle/artifacts/expand_globs.go @@ -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), } } diff --git a/bundle/artifacts/prepare.go b/bundle/artifacts/prepare.go index ae93f946c19..e285eb1ee30 100644 --- a/bundle/artifacts/prepare.go +++ b/bundle/artifacts/prepare.go @@ -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" @@ -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 } diff --git a/bundle/config/loader/process_include.go b/bundle/config/loader/process_include.go index dd8932caeed..064855caca2 100644 --- a/bundle/config/loader/process_include.go +++ b/bundle/config/loader/process_include.go @@ -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 { diff --git a/bundle/config/loader/process_include_test.go b/bundle/config/loader/process_include_test.go index 28c95ac905b..16ed455e622 100644 --- a/bundle/config/loader/process_include_test.go +++ b/bundle/config/loader/process_include_test.go @@ -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" @@ -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}, }, @@ -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}, }, @@ -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}, }, @@ -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}, }, @@ -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}, }, @@ -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}, }, @@ -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}, diff --git a/bundle/config/mutator/apply_source_linked_deployment_preset_test.go b/bundle/config/mutator/apply_source_linked_deployment_preset_test.go index c0371077537..8d50788a3b3 100644 --- a/bundle/config/mutator/apply_source_linked_deployment_preset_test.go +++ b/bundle/config/mutator/apply_source_linked_deployment_preset_test.go @@ -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" ) @@ -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 == "" { diff --git a/bundle/config/mutator/load_dbalert_files_test.go b/bundle/config/mutator/load_dbalert_files_test.go index 24d20a28d29..5e8a8d896e6 100644 --- a/bundle/config/mutator/load_dbalert_files_test.go +++ b/bundle/config/mutator/load_dbalert_files_test.go @@ -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" @@ -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"), }}) @@ -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"), }}) diff --git a/bundle/config/mutator/normalize_paths.go b/bundle/config/mutator/normalize_paths.go index ecab0e812db..7256ebad4b7 100644 --- a/bundle/config/mutator/normalize_paths.go +++ b/bundle/config/mutator/normalize_paths.go @@ -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+" ") @@ -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") } diff --git a/bundle/config/mutator/normalize_paths_test.go b/bundle/config/mutator/normalize_paths_test.go index 9ad1dcad128..9c9085a27c6 100644 --- a/bundle/config/mutator/normalize_paths_test.go +++ b/bundle/config/mutator/normalize_paths_test.go @@ -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" @@ -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) @@ -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) @@ -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) @@ -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) } diff --git a/bundle/config/mutator/prepend_workspace_prefix_test.go b/bundle/config/mutator/prepend_workspace_prefix_test.go index 93b3acde922..6c439247051 100644 --- a/bundle/config/mutator/prepend_workspace_prefix_test.go +++ b/bundle/config/mutator/prepend_workspace_prefix_test.go @@ -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" ) @@ -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()) diff --git a/bundle/config/mutator/python/apply_python_output_test.go b/bundle/config/mutator/python/apply_python_output_test.go index 2d64d6c4bbc..94d7e7c39cc 100644 --- a/bundle/config/mutator/python/apply_python_output_test.go +++ b/bundle/config/mutator/python/apply_python_output_test.go @@ -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" @@ -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, @@ -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, }, } diff --git a/bundle/config/mutator/python/python_diagnostics.go b/bundle/config/mutator/python/python_diagnostics.go index b947b3f6ad3..e47f6fb89ae 100644 --- a/bundle/config/mutator/python/python_diagnostics.go +++ b/bundle/config/mutator/python/python_diagnostics.go @@ -61,9 +61,9 @@ func parsePythonDiagnostics(input io.Reader) (diag.Diagnostics, error) { paths = dyn.ToStructPaths(path) } - var locations []dyn.Location + var locations []diag.Location location := convertPythonLocation(parsedLine.Location) - if location != (dyn.Location{}) { + if location != (diag.Location{}) { locations = append(locations, location) } @@ -100,8 +100,8 @@ func convertPythonSeverity(severity pythonSeverity) (diag.Severity, error) { } } -func convertPythonLocation(location pythonDiagnosticLocation) dyn.Location { - return dyn.Location{ +func convertPythonLocation(location pythonDiagnosticLocation) diag.Location { + return diag.Location{ File: location.File, Line: location.Line, Column: location.Column, diff --git a/bundle/config/mutator/python/python_diagnostics_test.go b/bundle/config/mutator/python/python_diagnostics_test.go index 43709031ca2..faba60e7498 100644 --- a/bundle/config/mutator/python/python_diagnostics_test.go +++ b/bundle/config/mutator/python/python_diagnostics_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/structs/structpath" "github.com/stretchr/testify/assert" ) @@ -17,7 +16,7 @@ func TestConvertPythonLocation(t *testing.T) { Column: 2, }) - assert.Equal(t, dyn.Location{ + assert.Equal(t, diag.Location{ File: "src/examples/file.py", Line: 1, Column: 2, @@ -39,7 +38,7 @@ func TestParsePythonDiagnostics(t *testing.T) { { Severity: diag.Error, Summary: "error summary", - Locations: []dyn.Location{ + Locations: []diag.Location{ { File: "src/examples/file.py", Line: 1, diff --git a/bundle/config/mutator/python/python_locations.go b/bundle/config/mutator/python/python_locations.go index 9cb65c302e5..5f85edfc488 100644 --- a/bundle/config/mutator/python/python_locations.go +++ b/bundle/config/mutator/python/python_locations.go @@ -7,12 +7,13 @@ import ( pathlib "path" "path/filepath" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" ) // generatedFileName is used as the virtual file name for YAML generated by Python code. // -// mergePythonLocations replaces dyn.Location with generatedFileName with locations loaded +// mergePythonLocations replaces diag.Location with generatedFileName with locations loaded // from locations.json const generatedFileName = "__generated_by_python__.yml" @@ -42,7 +43,7 @@ type pythonLocations struct { indexes map[int]*pythonLocations // location for the current node if it exists - location dyn.Location + location diag.Location // if true, location is present exists bool @@ -75,7 +76,7 @@ func mergePythonLocations(value dyn.Value, locations *pythonLocations) (dyn.Valu // We preserve any previous non-virtual locations in case when Python function modified // resource defined in YAML. newLocations := append( - []dyn.Location{newLocation}, + []diag.Location{newLocation}, removeVirtualLocations(value.Locations())..., ) @@ -83,8 +84,8 @@ func mergePythonLocations(value dyn.Value, locations *pythonLocations) (dyn.Valu }) } -func removeVirtualLocations(locations []dyn.Location) []dyn.Location { - var newLocations []dyn.Location +func removeVirtualLocations(locations []diag.Location) []diag.Location { + var newLocations []diag.Location for _, location := range locations { if filepath.Base(location.File) == generatedFileName { @@ -123,7 +124,7 @@ func parsePythonLocations(bundleRoot string, input io.Reader) (*pythonLocations, entry.File = filepath.Join(bundleRoot, entry.File) } - location := dyn.Location{ + location := diag.Location{ File: entry.File, Line: entry.Line, Column: entry.Column, @@ -136,7 +137,7 @@ func parsePythonLocations(bundleRoot string, input io.Reader) (*pythonLocations, } // putPythonLocation puts the location to the trie for the given path -func putPythonLocation(trie *pythonLocations, path dyn.Path, location dyn.Location) { +func putPythonLocation(trie *pythonLocations, path dyn.Path, location diag.Location) { currentNode := trie for _, component := range path { @@ -170,7 +171,7 @@ func newPythonLocations() *pythonLocations { // findPythonLocation finds the location or closest ancestor location in the trie for the given path // if no ancestor or exact location is found, false is returned. -func findPythonLocation(locations *pythonLocations, path dyn.Path) (dyn.Location, bool) { +func findPythonLocation(locations *pythonLocations, path dyn.Path) (diag.Location, bool) { currentNode := locations lastLocation := locations.location exists := locations.exists diff --git a/bundle/config/mutator/python/python_locations_test.go b/bundle/config/mutator/python/python_locations_test.go index 9c5b33d3b59..2bc815e7cdc 100644 --- a/bundle/config/mutator/python/python_locations_test.go +++ b/bundle/config/mutator/python/python_locations_test.go @@ -13,9 +13,9 @@ import ( ) func TestMergeLocations(t *testing.T) { - pythonLocation := dyn.Location{File: "foo.py", Line: 1, Column: 1} - generatedLocation := dyn.Location{File: generatedFileName, Line: 1, Column: 1} - yamlLocation := dyn.Location{File: "foo.yml", Line: 1, Column: 1} + pythonLocation := diag.Location{File: "foo.py", Line: 1, Column: 1} + generatedLocation := diag.Location{File: generatedFileName, Line: 1, Column: 1} + yamlLocation := diag.Location{File: "foo.yml", Line: 1, Column: 1} locations := newPythonLocations() putPythonLocation(locations, dyn.MustPathFromString("foo"), pythonLocation) @@ -24,13 +24,13 @@ func TestMergeLocations(t *testing.T) { map[string]dyn.Value{ "foo": dyn.V( map[string]dyn.Value{ - "baz": dyn.NewValue("baz", []dyn.Location{yamlLocation}), - "qux": dyn.NewValue("baz", []dyn.Location{generatedLocation, yamlLocation}), + "baz": dyn.NewValue("baz", []diag.Location{yamlLocation}), + "qux": dyn.NewValue("baz", []diag.Location{generatedLocation, yamlLocation}), }, ), - "bar": dyn.NewValue("baz", []dyn.Location{generatedLocation}), + "bar": dyn.NewValue("baz", []diag.Location{generatedLocation}), }, - []dyn.Location{yamlLocation}, + []diag.Location{yamlLocation}, ) expected := dyn.NewValue( @@ -38,16 +38,16 @@ func TestMergeLocations(t *testing.T) { "foo": dyn.NewValue( map[string]dyn.Value{ // pythonLocation is appended to the beginning of the list if absent - "baz": dyn.NewValue("baz", []dyn.Location{pythonLocation, yamlLocation}), + "baz": dyn.NewValue("baz", []diag.Location{pythonLocation, yamlLocation}), // generatedLocation is replaced by pythonLocation - "qux": dyn.NewValue("baz", []dyn.Location{pythonLocation, yamlLocation}), + "qux": dyn.NewValue("baz", []diag.Location{pythonLocation, yamlLocation}), }, - []dyn.Location{pythonLocation}, + []diag.Location{pythonLocation}, ), // if location is unknown, we keep it as-is - "bar": dyn.NewValue("baz", []dyn.Location{generatedLocation}), + "bar": dyn.NewValue("baz", []diag.Location{generatedLocation}), }, - []dyn.Location{yamlLocation}, + []diag.Location{yamlLocation}, ) actual, err := mergePythonLocations(input, locations) @@ -57,8 +57,8 @@ func TestMergeLocations(t *testing.T) { } func TestFindLocation(t *testing.T) { - location0 := dyn.Location{File: "foo.py", Line: 1, Column: 1} - location1 := dyn.Location{File: "foo.py", Line: 2, Column: 1} + location0 := diag.Location{File: "foo.py", Line: 1, Column: 1} + location1 := diag.Location{File: "foo.py", Line: 2, Column: 1} locations := newPythonLocations() putPythonLocation(locations, dyn.MustPathFromString("foo"), location0) @@ -71,9 +71,9 @@ func TestFindLocation(t *testing.T) { } func TestFindLocation_indexPathComponent(t *testing.T) { - location0 := dyn.Location{File: "foo.py", Line: 1, Column: 1} - location1 := dyn.Location{File: "foo.py", Line: 2, Column: 1} - location2 := dyn.Location{File: "foo.py", Line: 3, Column: 1} + location0 := diag.Location{File: "foo.py", Line: 1, Column: 1} + location1 := diag.Location{File: "foo.py", Line: 2, Column: 1} + location2 := diag.Location{File: "foo.py", Line: 3, Column: 1} locations := newPythonLocations() putPythonLocation(locations, dyn.MustPathFromString("foo"), location0) @@ -87,8 +87,8 @@ func TestFindLocation_indexPathComponent(t *testing.T) { } func TestFindLocation_closestAncestorLocation(t *testing.T) { - location0 := dyn.Location{File: "foo.py", Line: 1, Column: 1} - location1 := dyn.Location{File: "foo.py", Line: 2, Column: 1} + location0 := diag.Location{File: "foo.py", Line: 1, Column: 1} + location1 := diag.Location{File: "foo.py", Line: 2, Column: 1} locations := newPythonLocations() putPythonLocation(locations, dyn.MustPathFromString("foo"), location0) @@ -101,8 +101,8 @@ func TestFindLocation_closestAncestorLocation(t *testing.T) { } func TestFindLocation_unknownLocation(t *testing.T) { - location0 := dyn.Location{File: "foo.py", Line: 1, Column: 1} - location1 := dyn.Location{File: "foo.py", Line: 2, Column: 1} + location0 := diag.Location{File: "foo.py", Line: 1, Column: 1} + location1 := diag.Location{File: "foo.py", Line: 2, Column: 1} locations := newPythonLocations() putPythonLocation(locations, dyn.MustPathFromString("foo"), location0) @@ -114,7 +114,7 @@ func TestFindLocation_unknownLocation(t *testing.T) { } func TestLoadOutput(t *testing.T) { - location := dyn.Location{File: "my_job.py", Line: 1, Column: 1} + location := diag.Location{File: "my_job.py", Line: 1, Column: 1} bundleRoot := t.TempDir() output := `{ "resources": { @@ -151,12 +151,12 @@ func TestLoadOutput(t *testing.T) { name, err := dyn.Get(value, "resources.jobs.my_job.name") require.NoError(t, err) - require.Equal(t, []dyn.Location{location}, name.Locations()) + require.Equal(t, []diag.Location{location}, name.Locations()) } func TestParsePythonLocations_absolutePath(t *testing.T) { // output can contain absolute path that is outside of the bundle root - expected := dyn.Location{File: "/Shared/foo.py", Line: 1, Column: 2} + expected := diag.Location{File: "/Shared/foo.py", Line: 1, Column: 2} input := `{"path": "foo", "file": "/Shared/foo.py", "line": 1, "column": 2}` reader := bytes.NewReader([]byte(input)) @@ -171,7 +171,7 @@ func TestParsePythonLocations_absolutePath(t *testing.T) { func TestParsePythonLocations_relativePath(t *testing.T) { // output can contain relative paths, we expect all locations to be absolute // at this stage of mutator pipeline - expected := dyn.Location{File: filepath.Clean("/tmp/my_project/foo.py"), Line: 1, Column: 2} + expected := diag.Location{File: filepath.Clean("/tmp/my_project/foo.py"), Line: 1, Column: 2} input := `{"path": "foo", "file": "foo.py", "line": 1, "column": 2}` reader := bytes.NewReader([]byte(input)) diff --git a/bundle/config/mutator/python/python_mutator.go b/bundle/config/mutator/python/python_mutator.go index 9112aaa808d..90d7f9ff287 100644 --- a/bundle/config/mutator/python/python_mutator.go +++ b/bundle/config/mutator/python/python_mutator.go @@ -511,7 +511,7 @@ func loadOutput(rootPath string, outputFile io.Reader, locations *pythonLocation return dyn.InvalidValue, diag.FromErr(fmt.Errorf("failed to parse output file: %w", err)) } - // generated has dyn.Location as if it comes from generated YAML file + // generated has diag.Location as if it comes from generated YAML file // earlier we loaded locations.json with source locations in Python code generatedWithLocations, err := mergePythonLocations(generated, locations) if err != nil { diff --git a/bundle/config/mutator/python/python_mutator_test.go b/bundle/config/mutator/python/python_mutator_test.go index 9b106f727bf..f2c91749e87 100644 --- a/bundle/config/mutator/python/python_mutator_test.go +++ b/bundle/config/mutator/python/python_mutator_test.go @@ -11,6 +11,7 @@ import ( "slices" "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn/convert" "github.com/databricks/cli/bundle/env" @@ -54,7 +55,7 @@ resources: name: job_0 workspace: { current_user: { userName: test }}`) - // set rootPath so that we can make absolute paths in dyn.Location + // set rootPath so that we can make absolute paths in diag.Location b.BundleRootPath = rootPath ctx := withProcessStub( @@ -124,7 +125,7 @@ workspace: { current_user: { userName: test }}`) // location is databricks.yml, because output contains resource as-is jobName0, err := dyn.GetByPath(v, dyn.MustPathFromString("resources.jobs.job0.name")) require.NoError(t, err) - assert.Equal(t, []dyn.Location{ + assert.Equal(t, []diag.Location{ { File: "databricks.yml", Line: 9, @@ -134,7 +135,7 @@ workspace: { current_user: { userName: test }}`) jobName1, err := dyn.GetByPath(v, dyn.MustPathFromString("resources.jobs.job1.name")) require.NoError(t, err) - assert.Equal(t, []dyn.Location{ + assert.Equal(t, []diag.Location{ { File: filepath.Join(rootPath, "src/examples/job1.py"), Line: 5, @@ -144,7 +145,7 @@ workspace: { current_user: { userName: test }}`) pipelineName0, err := dyn.GetByPath(v, dyn.MustPathFromString("resources.pipelines.pipeline0.name")) require.NoError(t, err) - assert.Equal(t, []dyn.Location{ + assert.Equal(t, []diag.Location{ { File: filepath.Join(rootPath, "src/examples/pipeline0.py"), Line: 7, @@ -161,7 +162,7 @@ workspace: { current_user: { userName: test }}`) assert.Len(t, diags, 1) assert.Equal(t, "job doesn't have any tasks", diags[0].Summary) - assert.Equal(t, []dyn.Location{ + assert.Equal(t, []diag.Location{ { File: "src/examples/file.py", Line: 10, diff --git a/bundle/config/mutator/resourcemutator/apply_presets.go b/bundle/config/mutator/resourcemutator/apply_presets.go index f4e555ed7f3..bb84240d7cc 100644 --- a/bundle/config/mutator/resourcemutator/apply_presets.go +++ b/bundle/config/mutator/resourcemutator/apply_presets.go @@ -11,7 +11,6 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/metrics" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/textutil" "github.com/databricks/databricks-sdk-go/service/catalog" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -353,7 +352,7 @@ func validatePauseStatus(b *bundle.Bundle) diag.Diagnostics { return diag.Diagnostics{{ Summary: "Invalid value for trigger_pause_status, should be PAUSED or UNPAUSED", Severity: diag.Error, - Locations: []dyn.Location{b.Config.GetLocation("presets.trigger_pause_status")}, + Locations: []diag.Location{b.Config.GetLocation("presets.trigger_pause_status")}, }} } diff --git a/bundle/config/mutator/resourcemutator/expand_pipeline_glob_paths_test.go b/bundle/config/mutator/resourcemutator/expand_pipeline_glob_paths_test.go index 56440f7cd1c..ead2084d835 100644 --- a/bundle/config/mutator/resourcemutator/expand_pipeline_glob_paths_test.go +++ b/bundle/config/mutator/resourcemutator/expand_pipeline_glob_paths_test.go @@ -14,7 +14,7 @@ import ( "github.com/databricks/cli/bundle/config" "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/compute" "github.com/databricks/databricks-sdk-go/service/pipelines" "github.com/stretchr/testify/require" @@ -110,8 +110,8 @@ func TestExpandGlobPathsInPipelines(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) - bundletest.SetLocation(b, "resources.pipelines.pipeline.libraries[3]", []dyn.Location{{File: filepath.Join(dir, "relative", "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, "resources.pipelines.pipeline.libraries[3]", []diag.Location{{File: filepath.Join(dir, "relative", "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), resourcemutator.ExpandPipelineGlobPaths()) require.NoError(t, diags.Error()) diff --git a/bundle/config/mutator/resourcemutator/model_serving_endpoint_fixups.go b/bundle/config/mutator/resourcemutator/model_serving_endpoint_fixups.go index 87962a85e86..6c25146e6bd 100644 --- a/bundle/config/mutator/resourcemutator/model_serving_endpoint_fixups.go +++ b/bundle/config/mutator/resourcemutator/model_serving_endpoint_fixups.go @@ -5,7 +5,6 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/utils" "github.com/databricks/databricks-sdk-go/service/serving" ) @@ -56,7 +55,7 @@ func (m *modelServingEndpointFixups) Apply(ctx context.Context, b *bundle.Bundle Severity: diag.Error, Summary: "Cannot use both served_models and served_entities", Detail: "Model serving endpoint cannot specify both served_models and served_entities at the same time.", - Locations: []dyn.Location{ + Locations: []diag.Location{ b.Config.GetLocation("resources.model_serving_endpoints." + key), }, }) @@ -71,7 +70,7 @@ func (m *modelServingEndpointFixups) Apply(ctx context.Context, b *bundle.Bundle Severity: diag.Warning, Summary: "Using served_models is deprecated", Detail: "The served_models field is deprecated. Please use served_entities instead.", - Locations: []dyn.Location{ + Locations: []diag.Location{ b.Config.GetLocation("resources.model_serving_endpoints." + key + ".config.served_models"), }, }) diff --git a/bundle/config/mutator/resourcemutator/run_as.go b/bundle/config/mutator/resourcemutator/run_as.go index b36e915b372..65279c7f212 100644 --- a/bundle/config/mutator/resourcemutator/run_as.go +++ b/bundle/config/mutator/resourcemutator/run_as.go @@ -32,12 +32,12 @@ func (m *setRunAs) Name() string { return "SetRunAs" } -func reportRunAsNotSupported(resourceType string, location dyn.Location, currentUser, runAsUser string) diag.Diagnostics { +func reportRunAsNotSupported(resourceType string, location diag.Location, currentUser, runAsUser string) diag.Diagnostics { return diag.Diagnostics{{ Summary: fmt.Sprintf("%s do not support a setting a run_as user that is different from the owner.\n"+ "Current identity: %s. Run as identity: %s.\n"+ "See https://docs.databricks.com/dev-tools/bundles/run-as.html to learn more about the run_as property.", resourceType, currentUser, runAsUser), - Locations: []dyn.Location{location}, + Locations: []diag.Location{location}, Severity: diag.Error, }} } @@ -57,7 +57,7 @@ func validateRunAs(b *bundle.Bundle) diag.Diagnostics { if identityCount != 1 { return diag.Diagnostics{{ Summary: "run_as section must specify exactly one non-empty identity: user_name, service_principal_name, or group_name", - Locations: []dyn.Location{b.Config.GetLocation("run_as")}, + Locations: []diag.Location{b.Config.GetLocation("run_as")}, Severity: diag.Error, }} } diff --git a/bundle/config/mutator/resourcemutator/run_as_test.go b/bundle/config/mutator/resourcemutator/run_as_test.go index 10ad8fd9dbb..5d1aa602d02 100644 --- a/bundle/config/mutator/resourcemutator/run_as_test.go +++ b/bundle/config/mutator/resourcemutator/run_as_test.go @@ -10,6 +10,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/cli/libs/dyn/convert" "github.com/databricks/databricks-sdk-go/service/iam" @@ -416,7 +417,7 @@ func TestRunAsIdentities(t *testing.T) { diags = bundle.Apply(t.Context(), b, SetRunAs()) if tc.wantError { require.ErrorContains(t, diags.Error(), "run_as section must specify exactly one non-empty identity: user_name, service_principal_name, or group_name") - assert.Equal(t, []dyn.Location{r.GetLocation("run_as")}, diags[0].Locations) + assert.Equal(t, []diag.Location{r.GetLocation("run_as")}, diags[0].Locations) } else { require.NoError(t, diags.Error()) } diff --git a/bundle/config/mutator/resourcemutator/secret_scope_fixups.go b/bundle/config/mutator/resourcemutator/secret_scope_fixups.go index 0d5d541a6ee..8404d2444eb 100644 --- a/bundle/config/mutator/resourcemutator/secret_scope_fixups.go +++ b/bundle/config/mutator/resourcemutator/secret_scope_fixups.go @@ -9,7 +9,6 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/iamutil" "github.com/databricks/cli/libs/structs/structpath" "github.com/databricks/databricks-sdk-go/service/iam" @@ -140,7 +139,7 @@ func (m *secretScopeFixups) Apply(ctx context.Context, b *bundle.Bundle) diag.Di Summary: "Failed to collapse permissions for secret scope", Detail: err.Error(), Paths: structpath.NewPathSlice("resources", "secret_scopes", key), - Locations: []dyn.Location{b.Config.GetLocationOf(structpath.NewPath(nil, "resources", "secret_scopes", key))}, + Locations: []diag.Location{b.Config.GetLocationOf(structpath.NewPath(nil, "resources", "secret_scopes", key))}, }, } } diff --git a/bundle/config/mutator/resourcemutator/validate_target_mode.go b/bundle/config/mutator/resourcemutator/validate_target_mode.go index d100c327fe8..825d7267665 100644 --- a/bundle/config/mutator/resourcemutator/validate_target_mode.go +++ b/bundle/config/mutator/resourcemutator/validate_target_mode.go @@ -5,7 +5,6 @@ import ( "fmt" "strings" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/iamutil" "github.com/databricks/cli/bundle" @@ -55,7 +54,7 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics { diags = diags.Append(diag.Diagnostic{ Severity: diag.Error, Summary: "target with 'mode: development' cannot set trigger pause status to UNPAUSED by default", - Locations: []dyn.Location{b.Config.GetLocation("presets.trigger_pause_status")}, + Locations: []diag.Location{b.Config.GetLocation("presets.trigger_pause_status")}, }) } @@ -77,7 +76,7 @@ func validateDevelopmentMode(b *bundle.Bundle) diag.Diagnostics { diags = diags.Append(diag.Diagnostic{ Severity: diag.Error, Summary: "prefix should contain the current username or ${workspace.current_user.short_name} to ensure uniqueness when using 'mode: development'", - Locations: []dyn.Location{b.Config.GetLocation("presets.name_prefix")}, + Locations: []diag.Location{b.Config.GetLocation("presets.name_prefix")}, }) } return diags diff --git a/bundle/config/mutator/rewrite_sync_paths_test.go b/bundle/config/mutator/rewrite_sync_paths_test.go index 2b9d291ddd8..e01b5cc8eee 100644 --- a/bundle/config/mutator/rewrite_sync_paths_test.go +++ b/bundle/config/mutator/rewrite_sync_paths_test.go @@ -8,7 +8,7 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/mutator" "github.com/databricks/cli/bundle/internal/bundletest" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" "github.com/stretchr/testify/assert" ) @@ -33,12 +33,12 @@ func TestRewriteSyncPathsRelative(t *testing.T) { }, } - bundletest.SetLocation(b, "sync.paths[0]", []dyn.Location{{File: "./databricks.yml"}}) - bundletest.SetLocation(b, "sync.paths[1]", []dyn.Location{{File: "./databricks.yml"}}) - bundletest.SetLocation(b, "sync.include[0]", []dyn.Location{{File: "./file.yml"}}) - bundletest.SetLocation(b, "sync.include[1]", []dyn.Location{{File: "./a/file.yml"}}) - bundletest.SetLocation(b, "sync.exclude[0]", []dyn.Location{{File: "./a/b/file.yml"}}) - bundletest.SetLocation(b, "sync.exclude[1]", []dyn.Location{{File: "./a/b/c/file.yml"}}) + bundletest.SetLocation(b, "sync.paths[0]", []diag.Location{{File: "./databricks.yml"}}) + bundletest.SetLocation(b, "sync.paths[1]", []diag.Location{{File: "./databricks.yml"}}) + bundletest.SetLocation(b, "sync.include[0]", []diag.Location{{File: "./file.yml"}}) + bundletest.SetLocation(b, "sync.include[1]", []diag.Location{{File: "./a/file.yml"}}) + bundletest.SetLocation(b, "sync.exclude[0]", []diag.Location{{File: "./a/b/file.yml"}}) + bundletest.SetLocation(b, "sync.exclude[1]", []diag.Location{{File: "./a/b/c/file.yml"}}) diags := bundle.Apply(t.Context(), b, mutator.RewriteSyncPaths()) assert.NoError(t, diags.Error()) @@ -72,12 +72,12 @@ func TestRewriteSyncPathsAbsolute(t *testing.T) { }, } - bundletest.SetLocation(b, "sync.paths[0]", []dyn.Location{{File: "/tmp/dir/databricks.yml"}}) - bundletest.SetLocation(b, "sync.paths[1]", []dyn.Location{{File: "/tmp/dir/databricks.yml"}}) - bundletest.SetLocation(b, "sync.include[0]", []dyn.Location{{File: "/tmp/dir/file.yml"}}) - bundletest.SetLocation(b, "sync.include[1]", []dyn.Location{{File: "/tmp/dir/a/file.yml"}}) - bundletest.SetLocation(b, "sync.exclude[0]", []dyn.Location{{File: "/tmp/dir/a/b/file.yml"}}) - bundletest.SetLocation(b, "sync.exclude[1]", []dyn.Location{{File: "/tmp/dir/a/b/c/file.yml"}}) + bundletest.SetLocation(b, "sync.paths[0]", []diag.Location{{File: "/tmp/dir/databricks.yml"}}) + bundletest.SetLocation(b, "sync.paths[1]", []diag.Location{{File: "/tmp/dir/databricks.yml"}}) + bundletest.SetLocation(b, "sync.include[0]", []diag.Location{{File: "/tmp/dir/file.yml"}}) + bundletest.SetLocation(b, "sync.include[1]", []diag.Location{{File: "/tmp/dir/a/file.yml"}}) + bundletest.SetLocation(b, "sync.exclude[0]", []diag.Location{{File: "/tmp/dir/a/b/file.yml"}}) + bundletest.SetLocation(b, "sync.exclude[1]", []diag.Location{{File: "/tmp/dir/a/b/c/file.yml"}}) diags := bundle.Apply(t.Context(), b, mutator.RewriteSyncPaths()) assert.NoError(t, diags.Error()) diff --git a/bundle/config/mutator/sync_infer_root_test.go b/bundle/config/mutator/sync_infer_root_test.go index c8f4a09c472..e34b4210bd6 100644 --- a/bundle/config/mutator/sync_infer_root_test.go +++ b/bundle/config/mutator/sync_infer_root_test.go @@ -8,7 +8,7 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/mutator" "github.com/databricks/cli/bundle/internal/bundletest" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -184,7 +184,7 @@ func TestSyncInferRoot_Error(t *testing.T) { }, } - bundletest.SetLocation(b, "sync.paths", []dyn.Location{{File: "databricks.yml"}}) + bundletest.SetLocation(b, "sync.paths", []diag.Location{{File: "databricks.yml"}}) ctx := t.Context() diags := bundle.Apply(ctx, b, mutator.SyncInferRoot()) diff --git a/bundle/config/mutator/translate_paths.go b/bundle/config/mutator/translate_paths.go index 65a903bf5a3..8798364fec3 100644 --- a/bundle/config/mutator/translate_paths.go +++ b/bundle/config/mutator/translate_paths.go @@ -330,7 +330,7 @@ func applyTranslations(ctx context.Context, b *bundle.Bundle, t *translateContex return diag.Diagnostics{{ Severity: diag.Error, Summary: "workspace.file_path cannot be configured when experimental.immutable_folder is enabled", - Locations: []dyn.Location{loc}, + Locations: []diag.Location{loc}, }} } t.remoteRoot = resources.SnapshotFullPathRef + "/files" diff --git a/bundle/config/mutator/translate_paths_apps_test.go b/bundle/config/mutator/translate_paths_apps_test.go index a69999b2b2a..05c902235b1 100644 --- a/bundle/config/mutator/translate_paths_apps_test.go +++ b/bundle/config/mutator/translate_paths_apps_test.go @@ -9,7 +9,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/cli/libs/vfs" "github.com/databricks/databricks-sdk-go/service/apps" "github.com/stretchr/testify/assert" @@ -41,7 +41,7 @@ func TestTranslatePathsApps_FilePathRelativeSubDirectory(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.apps", []dyn.Location{{ + bundletest.SetLocation(b, "resources.apps", []diag.Location{{ File: filepath.Join(dir, "resources/app.yml"), }}) diff --git a/bundle/config/mutator/translate_paths_artifacts_test.go b/bundle/config/mutator/translate_paths_artifacts_test.go index 31f9a0ea4ad..cf55d3d70dd 100644 --- a/bundle/config/mutator/translate_paths_artifacts_test.go +++ b/bundle/config/mutator/translate_paths_artifacts_test.go @@ -9,7 +9,7 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/bundle/config/mutator" "github.com/databricks/cli/bundle/internal/bundletest" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/vfs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -38,7 +38,7 @@ func TestTranslatePathsArtifacts_InsideSyncRoot(t *testing.T) { }, } - bundletest.SetLocation(b, "artifacts", []dyn.Location{{ + bundletest.SetLocation(b, "artifacts", []diag.Location{{ File: filepath.Join(dir, "config/artifacts.yml"), }}) @@ -72,7 +72,7 @@ func TestTranslatePathsArtifacts_OutsideSyncRoot(t *testing.T) { }, } - bundletest.SetLocation(b, "artifacts", []dyn.Location{{ + bundletest.SetLocation(b, "artifacts", []diag.Location{{ File: filepath.Join(dir, "config/artifacts.yml"), }}) diff --git a/bundle/config/mutator/translate_paths_dashboards_test.go b/bundle/config/mutator/translate_paths_dashboards_test.go index 89625798805..84c36bc3706 100644 --- a/bundle/config/mutator/translate_paths_dashboards_test.go +++ b/bundle/config/mutator/translate_paths_dashboards_test.go @@ -9,7 +9,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/cli/libs/vfs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -37,7 +37,7 @@ func TestTranslatePathsDashboards_FilePathRelativeSubDirectory(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.dashboards", []dyn.Location{{ + bundletest.SetLocation(b, "resources.dashboards", []diag.Location{{ File: filepath.Join(dir, "resources/dashboard.yml"), }}) diff --git a/bundle/config/mutator/translate_paths_genie_spaces_test.go b/bundle/config/mutator/translate_paths_genie_spaces_test.go index a1ac0b160b1..ea053335a75 100644 --- a/bundle/config/mutator/translate_paths_genie_spaces_test.go +++ b/bundle/config/mutator/translate_paths_genie_spaces_test.go @@ -9,7 +9,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/cli/libs/vfs" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -37,7 +37,7 @@ func TestTranslatePathsGenieSpaces_FilePathRelativeSubDirectory(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.genie_spaces", []dyn.Location{{ + bundletest.SetLocation(b, "resources.genie_spaces", []diag.Location{{ File: filepath.Join(dir, "resources", "genie_space.yml"), }}) diff --git a/bundle/config/mutator/translate_paths_test.go b/bundle/config/mutator/translate_paths_test.go index 226a848b723..8aaf9ce9c71 100644 --- a/bundle/config/mutator/translate_paths_test.go +++ b/bundle/config/mutator/translate_paths_test.go @@ -14,6 +14,7 @@ import ( "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/bundle/config/variable" "github.com/databricks/cli/bundle/internal/bundletest" + "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/compute" @@ -93,7 +94,7 @@ func TestTranslatePathsSkippedWithGitSource(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -222,7 +223,7 @@ func TestTranslatePaths(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -365,8 +366,8 @@ func TestTranslatePathsInSubdirectories(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.jobs", []dyn.Location{{File: filepath.Join(dir, "job/resource.yml")}}) - bundletest.SetLocation(b, "resources.pipelines", []dyn.Location{{File: filepath.Join(dir, "pipeline/resource.yml")}}) + bundletest.SetLocation(b, "resources.jobs", []diag.Location{{File: filepath.Join(dir, "job/resource.yml")}}) + bundletest.SetLocation(b, "resources.pipelines", []diag.Location{{File: filepath.Join(dir, "pipeline/resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -433,7 +434,7 @@ func TestTranslatePathsOutsideSyncRoot(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "../resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "../resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.ErrorContains(t, diags.Error(), "is not contained in sync root path") @@ -465,7 +466,7 @@ func TestJobNotebookDoesNotExistError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "fake.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "fake.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.EqualError(t, diags.Error(), "notebook doesnt_exist.py not found") @@ -497,7 +498,7 @@ func TestJobFileDoesNotExistError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "fake.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "fake.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.EqualError(t, diags.Error(), "file doesnt_exist.py not found") @@ -529,7 +530,7 @@ func TestPipelineNotebookDoesNotExistError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "fake.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "fake.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.EqualError(t, diags.Error(), "notebook doesnt_exist.py not found") @@ -574,7 +575,7 @@ func TestPipelineNotebookDoesNotExistErrorWithoutExtension(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "fake.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "fake.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) if ext == "" { @@ -615,7 +616,7 @@ func TestPipelineFileDoesNotExistError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "fake.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "fake.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.EqualError(t, diags.Error(), "file doesnt_exist.py not found") @@ -651,7 +652,7 @@ func TestJobSparkPythonTaskWithNotebookSourceError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.ErrorContains(t, diags.Error(), `expected a file for "resources.jobs.job.tasks[0].spark_python_task.python_file" but got a notebook`) @@ -687,7 +688,7 @@ func TestJobNotebookTaskWithFileSourceError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.ErrorContains(t, diags.Error(), `expected a notebook for "resources.jobs.job.tasks[0].notebook_task.notebook_path" but got a file`) @@ -723,7 +724,7 @@ func TestPipelineNotebookLibraryWithFileSourceError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.ErrorContains(t, diags.Error(), `expected a notebook for "resources.pipelines.pipeline.libraries[0].notebook.path" but got a file`) @@ -759,7 +760,7 @@ func TestPipelineFileLibraryWithNotebookSourceError(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) assert.ErrorContains(t, diags.Error(), `expected a file for "resources.pipelines.pipeline.libraries[0].file.path" but got a notebook`) @@ -801,7 +802,7 @@ func TestTranslatePathJobEnvironments(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.jobs", []dyn.Location{{File: filepath.Join(dir, "job/resource.yml")}}) + bundletest.SetLocation(b, "resources.jobs", []diag.Location{{File: filepath.Join(dir, "job/resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -848,8 +849,8 @@ func TestTranslatePathWithComplexVariables(t *testing.T) { }, } - bundletest.SetLocation(b, "variables", []dyn.Location{{File: filepath.Join(dir, "variables/variables.yml")}}) - bundletest.SetLocation(b, "resources.jobs", []dyn.Location{{File: filepath.Join(dir, "job/resource.yml")}}) + bundletest.SetLocation(b, "variables", []diag.Location{{File: filepath.Join(dir, "variables/variables.yml")}}) + bundletest.SetLocation(b, "resources.jobs", []diag.Location{{File: filepath.Join(dir, "job/resource.yml")}}) ctx := t.Context() // Assign the variables to the dynamic configuration. @@ -977,7 +978,7 @@ func TestTranslatePathsWithSourceLinkedDeployment(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -1085,7 +1086,7 @@ func TestTranslatePathsWithSkipLocalFileValidation(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "databricks.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "databricks.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -1125,7 +1126,7 @@ func TestTranslatePathsWithSkipLocalFileValidationDirectory(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "databricks.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "databricks.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -1174,7 +1175,7 @@ func TestTranslatePathsDesignerNotebook(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "databricks.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "databricks.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) @@ -1228,7 +1229,7 @@ func TestTranslatePathsDesignerNotebookSkipLocalFileValidation(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "databricks.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "databricks.yml")}}) diags := bundle.ApplySeq(t.Context(), b, mutator.NormalizePaths(), mutator.TranslatePaths()) require.NoError(t, diags.Error()) diff --git a/bundle/config/root.go b/bundle/config/root.go index b87a2675692..3aa6fdd8b87 100644 --- a/bundle/config/root.go +++ b/bundle/config/root.go @@ -119,7 +119,7 @@ func LoadFromBytes(path string, raw []byte) (*Root, diag.Diagnostics) { return nil, diag.Diagnostics{{ Severity: diag.Error, Summary: le.Summary, - Locations: []dyn.Location{le.Loc}, + Locations: []diag.Location{le.Loc}, }} } return nil, diag.Errorf("failed to load %s: %v", path, err) @@ -587,10 +587,10 @@ func validateVariableOverrides(root, target dyn.Value) (err error) { // Best effort to get the location of configuration value at the specified path. // This function is useful to annotate error messages with the location, because // we don't want to fail with a different error message if we cannot retrieve the location. -func (r Root) GetLocation(path string) dyn.Location { +func (r Root) GetLocation(path string) diag.Location { v, err := dyn.Get(r.value, path) if err != nil { - return dyn.Location{} + return diag.Location{} } return v.Location() } @@ -598,7 +598,7 @@ func (r Root) GetLocation(path string) dyn.Location { // Get all locations of the configuration value at the specified path. We need both // this function and it's singular version (GetLocation) because some diagnostics just need // the primary location and some need all locations associated with a configuration value. -func (r Root) GetLocations(path string) []dyn.Location { +func (r Root) GetLocations(path string) []diag.Location { v, err := dyn.Get(r.value, path) if err != nil { return nil @@ -607,16 +607,16 @@ func (r Root) GetLocations(path string) []dyn.Location { } // GetLocationOf is [Root.GetLocation] for a path node. -func (r Root) GetLocationOf(path *structpath.PathNode) dyn.Location { +func (r Root) GetLocationOf(path *structpath.PathNode) diag.Location { v, ok := r.valueOf(path) if !ok { - return dyn.Location{} + return diag.Location{} } return v.Location() } // GetLocationsOf is [Root.GetLocations] for a path node. -func (r Root) GetLocationsOf(path *structpath.PathNode) []dyn.Location { +func (r Root) GetLocationsOf(path *structpath.PathNode) []diag.Location { v, ok := r.valueOf(path) if !ok { return nil diff --git a/bundle/config/validate/required.go b/bundle/config/validate/required.go index dce5c0686c1..9e3274b6f00 100644 --- a/bundle/config/validate/required.go +++ b/bundle/config/validate/required.go @@ -95,9 +95,9 @@ func sortDiagnostics(diags diag.Diagnostics) { // Bespoke code to error for fields that are not marked as required in the Go SDK / OpenAPI spec. func errorForMissingFields(ctx context.Context, b *bundle.Bundle) diag.Diagnostics { // Dashboards should always have a name and warehouse_id. - var nameLocations []dyn.Location + var nameLocations []diag.Location var namePaths []*structpath.PathNode - var warehouseIdLocations []dyn.Location + var warehouseIdLocations []diag.Location var warehouseIdPaths []*structpath.PathNode diags := diag.Diagnostics{} diff --git a/bundle/config/validate/single_node_cluster_test.go b/bundle/config/validate/single_node_cluster_test.go index f4494ae259c..997d39ea0ac 100644 --- a/bundle/config/validate/single_node_cluster_test.go +++ b/bundle/config/validate/single_node_cluster_test.go @@ -109,7 +109,7 @@ func TestValidateSingleNodeClusterFailForInteractiveClusters(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.clusters.foo", []dyn.Location{{File: "a.yml", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "resources.clusters.foo", []diag.Location{{File: "a.yml", Line: 1, Column: 1}}) // We can't set num_workers to 0 explicitly in the typed configuration. // Do it on the dyn.Value directly. @@ -122,7 +122,7 @@ func TestValidateSingleNodeClusterFailForInteractiveClusters(t *testing.T) { Severity: diag.Warning, Summary: singleNodeWarningSummary, Detail: singleNodeWarningDetail, - Locations: []dyn.Location{{File: "a.yml", Line: 1, Column: 1}}, + Locations: []diag.Location{{File: "a.yml", Line: 1, Column: 1}}, Paths: structpath.NewPathSlice("resources", "clusters", "foo"), }, }, diags) @@ -157,7 +157,7 @@ func TestValidateSingleNodeClusterFailForJobClusters(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.jobs.foo.job_clusters[0].new_cluster", []dyn.Location{{File: "b.yml", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "resources.jobs.foo.job_clusters[0].new_cluster", []diag.Location{{File: "b.yml", Line: 1, Column: 1}}) // We can't set num_workers to 0 explicitly in the typed configuration. // Do it on the dyn.Value directly. @@ -171,7 +171,7 @@ func TestValidateSingleNodeClusterFailForJobClusters(t *testing.T) { Severity: diag.Warning, Summary: singleNodeWarningSummary, Detail: singleNodeWarningDetail, - Locations: []dyn.Location{{File: "b.yml", Line: 1, Column: 1}}, + Locations: []diag.Location{{File: "b.yml", Line: 1, Column: 1}}, Paths: structpath.MustParsePaths("resources.jobs.foo.job_clusters[0].new_cluster"), }, }, diags) @@ -206,7 +206,7 @@ func TestValidateSingleNodeClusterFailForJobTaskClusters(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.jobs.foo.tasks[0].new_cluster", []dyn.Location{{File: "c.yml", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "resources.jobs.foo.tasks[0].new_cluster", []diag.Location{{File: "c.yml", Line: 1, Column: 1}}) // We can't set num_workers to 0 explicitly in the typed configuration. // Do it on the dyn.Value directly. @@ -220,7 +220,7 @@ func TestValidateSingleNodeClusterFailForJobTaskClusters(t *testing.T) { Severity: diag.Warning, Summary: singleNodeWarningSummary, Detail: singleNodeWarningDetail, - Locations: []dyn.Location{{File: "c.yml", Line: 1, Column: 1}}, + Locations: []diag.Location{{File: "c.yml", Line: 1, Column: 1}}, Paths: structpath.MustParsePaths("resources.jobs.foo.tasks[0].new_cluster"), }, }, diags) @@ -252,7 +252,7 @@ func TestValidateSingleNodeClusterFailForPipelineClusters(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.pipelines.foo.clusters[0]", []dyn.Location{{File: "d.yml", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "resources.pipelines.foo.clusters[0]", []diag.Location{{File: "d.yml", Line: 1, Column: 1}}) // We can't set num_workers to 0 explicitly in the typed configuration. // Do it on the dyn.Value directly. @@ -266,7 +266,7 @@ func TestValidateSingleNodeClusterFailForPipelineClusters(t *testing.T) { Severity: diag.Warning, Summary: singleNodeWarningSummary, Detail: singleNodeWarningDetail, - Locations: []dyn.Location{{File: "d.yml", Line: 1, Column: 1}}, + Locations: []diag.Location{{File: "d.yml", Line: 1, Column: 1}}, Paths: structpath.MustParsePaths("resources.pipelines.foo.clusters[0]"), }, }, diags) @@ -305,7 +305,7 @@ func TestValidateSingleNodeClusterFailForJobForEachTaskCluster(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.jobs.foo.tasks[0].for_each_task.task.new_cluster", []dyn.Location{{File: "e.yml", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "resources.jobs.foo.tasks[0].for_each_task.task.new_cluster", []diag.Location{{File: "e.yml", Line: 1, Column: 1}}) // We can't set num_workers to 0 explicitly in the typed configuration. // Do it on the dyn.Value directly. @@ -319,7 +319,7 @@ func TestValidateSingleNodeClusterFailForJobForEachTaskCluster(t *testing.T) { Severity: diag.Warning, Summary: singleNodeWarningSummary, Detail: singleNodeWarningDetail, - Locations: []dyn.Location{{File: "e.yml", Line: 1, Column: 1}}, + Locations: []diag.Location{{File: "e.yml", Line: 1, Column: 1}}, Paths: structpath.MustParsePaths("resources.jobs.foo.tasks[0].for_each_task.task.new_cluster"), }, }, diags) diff --git a/bundle/config/validate/tf_only_references.go b/bundle/config/validate/tf_only_references.go index 60eb87e4249..3603b6f4a7f 100644 --- a/bundle/config/validate/tf_only_references.go +++ b/bundle/config/validate/tf_only_references.go @@ -56,7 +56,7 @@ func (m *tfOnlyReferences) Apply(_ context.Context, b *bundle.Bundle) diag.Diagn // checkTFOnlyReference checks a single reference string like // "resources.jobs.src.always_running" and returns a diagnostic when it refers // to a TF-only field, or nil otherwise. -func checkTFOnlyReference(ref string, loc dyn.Location) *diag.Diagnostic { +func checkTFOnlyReference(ref string, loc diag.Location) *diag.Diagnostic { p, err := dyn.NewPathFromString(ref) // Need at least resources... if err != nil || len(p) < 4 || p[0].Key() != "resources" { @@ -82,6 +82,6 @@ func checkTFOnlyReference(ref string, loc dyn.Location) *diag.Diagnostic { return &diag.Diagnostic{ Severity: diag.Error, Summary: fmt.Sprintf("%q: Terraform-only field; cross-resource references to Terraform-only fields are not supported by the direct engine", ref), - Locations: []dyn.Location{loc}, + Locations: []diag.Location{loc}, } } diff --git a/bundle/config/validate/unique_resource_keys.go b/bundle/config/validate/unique_resource_keys.go index cff5ef3ccff..7d2e49569f7 100644 --- a/bundle/config/validate/unique_resource_keys.go +++ b/bundle/config/validate/unique_resource_keys.go @@ -36,7 +36,7 @@ func (m *uniqueResourceKeys) Apply(ctx context.Context, b *bundle.Bundle) diag.D diags := diag.Diagnostics{} type metadata struct { - locations []dyn.Location + locations []diag.Location paths []*structpath.PathNode } @@ -101,7 +101,7 @@ func (m *uniqueResourceKeys) Apply(ctx context.Context, b *bundle.Bundle) diag.D // Sort the locations and paths for consistent error messages. This helps // with unit testing. - slices.SortFunc(v.locations, func(a, b dyn.Location) int { + slices.SortFunc(v.locations, func(a, b diag.Location) int { if n := cmp.Compare(a.File, b.File); n != 0 { return n } diff --git a/bundle/config/validate/validate_artifact_path.go b/bundle/config/validate/validate_artifact_path.go index 33e0a024c7a..36494cf7d77 100644 --- a/bundle/config/validate/validate_artifact_path.go +++ b/bundle/config/validate/validate_artifact_path.go @@ -52,7 +52,7 @@ func extractVolumeFromPath(artifactPath string) (string, string, string, error) return catalogName, schemaName, volumeName, nil } -func findVolumeInBundle(r config.Root, catalogName, schemaName, volumeName string) (dyn.Path, []dyn.Location, bool) { +func findVolumeInBundle(r config.Root, catalogName, schemaName, volumeName string) (dyn.Path, []diag.Location, bool) { volumes := r.Resources.Volumes for k, v := range volumes { if v.CatalogName != catalogName || v.Name != volumeName { diff --git a/bundle/config/validate/validate_artifact_path_test.go b/bundle/config/validate/validate_artifact_path_test.go index 4f68f645990..97a08ab6e30 100644 --- a/bundle/config/validate/validate_artifact_path_test.go +++ b/bundle/config/validate/validate_artifact_path_test.go @@ -38,8 +38,8 @@ func TestValidateArtifactPathWithVolumeInBundle(t *testing.T) { }, } - bundletest.SetLocation(b, "workspace.artifact_path", []dyn.Location{{File: "file", Line: 1, Column: 1}}) - bundletest.SetLocation(b, "resources.volumes.foo", []dyn.Location{{File: "file", Line: 2, Column: 2}}) + bundletest.SetLocation(b, "workspace.artifact_path", []diag.Location{{File: "file", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "resources.volumes.foo", []diag.Location{{File: "file", Line: 2, Column: 2}}) ctx := t.Context() m := mocks.NewMockWorkspaceClient(t) @@ -53,7 +53,7 @@ func TestValidateArtifactPathWithVolumeInBundle(t *testing.T) { assert.Equal(t, diag.Diagnostics{{ Severity: diag.Error, Summary: "volume catalogN.schemaN.volumeN does not exist", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "file", Line: 1, Column: 1}, {File: "file", Line: 2, Column: 2}, }, @@ -77,13 +77,13 @@ func TestValidateArtifactPath(t *testing.T) { }, } - bundletest.SetLocation(b, "workspace.artifact_path", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + bundletest.SetLocation(b, "workspace.artifact_path", []diag.Location{{File: "file", Line: 1, Column: 1}}) assertDiags := func(t *testing.T, diags diag.Diagnostics, expected string) { assert.Len(t, diags, 1) assert.Equal(t, diag.Diagnostics{{ Severity: diag.Error, Summary: expected, - Locations: []dyn.Location{{File: "file", Line: 1, Column: 1}}, + Locations: []diag.Location{{File: "file", Line: 1, Column: 1}}, Paths: structpath.NewPathSlice("workspace", "artifact_path"), }}, diags) } @@ -164,13 +164,13 @@ func TestValidateArtifactPathWithInvalidPaths(t *testing.T) { }, } - bundletest.SetLocation(b, "workspace.artifact_path", []dyn.Location{{File: "config.yml", Line: 1, Column: 2}}) + bundletest.SetLocation(b, "workspace.artifact_path", []diag.Location{{File: "config.yml", Line: 1, Column: 2}}) diags := ValidateArtifactPath().Apply(t.Context(), b) require.Equal(t, diag.Diagnostics{{ Severity: diag.Error, Summary: "expected UC volume path to be in the format /Volumes////..., got " + p, - Locations: []dyn.Location{{File: "config.yml", Line: 1, Column: 2}}, + Locations: []diag.Location{{File: "config.yml", Line: 1, Column: 2}}, Paths: structpath.NewPathSlice("workspace", "artifact_path"), }}, diags) } @@ -193,7 +193,7 @@ func TestFindVolumeInBundle(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.volumes.foo", []dyn.Location{ + bundletest.SetLocation(b, "resources.volumes.foo", []diag.Location{ { File: "volume.yml", Line: 1, @@ -204,7 +204,7 @@ func TestFindVolumeInBundle(t *testing.T) { // volume is in DAB. path, locations, ok := findVolumeInBundle(b.Config, "main", "my_schema", "my_volume") assert.True(t, ok) - assert.Equal(t, []dyn.Location{{ + assert.Equal(t, []diag.Location{{ File: "volume.yml", Line: 1, Column: 2, @@ -233,7 +233,7 @@ func TestFindVolumeInBundle(t *testing.T) { b.Config.Resources.Volumes["foo"].SchemaName = "${resources.schemas.my_schema.name}" path, locations, ok = findVolumeInBundle(b.Config, "main", "valuedoesnotmatter", "my_volume") assert.True(t, ok) - assert.Equal(t, []dyn.Location{{ + assert.Equal(t, []diag.Location{{ File: "volume.yml", Line: 1, Column: 2, diff --git a/bundle/config/validate/validate_engine.go b/bundle/config/validate/validate_engine.go index 8f6020772ed..f19c2270b26 100644 --- a/bundle/config/validate/validate_engine.go +++ b/bundle/config/validate/validate_engine.go @@ -47,7 +47,7 @@ func (v *validateEngine) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnos return diags.Append(diag.Diagnostic{ Severity: diag.Error, Summary: fmt.Sprintf("invalid value %q for bundle.engine (expected %q)", configEngine, engine.EngineDirect), - Locations: []dyn.Location{loc}, + Locations: []diag.Location{loc}, }) } @@ -60,7 +60,7 @@ func (v *validateEngine) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnos Severity: severity, Summary: engine.TerraformRemovedSummary, Detail: engine.TerraformRemovedConfigDetail, - Locations: []dyn.Location{loc}, + Locations: []diag.Location{loc}, }) } diff --git a/bundle/config/validate/validate_engine_test.go b/bundle/config/validate/validate_engine_test.go index f74cb002650..da1bd7bf12d 100644 --- a/bundle/config/validate/validate_engine_test.go +++ b/bundle/config/validate/validate_engine_test.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/cli/bundle/config/engine" "github.com/databricks/cli/bundle/internal/bundletest" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" ) @@ -20,7 +19,7 @@ func TestValidateEngineDirect(t *testing.T) { }, }, } - bundletest.SetLocation(b, "bundle.engine", []dyn.Location{{File: "databricks.yml", Line: 5, Column: 3}}) + bundletest.SetLocation(b, "bundle.engine", []diag.Location{{File: "databricks.yml", Line: 5, Column: 3}}) diags := ValidateEngine().Apply(t.Context(), b) assert.Empty(t, diags) } @@ -33,13 +32,13 @@ func TestValidateEngineTerraformRemoved(t *testing.T) { }, }, } - loc := dyn.Location{File: "databricks.yml", Line: 5, Column: 3} - bundletest.SetLocation(b, "bundle.engine", []dyn.Location{loc}) + loc := diag.Location{File: "databricks.yml", Line: 5, Column: 3} + bundletest.SetLocation(b, "bundle.engine", []diag.Location{loc}) diags := ValidateEngine().Apply(t.Context(), b) assert.Len(t, diags, 1) assert.Equal(t, diag.Error, diags[0].Severity) assert.Contains(t, diags[0].Summary, "has been removed") - assert.Equal(t, []dyn.Location{loc}, diags[0].Locations) + assert.Equal(t, []diag.Location{loc}, diags[0].Locations) } func TestValidateEngineNotSet(t *testing.T) { @@ -58,7 +57,7 @@ func TestValidateEngineInvalid(t *testing.T) { }, }, } - bundletest.SetLocation(b, "bundle.engine", []dyn.Location{{File: "databricks.yml", Line: 5, Column: 3}}) + bundletest.SetLocation(b, "bundle.engine", []diag.Location{{File: "databricks.yml", Line: 5, Column: 3}}) diags := ValidateEngine().Apply(t.Context(), b) assert.Len(t, diags, 1) assert.Equal(t, diag.Error, diags[0].Severity) @@ -73,13 +72,13 @@ func TestValidateEngineTerraformConfigDeprecated(t *testing.T) { }, }, } - loc := dyn.Location{File: "databricks.yml", Line: 3, Column: 5} - bundletest.SetLocation(b, "bundle.terraform", []dyn.Location{loc}) + loc := diag.Location{File: "databricks.yml", Line: 3, Column: 5} + bundletest.SetLocation(b, "bundle.terraform", []diag.Location{loc}) diags := ValidateEngine().Apply(t.Context(), b) assert.Len(t, diags, 1) assert.Equal(t, diag.Warning, diags[0].Severity) assert.Contains(t, diags[0].Summary, "bundle.terraform is deprecated") - assert.Equal(t, []dyn.Location{loc}, diags[0].Locations) + assert.Equal(t, []diag.Location{loc}, diags[0].Locations) } func TestValidateEngineTerraformAllowed(t *testing.T) { @@ -91,7 +90,7 @@ func TestValidateEngineTerraformAllowed(t *testing.T) { }, AllowTerraformEngineConfig: true, } - bundletest.SetLocation(b, "bundle.engine", []dyn.Location{{File: "databricks.yml", Line: 5, Column: 3}}) + bundletest.SetLocation(b, "bundle.engine", []diag.Location{{File: "databricks.yml", Line: 5, Column: 3}}) diags := ValidateEngine().Apply(t.Context(), b) assert.Len(t, diags, 1) assert.Equal(t, diag.Warning, diags[0].Severity) diff --git a/bundle/configsync/sequences.go b/bundle/configsync/sequences.go index d0b6f599c72..4ce0274fdb3 100644 --- a/bundle/configsync/sequences.go +++ b/bundle/configsync/sequences.go @@ -11,6 +11,7 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/config" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/log" "github.com/databricks/cli/libs/structs/structpath" @@ -63,7 +64,7 @@ type blockResolver struct { // path relative to a block can be looked up inside it. blocks map[sourceBlock]dyn.Value target string - byLocation map[dyn.Location]sourceBlock + byLocation map[diag.Location]sourceBlock } // newBlockResolver builds the location -> block mapping for the bundle's resources, @@ -81,7 +82,7 @@ func newBlockResolver(ctx context.Context, b *bundle.Bundle) *blockResolver { r := &blockResolver{ blocks: make(map[sourceBlock]dyn.Value), target: b.Config.Bundle.Target, - byLocation: make(map[dyn.Location]sourceBlock), + byLocation: make(map[diag.Location]sourceBlock), } sourceFiles := slices.Sorted(maps.Keys(referencedFiles(root))) @@ -258,7 +259,7 @@ func (r *blockResolver) indexWithinBlock(block sourceBlock, sequencePath dyn.Pat return 0, false } - locations := make(map[dyn.Location]struct{}, len(element.Locations())) + locations := make(map[diag.Location]struct{}, len(element.Locations())) for _, location := range element.Locations() { locations[location] = struct{}{} } @@ -499,7 +500,7 @@ func (r *blockResolver) blocksDefiningSequence(change resolvedChange, sequencePa if err != nil { continue } - if slices.ContainsFunc(sequence.Locations(), func(l dyn.Location) bool { return l.File == block.file }) { + if slices.ContainsFunc(sequence.Locations(), func(l diag.Location) bool { return l.File == block.file }) { blocks = append(blocks, block) } } diff --git a/bundle/deploy/check_dashboards_modified_remotely.go b/bundle/deploy/check_dashboards_modified_remotely.go index f362f7967e8..d685f7ebeb6 100644 --- a/bundle/deploy/check_dashboards_modified_remotely.go +++ b/bundle/deploy/check_dashboards_modified_remotely.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/agent" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/structs/structpath" ) @@ -82,7 +81,7 @@ func (l *checkDashboardsModifiedRemotely) Apply(ctx context.Context, b *bundle.B Summary: fmt.Sprintf("failed to get dashboard %q", dashboard.Name), Detail: err.Error(), Paths: []*structpath.PathNode{path}, - Locations: []dyn.Location{loc}, + Locations: []diag.Location{loc}, }) continue } @@ -111,7 +110,7 @@ func (l *checkDashboardsModifiedRemotely) Apply(ctx context.Context, b *bundle.B "To overwrite the remote changes with your local version, use --force.\n" + "The remote modifications will be lost." + agent.AgentNotice(), Paths: []*structpath.PathNode{path}, - Locations: []dyn.Location{loc}, + Locations: []diag.Location{loc}, }) } diff --git a/bundle/deploy/metadata/compute_test.go b/bundle/deploy/metadata/compute_test.go index 58b8b390d35..cb163914bdb 100644 --- a/bundle/deploy/metadata/compute_test.go +++ b/bundle/deploy/metadata/compute_test.go @@ -9,7 +9,7 @@ import ( "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/bundle/internal/bundletest" "github.com/databricks/cli/bundle/metadata" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/vfs" "github.com/databricks/databricks-sdk-go/service/jobs" "github.com/databricks/databricks-sdk-go/service/pipelines" @@ -81,12 +81,12 @@ func TestComputeMetadataMutator(t *testing.T) { }, } - bundletest.SetLocation(b, "resources.jobs.my-job-1", []dyn.Location{{File: "a/b/c"}}) - bundletest.SetLocation(b, "resources.jobs.my-job-2", []dyn.Location{{File: "d/e/f"}}) - bundletest.SetLocation(b, "resources.pipelines.my-pipeline-1", []dyn.Location{{File: "x/y/z"}}) - bundletest.SetLocation(b, "resources.pipelines.my-pipeline-2", []dyn.Location{{File: "u/v/w"}}) - bundletest.SetLocation(b, "resources.dashboards.my-dashboard-1", []dyn.Location{{File: "g/h/i"}}) - bundletest.SetLocation(b, "resources.dashboards.my-dashboard-2", []dyn.Location{{File: "j/k/l"}}) + bundletest.SetLocation(b, "resources.jobs.my-job-1", []diag.Location{{File: "a/b/c"}}) + bundletest.SetLocation(b, "resources.jobs.my-job-2", []diag.Location{{File: "d/e/f"}}) + bundletest.SetLocation(b, "resources.pipelines.my-pipeline-1", []diag.Location{{File: "x/y/z"}}) + bundletest.SetLocation(b, "resources.pipelines.my-pipeline-2", []diag.Location{{File: "u/v/w"}}) + bundletest.SetLocation(b, "resources.dashboards.my-dashboard-1", []diag.Location{{File: "g/h/i"}}) + bundletest.SetLocation(b, "resources.dashboards.my-dashboard-2", []diag.Location{{File: "j/k/l"}}) expectedMetadata := metadata.Metadata{ Version: metadata.Version, diff --git a/bundle/generate/alert.go b/bundle/generate/alert.go index 3f2428b72e3..eba68126dd8 100644 --- a/bundle/generate/alert.go +++ b/bundle/generate/alert.go @@ -1,6 +1,7 @@ package generate import ( + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/databricks-sdk-go/service/sql" ) @@ -9,9 +10,9 @@ func ConvertAlertToValue(alert *sql.AlertV2, filePath string) (dyn.Value, error) // The majority of fields of the alert struct are present in .dbalert.json file. // We copy the relevant fields manually. dv := map[string]dyn.Value{ - "display_name": dyn.NewValue(alert.DisplayName, []dyn.Location{{Line: 1}}), - "warehouse_id": dyn.NewValue(alert.WarehouseId, []dyn.Location{{Line: 2}}), - "file_path": dyn.NewValue(filePath, []dyn.Location{{Line: 3}}), + "display_name": dyn.NewValue(alert.DisplayName, []diag.Location{{Line: 1}}), + "warehouse_id": dyn.NewValue(alert.WarehouseId, []diag.Location{{Line: 2}}), + "file_path": dyn.NewValue(filePath, []diag.Location{{Line: 3}}), } return dyn.V(dv), nil diff --git a/bundle/generate/app.go b/bundle/generate/app.go index 234967ce072..0714fc9b324 100644 --- a/bundle/generate/app.go +++ b/bundle/generate/app.go @@ -1,6 +1,7 @@ package generate import ( + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/convert" "github.com/databricks/databricks-sdk-go/service/apps" @@ -15,8 +16,8 @@ func ConvertAppToValue(app *apps.App, sourceCodePath string) (dyn.Value, error) // The majority of fields of the app struct are read-only. // We copy the relevant fields manually. dv := map[string]dyn.Value{ - "name": dyn.NewValue(app.Name, []dyn.Location{{Line: 1}}), - "description": dyn.NewValue(app.Description, []dyn.Location{{Line: 2}}), + "name": dyn.NewValue(app.Name, []diag.Location{{Line: 1}}), + "description": dyn.NewValue(app.Description, []diag.Location{{Line: 2}}), } // For a git-backed app, emit git_repository + git_source instead of a @@ -29,11 +30,11 @@ func ConvertAppToValue(app *apps.App, sourceCodePath string) (dyn.Value, error) dv["git_source"] = gs } } else { - dv["source_code_path"] = dyn.NewValue(sourceCodePath, []dyn.Location{{Line: 4}}) + dv["source_code_path"] = dyn.NewValue(sourceCodePath, []diag.Location{{Line: 4}}) } if ar.Kind() != dyn.KindNil { - dv["resources"] = ar.WithLocations([]dyn.Location{{Line: 5}}) + dv["resources"] = ar.WithLocations([]diag.Location{{Line: 5}}) } return dyn.V(dv), nil @@ -41,13 +42,13 @@ func ConvertAppToValue(app *apps.App, sourceCodePath string) (dyn.Value, error) func gitRepositoryValue(r *apps.GitRepository) dyn.Value { m := map[string]dyn.Value{ - "url": dyn.NewValue(r.Url, []dyn.Location{{Line: 1}}), - "provider": dyn.NewValue(r.Provider, []dyn.Location{{Line: 2}}), + "url": dyn.NewValue(r.Url, []diag.Location{{Line: 1}}), + "provider": dyn.NewValue(r.Provider, []diag.Location{{Line: 2}}), } if r.AutoDeploy { - m["auto_deploy"] = dyn.NewValue(r.AutoDeploy, []dyn.Location{{Line: 3}}) + m["auto_deploy"] = dyn.NewValue(r.AutoDeploy, []diag.Location{{Line: 3}}) } - return dyn.NewValue(m, []dyn.Location{{Line: 3}}) + return dyn.NewValue(m, []diag.Location{{Line: 3}}) } // gitSourceValue returns the reference the app deploys from (branch, tag, or @@ -67,17 +68,17 @@ func gitSourceValue(app *apps.App) dyn.Value { m := map[string]dyn.Value{} switch { case src.Branch != "": - m["branch"] = dyn.NewValue(src.Branch, []dyn.Location{{Line: 1}}) + m["branch"] = dyn.NewValue(src.Branch, []diag.Location{{Line: 1}}) case src.Tag != "": - m["tag"] = dyn.NewValue(src.Tag, []dyn.Location{{Line: 1}}) + m["tag"] = dyn.NewValue(src.Tag, []diag.Location{{Line: 1}}) case src.Commit != "": - m["commit"] = dyn.NewValue(src.Commit, []dyn.Location{{Line: 1}}) + m["commit"] = dyn.NewValue(src.Commit, []diag.Location{{Line: 1}}) } if src.SourceCodePath != "" { - m["source_code_path"] = dyn.NewValue(src.SourceCodePath, []dyn.Location{{Line: 2}}) + m["source_code_path"] = dyn.NewValue(src.SourceCodePath, []diag.Location{{Line: 2}}) } if len(m) == 0 { return dyn.NilValue } - return dyn.NewValue(m, []dyn.Location{{Line: 4}}) + return dyn.NewValue(m, []diag.Location{{Line: 4}}) } diff --git a/bundle/generate/dashboard.go b/bundle/generate/dashboard.go index 46014080693..6f045a39cb2 100644 --- a/bundle/generate/dashboard.go +++ b/bundle/generate/dashboard.go @@ -1,6 +1,7 @@ package generate import ( + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/databricks-sdk-go/service/dashboards" ) @@ -9,9 +10,9 @@ func ConvertDashboardToValue(dashboard *dashboards.Dashboard, filePath string) ( // The majority of fields of the dashboard struct are read-only. // We copy the relevant fields manually. dv := map[string]dyn.Value{ - "display_name": dyn.NewValue(dashboard.DisplayName, []dyn.Location{{Line: 1}}), - "warehouse_id": dyn.NewValue(dashboard.WarehouseId, []dyn.Location{{Line: 2}}), - "file_path": dyn.NewValue(filePath, []dyn.Location{{Line: 3}}), + "display_name": dyn.NewValue(dashboard.DisplayName, []diag.Location{{Line: 1}}), + "warehouse_id": dyn.NewValue(dashboard.WarehouseId, []diag.Location{{Line: 2}}), + "file_path": dyn.NewValue(filePath, []diag.Location{{Line: 3}}), } return dyn.V(dv), nil diff --git a/bundle/generate/genie_space.go b/bundle/generate/genie_space.go index 613ccf67ef0..639c65f314b 100644 --- a/bundle/generate/genie_space.go +++ b/bundle/generate/genie_space.go @@ -1,6 +1,7 @@ package generate import ( + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/databricks-sdk-go/service/dashboards" ) @@ -11,17 +12,17 @@ func ConvertGenieSpaceToValue(genieSpace *dashboards.GenieSpace, filePath string // fields (e.g. space_id, etag) must not appear in the generated config, so // we build the value field by field rather than marshaling the struct. dv := map[string]dyn.Value{ - "title": dyn.NewValue(genieSpace.Title, []dyn.Location{{Line: 1}}), - "warehouse_id": dyn.NewValue(genieSpace.WarehouseId, []dyn.Location{{Line: 2}}), - "file_path": dyn.NewValue(filePath, []dyn.Location{{Line: 3}}), + "title": dyn.NewValue(genieSpace.Title, []diag.Location{{Line: 1}}), + "warehouse_id": dyn.NewValue(genieSpace.WarehouseId, []diag.Location{{Line: 2}}), + "file_path": dyn.NewValue(filePath, []diag.Location{{Line: 3}}), } if genieSpace.Description != "" { - dv["description"] = dyn.NewValue(genieSpace.Description, []dyn.Location{{Line: 4}}) + dv["description"] = dyn.NewValue(genieSpace.Description, []diag.Location{{Line: 4}}) } if genieSpace.ParentPath != "" { - dv["parent_path"] = dyn.NewValue(ensureWorkspacePrefix(genieSpace.ParentPath), []dyn.Location{{Line: 5}}) + dv["parent_path"] = dyn.NewValue(ensureWorkspacePrefix(genieSpace.ParentPath), []diag.Location{{Line: 5}}) } return dyn.V(dv), nil diff --git a/bundle/generate/job.go b/bundle/generate/job.go index 825caaf4ce6..801eee1f5bd 100644 --- a/bundle/generate/job.go +++ b/bundle/generate/job.go @@ -1,6 +1,7 @@ package generate import ( + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/yamlsaver" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -23,7 +24,7 @@ func ConvertJobToValue(job *jobs.Job) (dyn.Value, error) { tasks = append(tasks, v) } // We're using location lines to define the order of keys in exported YAML. - value["tasks"] = dyn.NewValue(tasks, []dyn.Location{{Line: jobOrder.Get("tasks")}}) + value["tasks"] = dyn.NewValue(tasks, []diag.Location{{Line: jobOrder.Get("tasks")}}) } // We're processing job.Settings.Parameters separately to retain empty default values. @@ -31,13 +32,13 @@ func ConvertJobToValue(job *jobs.Job) (dyn.Value, error) { var params []dyn.Value for _, parameter := range job.Settings.Parameters { p := map[string]dyn.Value{ - "name": dyn.NewValue(parameter.Name, []dyn.Location{{Line: 0}}), // We use Line: 0 to ensure that the name goes first. - "default": dyn.NewValue(parameter.Default, []dyn.Location{{Line: 1}}), + "name": dyn.NewValue(parameter.Name, []diag.Location{{Line: 0}}), // We use Line: 0 to ensure that the name goes first. + "default": dyn.NewValue(parameter.Default, []diag.Location{{Line: 1}}), } params = append(params, dyn.V(p)) } - value["parameters"] = dyn.NewValue(params, []dyn.Location{{Line: jobOrder.Get("parameters")}}) + value["parameters"] = dyn.NewValue(params, []diag.Location{{Line: jobOrder.Get("parameters")}}) } return yamlsaver.ConvertToMapValue(job.Settings, jobOrder, []string{"format", "new_cluster", "existing_cluster_id"}, value) diff --git a/bundle/internal/bundletest/location.go b/bundle/internal/bundletest/location.go index 5dcd9d78f4d..b96cab0907d 100644 --- a/bundle/internal/bundletest/location.go +++ b/bundle/internal/bundletest/location.go @@ -2,13 +2,14 @@ package bundletest import ( "github.com/databricks/cli/bundle" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" ) // SetLocation sets the location of all values in the bundle to the given path. // This is useful for testing where we need to associate configuration // with the path it is loaded from. -func SetLocation(b *bundle.Bundle, prefix string, locations []dyn.Location) { +func SetLocation(b *bundle.Bundle, prefix string, locations []diag.Location) { start := dyn.MustPathFromString(prefix) err := b.Config.Mutate(func(root dyn.Value) (dyn.Value, error) { return dyn.Walk(root, func(p dyn.Path, v dyn.Value) (dyn.Value, error) { diff --git a/bundle/internal/schema/annotations_file.go b/bundle/internal/schema/annotations_file.go index 5c93610036a..78e279f4476 100644 --- a/bundle/internal/schema/annotations_file.go +++ b/bundle/internal/schema/annotations_file.go @@ -11,6 +11,7 @@ import ( yaml3 "go.yaml.in/yaml/v3" "github.com/databricks/cli/bundle/internal/annotation" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/convert" "github.com/databricks/cli/libs/dyn/yamlloader" @@ -322,7 +323,7 @@ func (s *fileSaver) block(typeKey string) (map[string]dyn.Value, error) { return nil, err } if len(node) > 0 { - out[edge.name] = dyn.NewValue(node, []dyn.Location{{Line: line}}) + out[edge.name] = dyn.NewValue(node, []diag.Location{{Line: line}}) line++ } } @@ -349,7 +350,7 @@ func (s *fileSaver) node(typeKey string, edge fieldEdge) (map[string]dyn.Value, return nil, err } if v.Kind() != dyn.KindNil { - out[typeDocKey] = v.WithLocations([]dyn.Location{{Line: lineTypeDoc}}) + out[typeDocKey] = v.WithLocations([]diag.Location{{Line: lineTypeDoc}}) } child, err := s.block(edge.typ) @@ -357,7 +358,7 @@ func (s *fileSaver) node(typeKey string, edge fieldEdge) (map[string]dyn.Value, return nil, err } if len(child) > 0 { - out[fieldsKey] = dyn.NewValue(child, []dyn.Location{{Line: lineFields}}) + out[fieldsKey] = dyn.NewValue(child, []diag.Location{{Line: lineFields}}) } } return out, nil diff --git a/bundle/libraries/expand_glob_references.go b/bundle/libraries/expand_glob_references.go index 2bdc81b60a2..df089f880a7 100644 --- a/bundle/libraries/expand_glob_references.go +++ b/bundle/libraries/expand_glob_references.go @@ -14,7 +14,7 @@ import ( type expand struct{} -func matchError(p dyn.Path, l []dyn.Location, message string) diag.Diagnostic { +func matchError(p dyn.Path, l []diag.Location, message string) diag.Diagnostic { return diag.Diagnostic{ Severity: diag.Error, Summary: message, diff --git a/bundle/libraries/expand_glob_references_test.go b/bundle/libraries/expand_glob_references_test.go index 44ffe97a6eb..331fbf2e7cb 100644 --- a/bundle/libraries/expand_glob_references_test.go +++ b/bundle/libraries/expand_glob_references_test.go @@ -9,6 +9,7 @@ import ( "github.com/databricks/cli/bundle/config/resources" "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/databricks-sdk-go/service/compute" "github.com/databricks/databricks-sdk-go/service/jobs" @@ -63,7 +64,7 @@ func TestGlobReferencesExpandedForTaskLibraries(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.Apply(t.Context(), b, ExpandGlobReferences()) require.Empty(t, diags) @@ -148,7 +149,7 @@ func TestGlobReferencesExpandedForForeachTaskLibraries(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.Apply(t.Context(), b, ExpandGlobReferences()) require.Empty(t, diags) @@ -223,7 +224,7 @@ func TestGlobReferencesExpandedForEnvironmentsDeps(t *testing.T) { }, } - bundletest.SetLocation(b, ".", []dyn.Location{{File: filepath.Join(dir, "resource.yml")}}) + bundletest.SetLocation(b, ".", []diag.Location{{File: filepath.Join(dir, "resource.yml")}}) diags := bundle.Apply(t.Context(), b, ExpandGlobReferences()) require.Empty(t, diags) @@ -276,8 +277,8 @@ func TestExpandGlobReferencesPreservesLocations(t *testing.T) { }, } - loc := dyn.Location{File: filepath.Join(dir, "resource.yml"), Line: 10, Column: 5} - bundletest.SetLocation(b, ".", []dyn.Location{loc}) + loc := diag.Location{File: filepath.Join(dir, "resource.yml"), Line: 10, Column: 5} + bundletest.SetLocation(b, ".", []diag.Location{loc}) diags := bundle.Apply(t.Context(), b, ExpandGlobReferences()) require.Empty(t, diags) diff --git a/bundle/libraries/remote_path.go b/bundle/libraries/remote_path.go index d45e8ff4c7e..70e577a1a2a 100644 --- a/bundle/libraries/remote_path.go +++ b/bundle/libraries/remote_path.go @@ -109,7 +109,7 @@ func ReplaceWithRemotePath(ctx context.Context, b *bundle.Bundle) (map[string][] for _, location := range locations { // Re-append the extras suffix that was stripped before upload. remotePathWithExtras := remotePath + location.extras - v, err = dyn.SetByPath(v, location.configPath, dyn.NewValue(remotePathWithExtras, []dyn.Location{location.location})) + v, err = dyn.SetByPath(v, location.configPath, dyn.NewValue(remotePathWithExtras, []diag.Location{location.location})) if err != nil { return v, fmt.Errorf("internal error: failed to update path %#v to %#v: %w", source, remotePathWithExtras, err) } diff --git a/bundle/libraries/same_name_libraries.go b/bundle/libraries/same_name_libraries.go index 1d50c946a27..722d42c7f64 100644 --- a/bundle/libraries/same_name_libraries.go +++ b/bundle/libraries/same_name_libraries.go @@ -26,7 +26,7 @@ var patterns = []dyn.Pattern{ type libData struct { fullPath string - locations []dyn.Location + locations []diag.Location paths []*structpath.PathNode otherPaths []string } @@ -56,7 +56,7 @@ func (c checkForSameNameLibraries) Apply(ctx context.Context, b *bundle.Bundle) if !ok { libs[lib] = &libData{ fullPath: libPath, - locations: []dyn.Location{libraryValue.Location()}, + locations: []diag.Location{libraryValue.Location()}, paths: dyn.ToStructPaths(p), otherPaths: []string{}, } diff --git a/bundle/libraries/upload.go b/bundle/libraries/upload.go index dabd4d8860d..247c380a864 100644 --- a/bundle/libraries/upload.go +++ b/bundle/libraries/upload.go @@ -37,7 +37,7 @@ type upload struct { type LocationToUpdate struct { configPath dyn.Path - location dyn.Location + location diag.Location // extras is the pip extras suffix (e.g. "[train]") to re-append to the // rewritten remote path. Empty for libraries that carry no extras. extras string diff --git a/bundle/permissions/permission_diagnostics.go b/bundle/permissions/permission_diagnostics.go index e25ccd5e724..0e01f72a0f4 100644 --- a/bundle/permissions/permission_diagnostics.go +++ b/bundle/permissions/permission_diagnostics.go @@ -8,7 +8,6 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/iamutil" "github.com/databricks/cli/libs/set" ) @@ -59,7 +58,7 @@ func (m *permissionDiagnostics) Apply(ctx context.Context, b *bundle.Bundle) dia identityType, b.Config.Workspace.CurrentUser.UserName, ), - Locations: []dyn.Location{b.Config.GetLocation("permissions")}, + Locations: []diag.Location{b.Config.GetLocation("permissions")}, ID: diag.PermissionNotIncluded, }} } diff --git a/bundle/render/render_text_output_test.go b/bundle/render/render_text_output_test.go index 3857803a406..4c87fbb4eb9 100644 --- a/bundle/render/render_text_output_test.go +++ b/bundle/render/render_text_output_test.go @@ -11,7 +11,6 @@ import ( "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/libs/cmdio" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/logdiag" "github.com/databricks/cli/libs/structs/structpath" "github.com/databricks/databricks-sdk-go/service/catalog" @@ -160,7 +159,7 @@ func TestRenderDiagnostics(t *testing.T) { Severity: diag.Error, Summary: "failed to load xxx", Detail: "'name' is required", - Locations: []dyn.Location{{ + Locations: []diag.Location{{ File: "foo.yaml", Line: 1, Column: 2, @@ -178,7 +177,7 @@ func TestRenderDiagnostics(t *testing.T) { Severity: diag.Error, Summary: "failed to load xxx", Detail: "'name' is required", - Locations: []dyn.Location{ + Locations: []diag.Location{ { File: "foo.yaml", Line: 1, @@ -244,7 +243,7 @@ func TestRenderDiagnostics(t *testing.T) { "resources.jobs.xxx", "resources.jobs.yyy", ), - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "foo.yaml", Line: 1, Column: 2}, {File: "bar.yaml", Line: 3, Column: 4}, }, diff --git a/bundle/run/app_test.go b/bundle/run/app_test.go index abdb7dd4f73..d43e8a92b16 100644 --- a/bundle/run/app_test.go +++ b/bundle/run/app_test.go @@ -15,7 +15,7 @@ import ( "github.com/databricks/cli/bundle/config/resources" "github.com/databricks/cli/bundle/internal/bundletest" "github.com/databricks/cli/libs/cmdio" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/vfs" "github.com/databricks/databricks-sdk-go/experimental/mocks" "github.com/databricks/databricks-sdk-go/service/apps" @@ -68,7 +68,7 @@ func setupBundle(t *testing.T) (context.Context, *bundle.Bundle, *mocks.MockWork mwc := mocks.NewMockWorkspaceClient(t) b.SetWorkpaceClient(mwc.WorkspaceClient) - bundletest.SetLocation(b, "resources.apps.my_app", []dyn.Location{{File: filepath.Join(root, "./databricks.yml")}}) + bundletest.SetLocation(b, "resources.apps.my_app", []diag.Location{{File: filepath.Join(root, "./databricks.yml")}}) ctx := cmdio.MockDiscard(t.Context()) diff --git a/bundle/tests/validate_test.go b/bundle/tests/validate_test.go index 449f2bd37c0..065dbf0652c 100644 --- a/bundle/tests/validate_test.go +++ b/bundle/tests/validate_test.go @@ -6,7 +6,6 @@ import ( "github.com/databricks/cli/bundle" "github.com/databricks/cli/bundle/phases" "github.com/databricks/cli/libs/diag" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/logdiag" "github.com/databricks/cli/libs/structs/structpath" "github.com/stretchr/testify/assert" @@ -24,7 +23,7 @@ func TestValidateUniqueResourceIdentifiers(t *testing.T) { { Severity: diag.Error, Summary: "multiple resources or scripts have been defined with the same key: foo", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "validate/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml", Line: 10, Column: 7}, {File: "validate/duplicate_resource_names_in_root_job_and_pipeline/databricks.yml", Line: 13, Column: 7}, }, @@ -41,7 +40,7 @@ func TestValidateUniqueResourceIdentifiers(t *testing.T) { { Severity: diag.Error, Summary: "multiple resources or scripts have been defined with the same key: foo", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "validate/duplicate_resource_names_in_root_job_and_experiment/databricks.yml", Line: 10, Column: 7}, {File: "validate/duplicate_resource_names_in_root_job_and_experiment/databricks.yml", Line: 18, Column: 7}, }, @@ -58,7 +57,7 @@ func TestValidateUniqueResourceIdentifiers(t *testing.T) { { Severity: diag.Error, Summary: "multiple resources or scripts have been defined with the same key: foo", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "validate/duplicate_resource_name_in_subconfiguration/databricks.yml", Line: 13, Column: 7}, {File: "validate/duplicate_resource_name_in_subconfiguration/resources.yml", Line: 4, Column: 7}, }, @@ -75,7 +74,7 @@ func TestValidateUniqueResourceIdentifiers(t *testing.T) { { Severity: diag.Error, Summary: "multiple resources or scripts have been defined with the same key: foo", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "validate/duplicate_resource_name_in_subconfiguration_job_and_job/databricks.yml", Line: 13, Column: 7}, {File: "validate/duplicate_resource_name_in_subconfiguration_job_and_job/resources.yml", Line: 4, Column: 7}, }, @@ -89,7 +88,7 @@ func TestValidateUniqueResourceIdentifiers(t *testing.T) { { Severity: diag.Error, Summary: "multiple resources or scripts have been defined with the same key: foo", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "validate/duplicate_resource_names_in_different_subconfiguations/resources1.yml", Line: 4, Column: 7}, {File: "validate/duplicate_resource_names_in_different_subconfiguations/resources2.yml", Line: 4, Column: 7}, }, @@ -106,7 +105,7 @@ func TestValidateUniqueResourceIdentifiers(t *testing.T) { { Severity: diag.Error, Summary: "multiple resources or scripts have been defined with the same key: foo", - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "validate/duplicate_resource_name_in_multiple_locations/databricks.yml", Line: 13, Column: 7}, {File: "validate/duplicate_resource_name_in_multiple_locations/resources1.yml", Line: 4, Column: 7}, {File: "validate/duplicate_resource_name_in_multiple_locations/resources1.yml", Line: 8, Column: 7}, diff --git a/cmd/air/convert_to_dabs.go b/cmd/air/convert_to_dabs.go index 2a2410accf2..02b29a4d02f 100644 --- a/cmd/air/convert_to_dabs.go +++ b/cmd/air/convert_to_dabs.go @@ -13,6 +13,7 @@ import ( "github.com/databricks/cli/cmd/root" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/yamlsaver" "github.com/spf13/cobra" @@ -263,7 +264,7 @@ func bundleCodeSourcePath(ctx context.Context, cfg *runConfig, configPath, bundl // It routes through dyn.V so nested Go maps/slices are converted recursively, // then stamps the ordering location. func nv(v any, n int) dyn.Value { - return dyn.V(v).WithLocations([]dyn.Location{{Line: n}}) + return dyn.V(v).WithLocations([]diag.Location{{Line: n}}) } // localBundlePath renders a bundle-relative path with a leading "./" so bundle diff --git a/cmd/apps/import.go b/cmd/apps/import.go index f6089870aec..355c51c690e 100644 --- a/cmd/apps/import.go +++ b/cmd/apps/import.go @@ -25,6 +25,7 @@ import ( "github.com/databricks/cli/libs/apps/prompt" "github.com/databricks/cli/libs/cmdctx" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/convert" "github.com/databricks/cli/libs/dyn/yamlsaver" @@ -460,16 +461,16 @@ func generateAppBundle(ctx context.Context, w *databricks.WorkspaceClient, app * bundleName := textutil.NormalizeString(app.Name) bundleConfig := map[string]dyn.Value{ "bundle": dyn.NewValue(map[string]dyn.Value{ - "name": dyn.NewValue(bundleName, []dyn.Location{{Line: 1}}), - }, []dyn.Location{{Line: 1}}), + "name": dyn.NewValue(bundleName, []diag.Location{{Line: 1}}), + }, []diag.Location{{Line: 1}}), "workspace": dyn.NewValue(map[string]dyn.Value{ - "host": dyn.NewValue(w.Config.Host, []dyn.Location{{Line: 2}}), - }, []dyn.Location{{Line: 10}}), + "host": dyn.NewValue(w.Config.Host, []diag.Location{{Line: 2}}), + }, []diag.Location{{Line: 10}}), "resources": dyn.NewValue(map[string]dyn.Value{ "apps": dyn.V(map[string]dyn.Value{ appKey: v, }), - }, []dyn.Location{{Line: 20}}), + }, []diag.Location{{Line: 20}}), } // Download the app source files diff --git a/cmd/pipelines/generate.go b/cmd/pipelines/generate.go index e1e5666b429..c865213c36a 100644 --- a/cmd/pipelines/generate.go +++ b/cmd/pipelines/generate.go @@ -10,6 +10,7 @@ import ( "github.com/databricks/cli/bundle/config" "github.com/databricks/cli/libs/cmdio" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/convert" "github.com/databricks/cli/libs/dyn/yamlloader" @@ -265,12 +266,12 @@ func convertToResources(spec *sdpPipeline, resourceName, srcFolder string) (map[ return nil, fmt.Errorf("failed to convert libraries into dyn.Value: %w", err) } - // maps are unordered, and saver is sorting keys by dyn.Location + // maps are unordered, and saver is sorting keys by diag.Location // this is helper function to monotonically assign locations as keys are created var line int - nextLocation := func() []dyn.Location { + nextLocation := func() []diag.Location { line += 1 - return []dyn.Location{{Line: line}} + return []diag.Location{{Line: line}} } pipelineMap := map[string]dyn.Value{ diff --git a/cmd/pipelines/generate_test.go b/cmd/pipelines/generate_test.go index d9396932dfa..7135031ccbb 100644 --- a/cmd/pipelines/generate_test.go +++ b/cmd/pipelines/generate_test.go @@ -5,6 +5,7 @@ import ( "path/filepath" "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/dynassert" "github.com/stretchr/testify/assert" @@ -177,27 +178,27 @@ func TestConvertToResources(t *testing.T) { "resources": dyn.V(map[string]dyn.Value{ "pipelines": dyn.V(map[string]dyn.Value{ "my_pipeline": dyn.V(map[string]dyn.Value{ - "name": dyn.V("My Pipeline").WithLocations([]dyn.Location{{Line: 1}}), - "catalog": dyn.V("${var.catalog}").WithLocations([]dyn.Location{{Line: 2}}), - "schema": dyn.V("${var.schema}").WithLocations([]dyn.Location{{Line: 3}}), - "root_path": dyn.V("../src/my_pipeline").WithLocations([]dyn.Location{{Line: 4}}), - "serverless": dyn.V(true).WithLocations([]dyn.Location{{Line: 5}}), + "name": dyn.V("My Pipeline").WithLocations([]diag.Location{{Line: 1}}), + "catalog": dyn.V("${var.catalog}").WithLocations([]diag.Location{{Line: 2}}), + "schema": dyn.V("${var.schema}").WithLocations([]diag.Location{{Line: 3}}), + "root_path": dyn.V("../src/my_pipeline").WithLocations([]diag.Location{{Line: 4}}), + "serverless": dyn.V(true).WithLocations([]diag.Location{{Line: 5}}), "libraries": dyn.V([]dyn.Value{ dyn.V(map[string]dyn.Value{ "glob": dyn.V(map[string]dyn.Value{ "include": dyn.V("../src/my_pipeline/transformations/**"), }), }), - }).WithLocations([]dyn.Location{{Line: 6}}), + }).WithLocations([]diag.Location{{Line: 6}}), "configuration": dyn.V(map[string]dyn.Value{ "key0": dyn.V("value0"), "key1": dyn.V("value1"), - }).WithLocations([]dyn.Location{{Line: 7}}), + }).WithLocations([]diag.Location{{Line: 7}}), "environment": dyn.V(map[string]dyn.Value{ "dependencies": dyn.V([]dyn.Value{ dyn.V("--editable ${workspace.file_path}"), }), - }).WithLocations([]dyn.Location{{Line: 8}}), + }).WithLocations([]diag.Location{{Line: 8}}), }), }), }), diff --git a/libs/diag/diagnostic.go b/libs/diag/diagnostic.go index f189cf0ac6c..9356cc9ddd6 100644 --- a/libs/diag/diagnostic.go +++ b/libs/diag/diagnostic.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" - "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/structs/structpath" ) @@ -21,7 +20,7 @@ type Diagnostic struct { // Locations are the source code locations associated with the diagnostic message. // It may be empty if there are no associated locations. - Locations []dyn.Location + Locations []Location // Paths are paths to the values in the configuration tree that the diagnostic is associated with. // It may be nil if there are no associated paths. diff --git a/libs/dyn/location.go b/libs/diag/location.go similarity index 93% rename from libs/dyn/location.go rename to libs/diag/location.go index b8ec818fcde..3b4a799e348 100644 --- a/libs/dyn/location.go +++ b/libs/diag/location.go @@ -1,4 +1,4 @@ -package dyn +package diag import ( "fmt" diff --git a/libs/dyn/location_test.go b/libs/diag/location_test.go similarity index 55% rename from libs/dyn/location_test.go rename to libs/diag/location_test.go index 29226d73d03..005254009e9 100644 --- a/libs/dyn/location_test.go +++ b/libs/diag/location_test.go @@ -1,13 +1,13 @@ -package dyn_test +package diag_test import ( "testing" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" "github.com/stretchr/testify/assert" ) func TestLocation(t *testing.T) { - loc := dyn.Location{File: "file", Line: 1, Column: 2} + loc := diag.Location{File: "file", Line: 1, Column: 2} assert.Equal(t, "file:1:2", loc.String()) } diff --git a/libs/dyn/convert/from_typed_test.go b/libs/dyn/convert/from_typed_test.go index 0c8cf902bb4..be43b20256b 100644 --- a/libs/dyn/convert/from_typed_test.go +++ b/libs/dyn/convert/from_typed_test.go @@ -3,6 +3,7 @@ package convert import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/dynassert" "github.com/stretchr/testify/assert" @@ -188,16 +189,16 @@ func TestFromTypedStructSetFieldsRetainLocation(t *testing.T) { } ref := dyn.V(map[string]dyn.Value{ - "foo": dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), - "bar": dyn.NewValue("baz", []dyn.Location{{File: "bar"}}), + "foo": dyn.NewValue("bar", []diag.Location{{File: "foo"}}), + "bar": dyn.NewValue("baz", []diag.Location{{File: "bar"}}), }) nv, err := FromTyped(src, ref) require.NoError(t, err) // Assert foo and bar have retained their location. - assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), nv.Get("foo")) - assert.Equal(t, dyn.NewValue("qux", []dyn.Location{{File: "bar"}}), nv.Get("bar")) + assert.Equal(t, dyn.NewValue("bar", []diag.Location{{File: "foo"}}), nv.Get("foo")) + assert.Equal(t, dyn.NewValue("qux", []diag.Location{{File: "bar"}}), nv.Get("bar")) } func TestFromTypedStringMapWithZeroValue(t *testing.T) { @@ -432,16 +433,16 @@ func TestFromTypedMapNonEmptyRetainLocation(t *testing.T) { } ref := dyn.V(map[string]dyn.Value{ - "foo": dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), - "bar": dyn.NewValue("baz", []dyn.Location{{File: "bar"}}), + "foo": dyn.NewValue("bar", []diag.Location{{File: "foo"}}), + "bar": dyn.NewValue("baz", []diag.Location{{File: "bar"}}), }) nv, err := FromTyped(src, ref) require.NoError(t, err) // Assert foo and bar have retained their locations. - assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), nv.Get("foo")) - assert.Equal(t, dyn.NewValue("qux", []dyn.Location{{File: "bar"}}), nv.Get("bar")) + assert.Equal(t, dyn.NewValue("bar", []diag.Location{{File: "foo"}}), nv.Get("foo")) + assert.Equal(t, dyn.NewValue("qux", []diag.Location{{File: "bar"}}), nv.Get("bar")) } func TestFromTypedMapFieldWithZeroValue(t *testing.T) { @@ -506,16 +507,16 @@ func TestFromTypedSliceNonEmptyRetainLocation(t *testing.T) { } ref := dyn.V([]dyn.Value{ - dyn.NewValue("foo", []dyn.Location{{File: "foo"}}), - dyn.NewValue("bar", []dyn.Location{{File: "bar"}}), + dyn.NewValue("foo", []diag.Location{{File: "foo"}}), + dyn.NewValue("bar", []diag.Location{{File: "bar"}}), }) nv, err := FromTyped(src, ref) require.NoError(t, err) // Assert foo and bar have retained their locations. - assert.Equal(t, dyn.NewValue("foo", []dyn.Location{{File: "foo"}}), nv.Index(0)) - assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "bar"}}), nv.Index(1)) + assert.Equal(t, dyn.NewValue("foo", []diag.Location{{File: "foo"}}), nv.Index(0)) + assert.Equal(t, dyn.NewValue("bar", []diag.Location{{File: "bar"}}), nv.Index(1)) } func TestFromTypedStringEmpty(t *testing.T) { @@ -551,19 +552,19 @@ func TestFromTypedStringNonEmptyOverwrite(t *testing.T) { } func TestFromTypedStringRetainsLocations(t *testing.T) { - ref := dyn.NewValue("foo", []dyn.Location{{File: "foo"}}) + ref := dyn.NewValue("foo", []diag.Location{{File: "foo"}}) // case: value has not been changed src := "foo" nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue("foo", []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue("foo", []diag.Location{{File: "foo"}}), nv) // case: value has been changed src = "bar" nv, err = FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue("bar", []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue("bar", []diag.Location{{File: "foo"}}), nv) } func TestFromTypedStringTypeError(t *testing.T) { @@ -606,19 +607,19 @@ func TestFromTypedBoolNonEmptyOverwrite(t *testing.T) { } func TestFromTypedBoolRetainsLocations(t *testing.T) { - ref := dyn.NewValue(true, []dyn.Location{{File: "foo"}}) + ref := dyn.NewValue(true, []diag.Location{{File: "foo"}}) // case: value has not been changed src := true nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(true, []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue(true, []diag.Location{{File: "foo"}}), nv) // case: value has been changed src = false nv, err = FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(false, []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue(false, []diag.Location{{File: "foo"}}), nv) } func TestFromTypedBoolVariableReference(t *testing.T) { @@ -669,19 +670,19 @@ func TestFromTypedIntNonEmptyOverwrite(t *testing.T) { } func TestFromTypedIntRetainsLocations(t *testing.T) { - ref := dyn.NewValue(1234, []dyn.Location{{File: "foo"}}) + ref := dyn.NewValue(1234, []diag.Location{{File: "foo"}}) // case: value has not been changed src := 1234 nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(1234, []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue(1234, []diag.Location{{File: "foo"}}), nv) // case: value has been changed src = 1235 nv, err = FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(int64(1235), []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue(int64(1235), []diag.Location{{File: "foo"}}), nv) } func TestFromTypedIntVariableReference(t *testing.T) { @@ -733,19 +734,19 @@ func TestFromTypedFloatNonEmptyOverwrite(t *testing.T) { func TestFromTypedFloatRetainsLocations(t *testing.T) { var src float64 - ref := dyn.NewValue(1.23, []dyn.Location{{File: "foo"}}) + ref := dyn.NewValue(1.23, []diag.Location{{File: "foo"}}) // case: value has not been changed src = 1.23 nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(1.23, []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue(1.23, []diag.Location{{File: "foo"}}), nv) // case: value has been changed src = 1.24 nv, err = FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(1.24, []dyn.Location{{File: "foo"}}), nv) + assert.Equal(t, dyn.NewValue(1.24, []diag.Location{{File: "foo"}}), nv) } func TestFromTypedFloatVariableReference(t *testing.T) { @@ -814,29 +815,29 @@ func TestFromTypedNilPointerRetainsLocations(t *testing.T) { } var src *Tmp - ref := dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}) + ref := dyn.NewValue(nil, []diag.Location{{File: "foobar"}}) nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}), nv) + assert.Equal(t, dyn.NewValue(nil, []diag.Location{{File: "foobar"}}), nv) } func TestFromTypedNilMapRetainsLocation(t *testing.T) { var src map[string]string - ref := dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}) + ref := dyn.NewValue(nil, []diag.Location{{File: "foobar"}}) nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}), nv) + assert.Equal(t, dyn.NewValue(nil, []diag.Location{{File: "foobar"}}), nv) } func TestFromTypedNilSliceRetainsLocation(t *testing.T) { var src []string - ref := dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}) + ref := dyn.NewValue(nil, []diag.Location{{File: "foobar"}}) nv, err := FromTyped(src, ref) require.NoError(t, err) - assert.Equal(t, dyn.NewValue(nil, []dyn.Location{{File: "foobar"}}), nv) + assert.Equal(t, dyn.NewValue(nil, []diag.Location{{File: "foobar"}}), nv) } func TestFromTypedForceSendFieldsComplexTypes(t *testing.T) { diff --git a/libs/dyn/convert/normalize.go b/libs/dyn/convert/normalize.go index 379baf439d1..e41ed4a0a87 100644 --- a/libs/dyn/convert/normalize.go +++ b/libs/dyn/convert/normalize.go @@ -84,7 +84,7 @@ func nullWarning(expected dyn.Kind, src dyn.Value, path dyn.Path) diag.Diagnosti return diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf("expected a %s value, found null", expected), - Locations: []dyn.Location{src.Location()}, + Locations: []diag.Location{src.Location()}, Paths: dyn.ToStructPaths(path), } } @@ -93,7 +93,7 @@ func typeMismatch(expected dyn.Kind, src dyn.Value, path dyn.Path) diag.Diagnost return diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf("expected %s, found %s", expected, src.Kind()), - Locations: []dyn.Location{src.Location()}, + Locations: []diag.Location{src.Location()}, Paths: dyn.ToStructPaths(path), } } @@ -398,7 +398,7 @@ func (n normalizeOptions) normalizeInt(typ reflect.Type, src dyn.Value, path dyn return dyn.InvalidValue, diags.Append(diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf(`cannot accurately represent "%g" as integer due to precision loss`, src.MustFloat()), - Locations: []dyn.Location{src.Location()}, + Locations: []diag.Location{src.Location()}, Paths: dyn.ToStructPaths(path), }) } @@ -415,7 +415,7 @@ func (n normalizeOptions) normalizeInt(typ reflect.Type, src dyn.Value, path dyn return dyn.InvalidValue, diags.Append(diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf("cannot parse %q as an integer", src.MustString()), - Locations: []dyn.Location{src.Location()}, + Locations: []diag.Location{src.Location()}, Paths: dyn.ToStructPaths(path), }) } @@ -442,7 +442,7 @@ func (n normalizeOptions) normalizeFloat(typ reflect.Type, src dyn.Value, path d return dyn.InvalidValue, diags.Append(diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf(`cannot accurately represent "%d" as floating point number due to precision loss`, src.MustInt()), - Locations: []dyn.Location{src.Location()}, + Locations: []diag.Location{src.Location()}, Paths: dyn.ToStructPaths(path), }) } @@ -459,7 +459,7 @@ func (n normalizeOptions) normalizeFloat(typ reflect.Type, src dyn.Value, path d return dyn.InvalidValue, diags.Append(diag.Diagnostic{ Severity: diag.Warning, Summary: fmt.Sprintf("cannot parse %q as a floating point number", src.MustString()), - Locations: []dyn.Location{src.Location()}, + Locations: []diag.Location{src.Location()}, Paths: dyn.ToStructPaths(path), }) } diff --git a/libs/dyn/convert/normalize_test.go b/libs/dyn/convert/normalize_test.go index b2bed72db71..ac95aaafac6 100644 --- a/libs/dyn/convert/normalize_test.go +++ b/libs/dyn/convert/normalize_test.go @@ -44,7 +44,7 @@ func TestNormalizeStructElementDiagnostic(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected string, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: structpath.NewPathSlice("bar"), }, diags[0]) @@ -65,7 +65,7 @@ func TestNormalizeStructUnknownField(t *testing.T) { m.SetLoc("foo", nil, dyn.V("val-foo")) // Set the unknown field, with location information. - m.SetLoc("bar", []dyn.Location{ + m.SetLoc("bar", []diag.Location{ {File: "hello.yaml", Line: 1, Column: 1}, {File: "world.yaml", Line: 2, Column: 2}, }, dyn.V("var-bar")) @@ -78,7 +78,7 @@ func TestNormalizeStructUnknownField(t *testing.T) { Severity: diag.Warning, Summary: `unknown field: bar`, // Assert location of the unknown field is included in the diagnostic. - Locations: []dyn.Location{ + Locations: []diag.Location{ {File: "hello.yaml", Line: 1, Column: 1}, {File: "world.yaml", Line: 2, Column: 2}, }, @@ -115,7 +115,7 @@ func TestNormalizeStructError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected map, found string`, - Locations: []dyn.Location{vin.Get("foo").Location()}, + Locations: []diag.Location{vin.Get("foo").Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -242,7 +242,7 @@ func TestNormalizeStructVariableReference(t *testing.T) { } var typ Tmp - vin := dyn.NewValue("${var.foo}", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("${var.foo}", []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(typ, vin) assert.Empty(t, err) assert.Equal(t, vin, vout) @@ -254,13 +254,13 @@ func TestNormalizeStructRandomStringError(t *testing.T) { } var typ Tmp - vin := dyn.NewValue("var foo", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("var foo", []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected map, found string`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -271,13 +271,13 @@ func TestNormalizeStructIntError(t *testing.T) { } var typ Tmp - vin := dyn.NewValue(1, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(1, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected map, found int`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -306,7 +306,7 @@ func TestNormalizeMapElementDiagnostic(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected string, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: structpath.NewPathSlice("bar"), }, err[0]) @@ -332,7 +332,7 @@ func TestNormalizeMapError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected map, found string`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -373,7 +373,7 @@ func TestNormalizeMapNestedError(t *testing.T) { func TestNormalizeMapVariableReference(t *testing.T) { var typ map[string]string - vin := dyn.NewValue("${var.foo}", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("${var.foo}", []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(typ, vin) assert.Empty(t, err) assert.Equal(t, vin, vout) @@ -381,26 +381,26 @@ func TestNormalizeMapVariableReference(t *testing.T) { func TestNormalizeMapRandomStringError(t *testing.T) { var typ map[string]string - vin := dyn.NewValue("var foo", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("var foo", []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected map, found string`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } func TestNormalizeMapIntError(t *testing.T) { var typ map[string]string - vin := dyn.NewValue(1, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(1, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected map, found int`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -430,7 +430,7 @@ func TestNormalizeSliceElementDiagnostic(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected string, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: []*structpath.PathNode{structpath.NewIndex(nil, 2)}, }, err[0]) @@ -454,7 +454,7 @@ func TestNormalizeSliceError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected sequence, found string`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -495,7 +495,7 @@ func TestNormalizeSliceNestedError(t *testing.T) { func TestNormalizeSliceVariableReference(t *testing.T) { var typ []string - vin := dyn.NewValue("${var.foo}", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("${var.foo}", []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(typ, vin) assert.Empty(t, err) assert.Equal(t, vin, vout) @@ -503,26 +503,26 @@ func TestNormalizeSliceVariableReference(t *testing.T) { func TestNormalizeSliceRandomStringError(t *testing.T) { var typ []string - vin := dyn.NewValue("var foo", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("var foo", []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected sequence, found string`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } func TestNormalizeSliceIntError(t *testing.T) { var typ []string - vin := dyn.NewValue(1, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(1, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected sequence, found int`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -537,20 +537,20 @@ func TestNormalizeString(t *testing.T) { func TestNormalizeStringNil(t *testing.T) { var typ string - vin := dyn.NewValue(nil, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(nil, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(&typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected a string value, found null`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } func TestNormalizeStringFromBool(t *testing.T) { var typ string - vin := dyn.NewValue(true, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(true, []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) assert.Equal(t, dyn.NewValue("true", vin.Locations()), vout) @@ -558,7 +558,7 @@ func TestNormalizeStringFromBool(t *testing.T) { func TestNormalizeStringFromInt(t *testing.T) { var typ string - vin := dyn.NewValue(123, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(123, []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) assert.Equal(t, dyn.NewValue("123", vin.Locations()), vout) @@ -566,7 +566,7 @@ func TestNormalizeStringFromInt(t *testing.T) { func TestNormalizeStringFromFloat(t *testing.T) { var typ string - vin := dyn.NewValue(1.20, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(1.20, []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) assert.Equal(t, dyn.NewValue("1.2", vin.Locations()), vout) @@ -574,7 +574,7 @@ func TestNormalizeStringFromFloat(t *testing.T) { func TestNormalizeStringFromTime(t *testing.T) { var typ string - vin := dyn.NewValue(dyn.MustTime("2024-08-29"), []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(dyn.MustTime("2024-08-29"), []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) assert.Equal(t, dyn.NewValue("2024-08-29", vin.Locations()), vout) @@ -588,7 +588,7 @@ func TestNormalizeStringError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected string, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -603,13 +603,13 @@ func TestNormalizeBool(t *testing.T) { func TestNormalizeBoolNil(t *testing.T) { var typ bool - vin := dyn.NewValue(nil, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(nil, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(&typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected a bool value, found null`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -655,7 +655,7 @@ func TestNormalizeBoolFromStringError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected bool, found string`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -668,7 +668,7 @@ func TestNormalizeBoolError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected bool, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -683,13 +683,13 @@ func TestNormalizeInt(t *testing.T) { func TestNormalizeIntNil(t *testing.T) { var typ int - vin := dyn.NewValue(nil, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(nil, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(&typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected a int value, found null`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -710,7 +710,7 @@ func TestNormalizeIntFromFloatError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `cannot accurately represent "1.5" as integer due to precision loss`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -739,7 +739,7 @@ func TestNormalizeIntFromStringError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `cannot parse "abc" as an integer`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -752,7 +752,7 @@ func TestNormalizeIntError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected int, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -767,13 +767,13 @@ func TestNormalizeFloat(t *testing.T) { func TestNormalizeFloatNil(t *testing.T) { var typ float64 - vin := dyn.NewValue(nil, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(nil, []diag.Location{{File: "file", Line: 1, Column: 1}}) _, err := Normalize(&typ, vin) assert.Len(t, err, 1) assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected a float value, found null`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -798,7 +798,7 @@ func TestNormalizeFloatFromIntError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `cannot accurately represent "9007199254740993" as floating point number due to precision loss`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -827,7 +827,7 @@ func TestNormalizeFloatFromStringError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `cannot parse "abc" as a floating point number`, - Locations: []dyn.Location{vin.Location()}, + Locations: []diag.Location{vin.Location()}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -840,7 +840,7 @@ func TestNormalizeFloatError(t *testing.T) { assert.Equal(t, diag.Diagnostic{ Severity: diag.Warning, Summary: `expected float, found map`, - Locations: []dyn.Location{{}}, + Locations: []diag.Location{{}}, Paths: dyn.ToStructPaths(dyn.EmptyPath), }, err[0]) } @@ -940,41 +940,41 @@ func TestNormalizeAnchorContainers(t *testing.T) { func TestNormalizeAnyFromSlice(t *testing.T) { var typ any - v1 := dyn.NewValue(1, []dyn.Location{{File: "file", Line: 1, Column: 1}}) - v2 := dyn.NewValue(2, []dyn.Location{{File: "file", Line: 1, Column: 1}}) - vin := dyn.NewValue([]dyn.Value{v1, v2}, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + v1 := dyn.NewValue(1, []diag.Location{{File: "file", Line: 1, Column: 1}}) + v2 := dyn.NewValue(2, []diag.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue([]dyn.Value{v1, v2}, []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) - assert.Equal(t, dyn.NewValue([]dyn.Value{v1, v2}, []dyn.Location{{File: "file", Line: 1, Column: 1}}), vout) + assert.Equal(t, dyn.NewValue([]dyn.Value{v1, v2}, []diag.Location{{File: "file", Line: 1, Column: 1}}), vout) } func TestNormalizeAnyFromString(t *testing.T) { var typ any - vin := dyn.NewValue("string", []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue("string", []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) - assert.Equal(t, dyn.NewValue("string", []dyn.Location{{File: "file", Line: 1, Column: 1}}), vout) + assert.Equal(t, dyn.NewValue("string", []diag.Location{{File: "file", Line: 1, Column: 1}}), vout) } func TestNormalizeAnyFromBool(t *testing.T) { var typ any - vin := dyn.NewValue(false, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(false, []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) - assert.Equal(t, dyn.NewValue(false, []dyn.Location{{File: "file", Line: 1, Column: 1}}), vout) + assert.Equal(t, dyn.NewValue(false, []diag.Location{{File: "file", Line: 1, Column: 1}}), vout) } func TestNormalizeAnyFromInt(t *testing.T) { var typ any - vin := dyn.NewValue(10, []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(10, []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) - assert.Equal(t, dyn.NewValue(10, []dyn.Location{{File: "file", Line: 1, Column: 1}}), vout) + assert.Equal(t, dyn.NewValue(10, []diag.Location{{File: "file", Line: 1, Column: 1}}), vout) } func TestNormalizeAnyFromTime(t *testing.T) { var typ any - vin := dyn.NewValue(dyn.MustTime("2024-08-29"), []dyn.Location{{File: "file", Line: 1, Column: 1}}) + vin := dyn.NewValue(dyn.MustTime("2024-08-29"), []diag.Location{{File: "file", Line: 1, Column: 1}}) vout, err := Normalize(&typ, vin) assert.Empty(t, err) assert.Equal(t, dyn.NewValue("2024-08-29", vin.Locations()), vout) diff --git a/libs/dyn/dynloc/locations.go b/libs/dyn/dynloc/locations.go index 5c8e22f0939..d343e24533c 100644 --- a/libs/dyn/dynloc/locations.go +++ b/libs/dyn/dynloc/locations.go @@ -6,6 +6,7 @@ import ( "path/filepath" "slices" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" ) @@ -37,8 +38,8 @@ type Locations struct { basePath string } -func (l *Locations) gatherLocations(v dyn.Value) (map[string][]dyn.Location, error) { - locs := map[string][]dyn.Location{} +func (l *Locations) gatherLocations(v dyn.Value) (map[string][]diag.Location, error) { + locs := map[string][]diag.Location{} patterns := []dyn.Pattern{ dyn.NewPattern(dyn.AnyKey()), // Top level fields dyn.NewPattern(dyn.Key("resources"), dyn.AnyKey()), // Resource groups ("resources.jobs") @@ -74,7 +75,7 @@ func (l *Locations) normalizeFilePath(file string) (string, error) { return filepath.ToSlash(file), nil } -func (l *Locations) registerFileNames(locs []dyn.Location) error { +func (l *Locations) registerFileNames(locs []diag.Location) error { cache := map[string]string{} for _, loc := range locs { // Never process the same file path twice. diff --git a/libs/dyn/jsonloader/json.go b/libs/dyn/jsonloader/json.go index 3161ef637b1..8db526bd97d 100644 --- a/libs/dyn/jsonloader/json.go +++ b/libs/dyn/jsonloader/json.go @@ -7,6 +7,7 @@ import ( "fmt" "io" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" ) @@ -78,7 +79,7 @@ func decodeValue(decoder *json.Decoder, o *Offset) (dyn.Value, error) { // Get the offset of the key by subtracting the length of the key and the '"' character keyOffset := decoder.InputOffset() - int64(len(key)+1) - loc := []dyn.Location{o.GetPosition(keyOffset)} + loc := []diag.Location{o.GetPosition(keyOffset)} // Decode the value recursively val, err := decodeValue(decoder, o) @@ -92,7 +93,7 @@ func decodeValue(decoder *json.Decoder, o *Offset) (dyn.Value, error) { if _, err := decoder.Token(); err != nil { return invalidValueWithLocation(decoder, o), err } - return dyn.NewValue(obj, []dyn.Location{location}), nil + return dyn.NewValue(obj, []diag.Location{location}), nil case '[': location = o.GetPosition(offset - 1) // Decode JSON array @@ -108,20 +109,20 @@ func decodeValue(decoder *json.Decoder, o *Offset) (dyn.Value, error) { if _, err := decoder.Token(); err != nil { return invalidValueWithLocation(decoder, o), err } - return dyn.NewValue(arr, []dyn.Location{location}), nil + return dyn.NewValue(arr, []diag.Location{location}), nil } case json.Number: // Integers that overflow int64 fall back to float64, matching the decoder's behavior without UseNumber. if i64, err := tok.Int64(); err == nil { - return dyn.NewValue(i64, []dyn.Location{location}), nil + return dyn.NewValue(i64, []diag.Location{location}), nil } f64, err := tok.Float64() if err != nil { return invalidValueWithLocation(decoder, o), fmt.Errorf("invalid number %q: %w", tok.String(), err) } - return dyn.NewValue(f64, []dyn.Location{location}), nil + return dyn.NewValue(f64, []diag.Location{location}), nil default: - return dyn.NewValue(tok, []dyn.Location{location}), nil + return dyn.NewValue(tok, []diag.Location{location}), nil } return invalidValueWithLocation(decoder, o), fmt.Errorf("unexpected token: %v", token) @@ -129,5 +130,5 @@ func decodeValue(decoder *json.Decoder, o *Offset) (dyn.Value, error) { func invalidValueWithLocation(decoder *json.Decoder, o *Offset) dyn.Value { location := o.GetPosition(decoder.InputOffset()) - return dyn.InvalidValue.WithLocations([]dyn.Location{location}) + return dyn.InvalidValue.WithLocations([]diag.Location{location}) } diff --git a/libs/dyn/jsonloader/locations.go b/libs/dyn/jsonloader/locations.go index d69c3c5c861..3dbe2da6630 100644 --- a/libs/dyn/jsonloader/locations.go +++ b/libs/dyn/jsonloader/locations.go @@ -3,7 +3,7 @@ package jsonloader import ( "sort" - "github.com/databricks/cli/libs/dyn" + "github.com/databricks/cli/libs/diag" ) type LineOffset struct { @@ -30,14 +30,14 @@ func BuildLineOffsets(data []byte) Offset { } // GetPosition maps a byte offset to its corresponding line and column numbers. -func (o Offset) GetPosition(offset int64) dyn.Location { +func (o Offset) GetPosition(offset int64) diag.Location { // Binary search to find the line idx := max(sort.Search(len(o.offsets), func(i int) bool { return o.offsets[i].Start > offset })-1, 0) lineOffset := o.offsets[idx] - return dyn.Location{ + return diag.Location{ File: o.source, Line: lineOffset.Line, Column: int(offset-lineOffset.Start) + 1, diff --git a/libs/dyn/mapping.go b/libs/dyn/mapping.go index e7e1bbbc670..8b29181e40f 100644 --- a/libs/dyn/mapping.go +++ b/libs/dyn/mapping.go @@ -3,6 +3,8 @@ package dyn import ( "maps" "slices" + + "github.com/databricks/cli/libs/diag" ) // Pair represents a single key-value pair in a Mapping. @@ -107,7 +109,7 @@ func (m *Mapping) GetByString(skey string) (Value, bool) { // Set sets the value for the given key in the mapping. // If the key already exists, the value is updated. The location loc is ignored. // If the key does not exist, a new key-value pair is added. -func (m *Mapping) SetLoc(skey string, loc []Location, value Value) { +func (m *Mapping) SetLoc(skey string, loc []diag.Location, value Value) { // If the key already exists, update the value. if i, ok := m.index[skey]; ok { m.pairs[i].Value = value diff --git a/libs/dyn/merge/elements_by_key_test.go b/libs/dyn/merge/elements_by_key_test.go index 1cc873636f9..2aa19306820 100644 --- a/libs/dyn/merge/elements_by_key_test.go +++ b/libs/dyn/merge/elements_by_key_test.go @@ -4,6 +4,7 @@ import ( "strings" "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -50,10 +51,10 @@ func TestElementByKey(t *testing.T) { } func TestElementByKeyPreservesLocations(t *testing.T) { - loc := dyn.Location{File: "config.yml", Line: 10, Column: 5} + loc := diag.Location{File: "config.yml", Line: 10, Column: 5} vin := dyn.V([]dyn.Value{ dyn.V(map[string]dyn.Value{ - "key": dyn.NewValue("foo", []dyn.Location{loc}), + "key": dyn.NewValue("foo", []diag.Location{loc}), "value": dyn.V(42), }), }) diff --git a/libs/dyn/merge/merge_test.go b/libs/dyn/merge/merge_test.go index 43e0e08c182..9545c752258 100644 --- a/libs/dyn/merge/merge_test.go +++ b/libs/dyn/merge/merge_test.go @@ -3,22 +3,23 @@ package merge import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" ) func TestMergeMaps(t *testing.T) { - l1 := dyn.Location{File: "file1", Line: 1, Column: 2} + l1 := diag.Location{File: "file1", Line: 1, Column: 2} v1 := dyn.NewValue(map[string]dyn.Value{ - "foo": dyn.NewValue("bar", []dyn.Location{l1}), - "bar": dyn.NewValue("baz", []dyn.Location{l1}), - }, []dyn.Location{l1}) + "foo": dyn.NewValue("bar", []diag.Location{l1}), + "bar": dyn.NewValue("baz", []diag.Location{l1}), + }, []diag.Location{l1}) - l2 := dyn.Location{File: "file2", Line: 3, Column: 4} + l2 := diag.Location{File: "file2", Line: 3, Column: 4} v2 := dyn.NewValue(map[string]dyn.Value{ - "bar": dyn.NewValue("qux", []dyn.Location{l2}), - "qux": dyn.NewValue("foo", []dyn.Location{l2}), - }, []dyn.Location{l2}) + "bar": dyn.NewValue("qux", []diag.Location{l2}), + "qux": dyn.NewValue("foo", []diag.Location{l2}), + }, []diag.Location{l2}) // Merge v2 into v1. { @@ -31,10 +32,10 @@ func TestMergeMaps(t *testing.T) { }, out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l1, l2}, out.Locations()) - assert.Equal(t, []dyn.Location{l2, l1}, out.Get("bar").Locations()) - assert.Equal(t, []dyn.Location{l1}, out.Get("foo").Locations()) - assert.Equal(t, []dyn.Location{l2}, out.Get("qux").Locations()) + assert.Equal(t, []diag.Location{l1, l2}, out.Locations()) + assert.Equal(t, []diag.Location{l2, l1}, out.Get("bar").Locations()) + assert.Equal(t, []diag.Location{l1}, out.Get("foo").Locations()) + assert.Equal(t, []diag.Location{l2}, out.Get("qux").Locations()) // Location of the merged value should be the location of v1. assert.Equal(t, l1, out.Location()) @@ -59,10 +60,10 @@ func TestMergeMaps(t *testing.T) { }, out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l2, l1}, out.Locations()) - assert.Equal(t, []dyn.Location{l1, l2}, out.Get("bar").Locations()) - assert.Equal(t, []dyn.Location{l1}, out.Get("foo").Locations()) - assert.Equal(t, []dyn.Location{l2}, out.Get("qux").Locations()) + assert.Equal(t, []diag.Location{l2, l1}, out.Locations()) + assert.Equal(t, []diag.Location{l1, l2}, out.Get("bar").Locations()) + assert.Equal(t, []diag.Location{l1}, out.Get("foo").Locations()) + assert.Equal(t, []diag.Location{l2}, out.Get("qux").Locations()) // Location of the merged value should be the location of v2. assert.Equal(t, l2, out.Location()) @@ -78,13 +79,13 @@ func TestMergeMaps(t *testing.T) { } func TestMergeMapsNil(t *testing.T) { - l := dyn.Location{File: "file", Line: 1, Column: 2} + l := diag.Location{File: "file", Line: 1, Column: 2} v := dyn.NewValue(map[string]dyn.Value{ "foo": dyn.V("bar"), - }, []dyn.Location{l}) + }, []diag.Location{l}) - nilL := dyn.Location{File: "file", Line: 3, Column: 4} - nilV := dyn.NewValue(nil, []dyn.Location{nilL}) + nilL := diag.Location{File: "file", Line: 3, Column: 4} + nilV := dyn.NewValue(nil, []diag.Location{nilL}) // Merge nil into v. { @@ -95,7 +96,7 @@ func TestMergeMapsNil(t *testing.T) { }, out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l, nilL}, out.Locations()) + assert.Equal(t, []diag.Location{l, nilL}, out.Locations()) // Location of the non-nil value should be returned by .Location(). assert.Equal(t, l, out.Location()) @@ -110,7 +111,7 @@ func TestMergeMapsNil(t *testing.T) { }, out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l, nilL}, out.Locations()) + assert.Equal(t, []diag.Location{l, nilL}, out.Locations()) // Location of the non-nil value should be returned by .Location(). assert.Equal(t, l, out.Location()) @@ -133,18 +134,18 @@ func TestMergeMapsError(t *testing.T) { } func TestMergeSequences(t *testing.T) { - l1 := dyn.Location{File: "file1", Line: 1, Column: 2} + l1 := diag.Location{File: "file1", Line: 1, Column: 2} v1 := dyn.NewValue([]dyn.Value{ - dyn.NewValue("bar", []dyn.Location{l1}), - dyn.NewValue("baz", []dyn.Location{l1}), - }, []dyn.Location{l1}) + dyn.NewValue("bar", []diag.Location{l1}), + dyn.NewValue("baz", []diag.Location{l1}), + }, []diag.Location{l1}) - l2 := dyn.Location{File: "file2", Line: 3, Column: 4} - l3 := dyn.Location{File: "file3", Line: 5, Column: 6} + l2 := diag.Location{File: "file2", Line: 3, Column: 4} + l3 := diag.Location{File: "file3", Line: 5, Column: 6} v2 := dyn.NewValue([]dyn.Value{ - dyn.NewValue("qux", []dyn.Location{l2}), - dyn.NewValue("foo", []dyn.Location{l3}), - }, []dyn.Location{l2, l3}) + dyn.NewValue("qux", []diag.Location{l2}), + dyn.NewValue("foo", []diag.Location{l3}), + }, []diag.Location{l2, l3}) // Merge v2 into v1. { @@ -158,7 +159,7 @@ func TestMergeSequences(t *testing.T) { }, out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l1, l2, l3}, out.Locations()) + assert.Equal(t, []diag.Location{l1, l2, l3}, out.Locations()) // Location of the merged value should be the location of v1. assert.Equal(t, l1, out.Location()) @@ -182,7 +183,7 @@ func TestMergeSequences(t *testing.T) { }, out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l2, l3, l1}, out.Locations()) + assert.Equal(t, []diag.Location{l2, l3, l1}, out.Locations()) // Location of the merged value should be the location of v2. assert.Equal(t, l2, out.Location()) @@ -235,10 +236,10 @@ func TestMergeSequencesError(t *testing.T) { } func TestMergePrimitives(t *testing.T) { - l1 := dyn.Location{File: "file1", Line: 1, Column: 2} - l2 := dyn.Location{File: "file2", Line: 3, Column: 4} - v1 := dyn.NewValue("bar", []dyn.Location{l1}) - v2 := dyn.NewValue("baz", []dyn.Location{l2}) + l1 := diag.Location{File: "file1", Line: 1, Column: 2} + l2 := diag.Location{File: "file2", Line: 3, Column: 4} + v1 := dyn.NewValue("bar", []diag.Location{l1}) + v2 := dyn.NewValue("baz", []diag.Location{l2}) // Merge v2 into v1. { @@ -247,7 +248,7 @@ func TestMergePrimitives(t *testing.T) { assert.Equal(t, "baz", out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l2, l1}, out.Locations()) + assert.Equal(t, []diag.Location{l2, l1}, out.Locations()) // Location of the merged value should be the location of v2, the second value. assert.Equal(t, l2, out.Location()) @@ -260,7 +261,7 @@ func TestMergePrimitives(t *testing.T) { assert.Equal(t, "bar", out.AsAny()) // Locations of both values should be preserved. - assert.Equal(t, []dyn.Location{l1, l2}, out.Locations()) + assert.Equal(t, []diag.Location{l1, l2}, out.Locations()) // Location of the merged value should be the location of v1, the second value. assert.Equal(t, l1, out.Location()) diff --git a/libs/dyn/merge/override_test.go b/libs/dyn/merge/override_test.go index adc565fec05..17602f57ad7 100644 --- a/libs/dyn/merge/override_test.go +++ b/libs/dyn/merge/override_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/dynassert" "github.com/stretchr/testify/assert" @@ -20,86 +21,86 @@ type overrideTestCase struct { } func TestOverride_Primitive(t *testing.T) { - leftLocation := dyn.Location{File: "left.yml", Line: 1, Column: 1} - rightLocation := dyn.Location{File: "right.yml", Line: 1, Column: 1} + leftLocation := diag.Location{File: "left.yml", Line: 1, Column: 1} + rightLocation := diag.Location{File: "right.yml", Line: 1, Column: 1} modifiedTestCases := []overrideTestCase{ { name: "string (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue("a", []dyn.Location{leftLocation}), - right: dyn.NewValue("b", []dyn.Location{rightLocation}), - expected: dyn.NewValue("b", []dyn.Location{rightLocation}), + left: dyn.NewValue("a", []diag.Location{leftLocation}), + right: dyn.NewValue("b", []diag.Location{rightLocation}), + expected: dyn.NewValue("b", []diag.Location{rightLocation}), }, { name: "string (not updated)", state: visitorState{}, - left: dyn.NewValue("a", []dyn.Location{leftLocation}), - right: dyn.NewValue("a", []dyn.Location{rightLocation}), - expected: dyn.NewValue("a", []dyn.Location{leftLocation}), + left: dyn.NewValue("a", []diag.Location{leftLocation}), + right: dyn.NewValue("a", []diag.Location{rightLocation}), + expected: dyn.NewValue("a", []diag.Location{leftLocation}), }, { name: "bool (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue(true, []dyn.Location{leftLocation}), - right: dyn.NewValue(false, []dyn.Location{rightLocation}), - expected: dyn.NewValue(false, []dyn.Location{rightLocation}), + left: dyn.NewValue(true, []diag.Location{leftLocation}), + right: dyn.NewValue(false, []diag.Location{rightLocation}), + expected: dyn.NewValue(false, []diag.Location{rightLocation}), }, { name: "bool (not updated)", state: visitorState{}, - left: dyn.NewValue(true, []dyn.Location{leftLocation}), - right: dyn.NewValue(true, []dyn.Location{rightLocation}), - expected: dyn.NewValue(true, []dyn.Location{leftLocation}), + left: dyn.NewValue(true, []diag.Location{leftLocation}), + right: dyn.NewValue(true, []diag.Location{rightLocation}), + expected: dyn.NewValue(true, []diag.Location{leftLocation}), }, { name: "int (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue(1, []dyn.Location{leftLocation}), - right: dyn.NewValue(2, []dyn.Location{rightLocation}), - expected: dyn.NewValue(2, []dyn.Location{rightLocation}), + left: dyn.NewValue(1, []diag.Location{leftLocation}), + right: dyn.NewValue(2, []diag.Location{rightLocation}), + expected: dyn.NewValue(2, []diag.Location{rightLocation}), }, { name: "int (not updated)", state: visitorState{}, - left: dyn.NewValue(int32(1), []dyn.Location{leftLocation}), - right: dyn.NewValue(int64(1), []dyn.Location{rightLocation}), - expected: dyn.NewValue(int32(1), []dyn.Location{leftLocation}), + left: dyn.NewValue(int32(1), []diag.Location{leftLocation}), + right: dyn.NewValue(int64(1), []diag.Location{rightLocation}), + expected: dyn.NewValue(int32(1), []diag.Location{leftLocation}), }, { name: "float (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue(1.0, []dyn.Location{leftLocation}), - right: dyn.NewValue(2.0, []dyn.Location{rightLocation}), - expected: dyn.NewValue(2.0, []dyn.Location{rightLocation}), + left: dyn.NewValue(1.0, []diag.Location{leftLocation}), + right: dyn.NewValue(2.0, []diag.Location{rightLocation}), + expected: dyn.NewValue(2.0, []diag.Location{rightLocation}), }, { name: "float (not updated)", state: visitorState{}, - left: dyn.NewValue(float32(1.0), []dyn.Location{leftLocation}), - right: dyn.NewValue(float64(1.0), []dyn.Location{rightLocation}), - expected: dyn.NewValue(float32(1.0), []dyn.Location{leftLocation}), + left: dyn.NewValue(float32(1.0), []diag.Location{leftLocation}), + right: dyn.NewValue(float64(1.0), []diag.Location{rightLocation}), + expected: dyn.NewValue(float32(1.0), []diag.Location{leftLocation}), }, { name: "time (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []dyn.Location{leftLocation}), - right: dyn.NewValue(dyn.FromTime(time.UnixMilli(10001)), []dyn.Location{rightLocation}), - expected: dyn.NewValue(dyn.FromTime(time.UnixMilli(10001)), []dyn.Location{rightLocation}), + left: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []diag.Location{leftLocation}), + right: dyn.NewValue(dyn.FromTime(time.UnixMilli(10001)), []diag.Location{rightLocation}), + expected: dyn.NewValue(dyn.FromTime(time.UnixMilli(10001)), []diag.Location{rightLocation}), }, { name: "time (not updated)", state: visitorState{}, - left: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []dyn.Location{leftLocation}), - right: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []dyn.Location{rightLocation}), - expected: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []dyn.Location{leftLocation}), + left: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []diag.Location{leftLocation}), + right: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []diag.Location{rightLocation}), + expected: dyn.NewValue(dyn.FromTime(time.UnixMilli(10000)), []diag.Location{leftLocation}), }, { name: "different types (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue("a", []dyn.Location{leftLocation}), - right: dyn.NewValue(42, []dyn.Location{rightLocation}), - expected: dyn.NewValue(42, []dyn.Location{rightLocation}), + left: dyn.NewValue("a", []diag.Location{leftLocation}), + right: dyn.NewValue(42, []diag.Location{rightLocation}), + expected: dyn.NewValue(42, []diag.Location{rightLocation}), }, { name: "map - remove 'a', update 'b'", @@ -109,22 +110,22 @@ func TestOverride_Primitive(t *testing.T) { }, left: dyn.NewValue( map[string]dyn.Value{ - "a": dyn.NewValue(42, []dyn.Location{leftLocation}), - "b": dyn.NewValue(10, []dyn.Location{leftLocation}), + "a": dyn.NewValue(42, []diag.Location{leftLocation}), + "b": dyn.NewValue(10, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}), + []diag.Location{leftLocation}), right: dyn.NewValue( map[string]dyn.Value{ - "b": dyn.NewValue(20, []dyn.Location{rightLocation}), + "b": dyn.NewValue(20, []diag.Location{rightLocation}), }, - []dyn.Location{rightLocation}), + []diag.Location{rightLocation}), expected: dyn.NewValue( map[string]dyn.Value{ - "b": dyn.NewValue(20, []dyn.Location{rightLocation}), + "b": dyn.NewValue(20, []diag.Location{rightLocation}), }, - []dyn.Location{leftLocation}), + []diag.Location{leftLocation}), }, { name: "map - add 'a'", @@ -133,26 +134,26 @@ func TestOverride_Primitive(t *testing.T) { }, left: dyn.NewValue( map[string]dyn.Value{ - "b": dyn.NewValue(10, []dyn.Location{leftLocation}), + "b": dyn.NewValue(10, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( map[string]dyn.Value{ - "a": dyn.NewValue(42, []dyn.Location{rightLocation}), - "b": dyn.NewValue(10, []dyn.Location{rightLocation}), + "a": dyn.NewValue(42, []diag.Location{rightLocation}), + "b": dyn.NewValue(10, []diag.Location{rightLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), expected: dyn.NewValue( map[string]dyn.Value{ - "a": dyn.NewValue(42, []dyn.Location{rightLocation}), + "a": dyn.NewValue(42, []diag.Location{rightLocation}), // location hasn't changed because value hasn't changed - "b": dyn.NewValue(10, []dyn.Location{leftLocation}), + "b": dyn.NewValue(10, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, { @@ -162,25 +163,25 @@ func TestOverride_Primitive(t *testing.T) { }, left: dyn.NewValue( map[string]dyn.Value{ - "a": dyn.NewValue(42, []dyn.Location{leftLocation}), - "b": dyn.NewValue(10, []dyn.Location{leftLocation}), + "a": dyn.NewValue(42, []diag.Location{leftLocation}), + "b": dyn.NewValue(10, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( map[string]dyn.Value{ - "b": dyn.NewValue(10, []dyn.Location{rightLocation}), + "b": dyn.NewValue(10, []diag.Location{rightLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), expected: dyn.NewValue( map[string]dyn.Value{ // location hasn't changed because value hasn't changed - "b": dyn.NewValue(10, []dyn.Location{leftLocation}), + "b": dyn.NewValue(10, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, { @@ -192,38 +193,38 @@ func TestOverride_Primitive(t *testing.T) { map[string]dyn.Value{ "jobs": dyn.NewValue( map[string]dyn.Value{ - "job_0": dyn.NewValue(42, []dyn.Location{leftLocation}), + "job_0": dyn.NewValue(42, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( map[string]dyn.Value{ "jobs": dyn.NewValue( map[string]dyn.Value{ - "job_0": dyn.NewValue(42, []dyn.Location{rightLocation}), - "job_1": dyn.NewValue(1337, []dyn.Location{rightLocation}), + "job_0": dyn.NewValue(42, []diag.Location{rightLocation}), + "job_1": dyn.NewValue(1337, []diag.Location{rightLocation}), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), expected: dyn.NewValue( map[string]dyn.Value{ "jobs": dyn.NewValue( map[string]dyn.Value{ - "job_0": dyn.NewValue(42, []dyn.Location{leftLocation}), - "job_1": dyn.NewValue(1337, []dyn.Location{rightLocation}), + "job_0": dyn.NewValue(42, []diag.Location{leftLocation}), + "job_1": dyn.NewValue(1337, []diag.Location{rightLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, { @@ -233,35 +234,35 @@ func TestOverride_Primitive(t *testing.T) { map[string]dyn.Value{ "jobs": dyn.NewValue( map[string]dyn.Value{ - "job_0": dyn.NewValue(42, []dyn.Location{leftLocation}), - "job_1": dyn.NewValue(1337, []dyn.Location{rightLocation}), + "job_0": dyn.NewValue(42, []diag.Location{leftLocation}), + "job_1": dyn.NewValue(1337, []diag.Location{rightLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( map[string]dyn.Value{ "jobs": dyn.NewValue( map[string]dyn.Value{ - "job_0": dyn.NewValue(42, []dyn.Location{rightLocation}), + "job_0": dyn.NewValue(42, []diag.Location{rightLocation}), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), expected: dyn.NewValue( map[string]dyn.Value{ "jobs": dyn.NewValue( map[string]dyn.Value{ - "job_0": dyn.NewValue(42, []dyn.Location{leftLocation}), + "job_0": dyn.NewValue(42, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, { @@ -269,23 +270,23 @@ func TestOverride_Primitive(t *testing.T) { state: visitorState{added: []string{"root[1]"}}, left: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{leftLocation}), + dyn.NewValue(42, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{rightLocation}), - dyn.NewValue(10, []dyn.Location{rightLocation}), + dyn.NewValue(42, []diag.Location{rightLocation}), + dyn.NewValue(10, []diag.Location{rightLocation}), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), expected: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{leftLocation}), - dyn.NewValue(10, []dyn.Location{rightLocation}), + dyn.NewValue(42, []diag.Location{leftLocation}), + dyn.NewValue(10, []diag.Location{rightLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, { @@ -293,22 +294,22 @@ func TestOverride_Primitive(t *testing.T) { state: visitorState{removed: []string{"root[1]"}}, left: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{leftLocation}), - dyn.NewValue(10, []dyn.Location{leftLocation}), + dyn.NewValue(42, []diag.Location{leftLocation}), + dyn.NewValue(10, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{rightLocation}), + dyn.NewValue(42, []diag.Location{rightLocation}), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), expected: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{leftLocation}), + dyn.NewValue(42, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), // location hasn't changed because value hasn't changed }, @@ -317,43 +318,43 @@ func TestOverride_Primitive(t *testing.T) { state: visitorState{}, left: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{leftLocation}), + dyn.NewValue(42, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), right: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{rightLocation}), + dyn.NewValue(42, []diag.Location{rightLocation}), }, - []dyn.Location{rightLocation}, + []diag.Location{rightLocation}, ), expected: dyn.NewValue( []dyn.Value{ - dyn.NewValue(42, []dyn.Location{leftLocation}), + dyn.NewValue(42, []diag.Location{leftLocation}), }, - []dyn.Location{leftLocation}, + []diag.Location{leftLocation}, ), }, { name: "nil (not updated)", state: visitorState{}, - left: dyn.NilValue.WithLocations([]dyn.Location{leftLocation}), - right: dyn.NilValue.WithLocations([]dyn.Location{rightLocation}), - expected: dyn.NilValue.WithLocations([]dyn.Location{leftLocation}), + left: dyn.NilValue.WithLocations([]diag.Location{leftLocation}), + right: dyn.NilValue.WithLocations([]diag.Location{rightLocation}), + expected: dyn.NilValue.WithLocations([]diag.Location{leftLocation}), }, { name: "nil (updated)", state: visitorState{updated: []string{"root"}}, left: dyn.NilValue, - right: dyn.NewValue(42, []dyn.Location{rightLocation}), - expected: dyn.NewValue(42, []dyn.Location{rightLocation}), + right: dyn.NewValue(42, []diag.Location{rightLocation}), + expected: dyn.NewValue(42, []diag.Location{rightLocation}), }, { name: "change kind (updated)", state: visitorState{updated: []string{"root"}}, - left: dyn.NewValue(42.0, []dyn.Location{leftLocation}), - right: dyn.NewValue(42, []dyn.Location{rightLocation}), - expected: dyn.NewValue(42, []dyn.Location{rightLocation}), + left: dyn.NewValue(42.0, []diag.Location{leftLocation}), + right: dyn.NewValue(42, []diag.Location{rightLocation}), + expected: dyn.NewValue(42, []diag.Location{rightLocation}), }, } @@ -423,26 +424,26 @@ func TestOverride_Primitive(t *testing.T) { } func TestOverride_PreserveMappingKeys(t *testing.T) { - leftLocation := dyn.Location{File: "left.yml", Line: 1, Column: 1} - leftKeyLocation := dyn.Location{File: "left.yml", Line: 2, Column: 1} - leftValueLocation := dyn.Location{File: "left.yml", Line: 3, Column: 1} + leftLocation := diag.Location{File: "left.yml", Line: 1, Column: 1} + leftKeyLocation := diag.Location{File: "left.yml", Line: 2, Column: 1} + leftValueLocation := diag.Location{File: "left.yml", Line: 3, Column: 1} - rightLocation := dyn.Location{File: "right.yml", Line: 1, Column: 1} - rightKeyLocation := dyn.Location{File: "right.yml", Line: 2, Column: 1} - rightValueLocation := dyn.Location{File: "right.yml", Line: 3, Column: 1} + rightLocation := diag.Location{File: "right.yml", Line: 1, Column: 1} + rightKeyLocation := diag.Location{File: "right.yml", Line: 2, Column: 1} + rightValueLocation := diag.Location{File: "right.yml", Line: 3, Column: 1} left := dyn.NewMapping() - left.SetLoc("a", []dyn.Location{leftKeyLocation}, dyn.NewValue(42, []dyn.Location{leftValueLocation})) + left.SetLoc("a", []diag.Location{leftKeyLocation}, dyn.NewValue(42, []diag.Location{leftValueLocation})) right := dyn.NewMapping() - right.SetLoc("a", []dyn.Location{rightKeyLocation}, dyn.NewValue(7, []dyn.Location{rightValueLocation})) + right.SetLoc("a", []diag.Location{rightKeyLocation}, dyn.NewValue(7, []diag.Location{rightValueLocation})) state, visitor := createVisitor(visitorOpts{}) out, err := override( dyn.EmptyPath, - dyn.NewValue(left, []dyn.Location{leftLocation}), - dyn.NewValue(right, []dyn.Location{rightLocation}), + dyn.NewValue(left, []diag.Location{leftLocation}), + dyn.NewValue(right, []diag.Location{rightLocation}), visitor, ) diff --git a/libs/dyn/merge/select_test.go b/libs/dyn/merge/select_test.go index f9f010fb9db..c621f226849 100644 --- a/libs/dyn/merge/select_test.go +++ b/libs/dyn/merge/select_test.go @@ -3,12 +3,13 @@ package merge import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" ) func TestSelect(t *testing.T) { - locations := []dyn.Location{{File: "foo.yml", Line: 1, Column: 1}} + locations := []diag.Location{{File: "foo.yml", Line: 1, Column: 1}} included := []string{"foo"} input := dyn.NewValue( map[string]dyn.Value{ @@ -31,7 +32,7 @@ func TestSelect(t *testing.T) { } func TestAntiSelect(t *testing.T) { - locations := []dyn.Location{{File: "foo.yml", Line: 1, Column: 1}} + locations := []diag.Location{{File: "foo.yml", Line: 1, Column: 1}} excluded := []string{"foo"} input := dyn.NewValue( map[string]dyn.Value{ diff --git a/libs/dyn/value.go b/libs/dyn/value.go index 72803511b80..8cbd9b801ea 100644 --- a/libs/dyn/value.go +++ b/libs/dyn/value.go @@ -4,6 +4,8 @@ import ( "fmt" "reflect" "slices" + + "github.com/databricks/cli/libs/diag" ) type Value struct { @@ -14,7 +16,7 @@ type Value struct { // List of locations this value is defined at. The first location in the slice // is the location returned by the `.Location()` method and is typically used // for reporting errors and warnings associated with the value. - l []Location + l []diag.Location // Whether or not this value is an anchor. // If this node doesn't map to a type, we don't need to warn about it. @@ -37,7 +39,7 @@ func V(v any) Value { } // NewValue constructs a new Value with the given value and location. -func NewValue(v any, loc []Location) Value { +func NewValue(v any, loc []diag.Location) Value { switch vin := v.(type) { case map[string]Value: v = newMappingFromGoMap(vin) @@ -54,7 +56,7 @@ func NewValue(v any, loc []Location) Value { } // WithLocations returns a new Value with its location set to the given value. -func (v Value) WithLocations(loc []Location) Value { +func (v Value) WithLocations(loc []diag.Location) Value { return Value{ v: v.v, k: v.k, @@ -81,13 +83,13 @@ func (v Value) Value() any { return v.v } -func (v Value) Locations() []Location { +func (v Value) Locations() []diag.Location { return v.l } -func (v Value) Location() Location { +func (v Value) Location() diag.Location { if len(v.l) == 0 { - return Location{} + return diag.Location{} } return v.l[0] diff --git a/libs/dyn/value_eq_test.go b/libs/dyn/value_eq_test.go index 83c255edd54..22fe2df0080 100644 --- a/libs/dyn/value_eq_test.go +++ b/libs/dyn/value_eq_test.go @@ -3,12 +3,13 @@ package dyn import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestValueEqMap(t *testing.T) { - loc := []Location{{File: "file", Line: 1, Column: 2}} + loc := []diag.Location{{File: "file", Line: 1, Column: 2}} v := NewValue(map[string]Value{"key": V("value")}, loc) tests := []struct { @@ -37,7 +38,7 @@ func TestValueEqMap(t *testing.T) { { name: "different locations", a: v, - b: v.WithLocations([]Location{{File: "other", Line: 1, Column: 2}}), + b: v.WithLocations([]diag.Location{{File: "other", Line: 1, Column: 2}}), want: false, }, { diff --git a/libs/dyn/value_test.go b/libs/dyn/value_test.go index 8717aae620e..667e2cbdd59 100644 --- a/libs/dyn/value_test.go +++ b/libs/dyn/value_test.go @@ -3,6 +3,7 @@ package dyn_test import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" ) @@ -33,9 +34,9 @@ func TestValueAsMap(t *testing.T) { map[string]dyn.Value{ "key": dyn.NewValue( "value", - []dyn.Location{{File: "file", Line: 1, Column: 2}}), + []diag.Location{{File: "file", Line: 1, Column: 2}}), }, - []dyn.Location{{File: "file", Line: 1, Column: 2}}, + []diag.Location{{File: "file", Line: 1, Column: 2}}, ) m, ok := mapValue.AsMap() diff --git a/libs/dyn/value_underlying_test.go b/libs/dyn/value_underlying_test.go index 7f9f9184b92..189a49a0ea3 100644 --- a/libs/dyn/value_underlying_test.go +++ b/libs/dyn/value_underlying_test.go @@ -4,6 +4,7 @@ import ( "testing" "time" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" ) @@ -11,7 +12,7 @@ import ( func TestValueUnderlyingMap(t *testing.T) { v := dyn.V( map[string]dyn.Value{ - "key": dyn.NewValue("value", []dyn.Location{{File: "file", Line: 1, Column: 2}}), + "key": dyn.NewValue("value", []diag.Location{{File: "file", Line: 1, Column: 2}}), }, ) @@ -33,7 +34,7 @@ func TestValueUnderlyingMap(t *testing.T) { func TestValueUnderlyingSequence(t *testing.T) { v := dyn.V( []dyn.Value{ - dyn.NewValue("value", []dyn.Location{{File: "file", Line: 1, Column: 2}}), + dyn.NewValue("value", []diag.Location{{File: "file", Line: 1, Column: 2}}), }, ) diff --git a/libs/dyn/yamlloader/loader.go b/libs/dyn/yamlloader/loader.go index 0f69f0c638b..aebbf0883e9 100644 --- a/libs/dyn/yamlloader/loader.go +++ b/libs/dyn/yamlloader/loader.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "go.yaml.in/yaml/v3" ) @@ -13,7 +14,7 @@ import ( // LocationError is an error with a YAML source location that can be displayed // to the user with a file path, line, and column number. type LocationError struct { - Loc dyn.Location + Loc diag.Location Summary string } @@ -30,7 +31,7 @@ type loader struct { activeAliases map[*yaml.Node]bool } -func errorf(loc dyn.Location, format string, args ...any) error { +func errorf(loc diag.Location, format string, args ...any) error { return fmt.Errorf("yaml (%s): %s", loc, fmt.Sprintf(format, args...)) } @@ -41,8 +42,8 @@ func newLoader(path string) *loader { } } -func (d *loader) location(node *yaml.Node) dyn.Location { - return dyn.Location{ +func (d *loader) location(node *yaml.Node) diag.Location { + return diag.Location{ File: d.path, Line: node.Line, Column: node.Column, @@ -50,7 +51,7 @@ func (d *loader) location(node *yaml.Node) dyn.Location { } func (d *loader) load(node *yaml.Node) (dyn.Value, error) { - loc := dyn.Location{ + loc := diag.Location{ File: d.path, Line: node.Line, Column: node.Column, @@ -87,11 +88,11 @@ func (d *loader) load(node *yaml.Node) (dyn.Value, error) { return value, nil } -func (d *loader) loadDocument(node *yaml.Node, loc dyn.Location) (dyn.Value, error) { +func (d *loader) loadDocument(node *yaml.Node, loc diag.Location) (dyn.Value, error) { return d.load(node.Content[0]) } -func (d *loader) loadSequence(node *yaml.Node, loc dyn.Location) (dyn.Value, error) { +func (d *loader) loadSequence(node *yaml.Node, loc diag.Location) (dyn.Value, error) { acc := make([]dyn.Value, len(node.Content)) for i, n := range node.Content { v, err := d.load(n) @@ -102,10 +103,10 @@ func (d *loader) loadSequence(node *yaml.Node, loc dyn.Location) (dyn.Value, err acc[i] = v } - return dyn.NewValue(acc, []dyn.Location{loc}), nil + return dyn.NewValue(acc, []diag.Location{loc}), nil } -func (d *loader) loadMapping(node *yaml.Node, loc dyn.Location) (dyn.Value, error) { +func (d *loader) loadMapping(node *yaml.Node, loc diag.Location) (dyn.Value, error) { var merge *yaml.Node acc := dyn.NewMapping() @@ -140,7 +141,7 @@ func (d *loader) loadMapping(node *yaml.Node, loc dyn.Location) (dyn.Value, erro return dyn.InvalidValue, errorf(loc, "invalid key tag: %v", st) } - loc := []dyn.Location{{ + loc := []diag.Location{{ File: d.path, Line: key.Line, Column: key.Column, @@ -155,7 +156,7 @@ func (d *loader) loadMapping(node *yaml.Node, loc dyn.Location) (dyn.Value, erro } if merge == nil { - return dyn.NewValue(acc, []dyn.Location{loc}), nil + return dyn.NewValue(acc, []diag.Location{loc}), nil } // Build location for the merge node. @@ -196,28 +197,28 @@ func (d *loader) loadMapping(node *yaml.Node, loc dyn.Location) (dyn.Value, erro out.Merge(m) } - return dyn.NewValue(out, []dyn.Location{loc}), nil + return dyn.NewValue(out, []diag.Location{loc}), nil } -func newIntValue(i64 int64, loc dyn.Location) dyn.Value { +func newIntValue(i64 int64, loc diag.Location) dyn.Value { // Use regular int type instead of int64 if possible. if i64 >= math.MinInt32 && i64 <= math.MaxInt32 { - return dyn.NewValue(int(i64), []dyn.Location{loc}) + return dyn.NewValue(int(i64), []diag.Location{loc}) } - return dyn.NewValue(i64, []dyn.Location{loc}) + return dyn.NewValue(i64, []diag.Location{loc}) } -func (d *loader) loadScalar(node *yaml.Node, loc dyn.Location) (dyn.Value, error) { +func (d *loader) loadScalar(node *yaml.Node, loc diag.Location) (dyn.Value, error) { st := node.ShortTag() switch st { case "!!str": - return dyn.NewValue(node.Value, []dyn.Location{loc}), nil + return dyn.NewValue(node.Value, []diag.Location{loc}), nil case "!!bool": switch strings.ToLower(node.Value) { case "true": - return dyn.NewValue(true, []dyn.Location{loc}), nil + return dyn.NewValue(true, []diag.Location{loc}), nil case "false": - return dyn.NewValue(false, []dyn.Location{loc}), nil + return dyn.NewValue(false, []diag.Location{loc}), nil default: return dyn.InvalidValue, errorf(loc, "invalid bool value: %v", node.Value) } @@ -255,20 +256,20 @@ func (d *loader) loadScalar(node *yaml.Node, loc dyn.Location) (dyn.Value, error // Deal with infinity and NaN values. switch v { case ".inf": - return dyn.NewValue(f64, []dyn.Location{loc}), nil + return dyn.NewValue(f64, []diag.Location{loc}), nil case ".nan": - return dyn.NewValue(math.NaN(), []dyn.Location{loc}), nil + return dyn.NewValue(math.NaN(), []diag.Location{loc}), nil } return dyn.InvalidValue, errorf(loc, "invalid float value: %v", node.Value) } - return dyn.NewValue(f64, []dyn.Location{loc}), nil + return dyn.NewValue(f64, []diag.Location{loc}), nil case "!!null": - return dyn.NewValue(nil, []dyn.Location{loc}), nil + return dyn.NewValue(nil, []diag.Location{loc}), nil case "!!timestamp": t, err := dyn.NewTime(node.Value) if err == nil { - return dyn.NewValue(t, []dyn.Location{loc}), nil + return dyn.NewValue(t, []diag.Location{loc}), nil } return dyn.InvalidValue, errorf(loc, "invalid timestamp value: %v", node.Value) default: @@ -276,7 +277,7 @@ func (d *loader) loadScalar(node *yaml.Node, loc dyn.Location) (dyn.Value, error } } -func (d *loader) loadAlias(node *yaml.Node, loc dyn.Location) (dyn.Value, error) { +func (d *loader) loadAlias(node *yaml.Node, loc diag.Location) (dyn.Value, error) { if d.activeAliases[node] { return dyn.InvalidValue, errorf(loc, "cyclic reference to anchor %q", node.Value) } diff --git a/libs/dyn/yamlloader/yaml_anchor_test.go b/libs/dyn/yamlloader/yaml_anchor_test.go index 53cd6945f93..00f4576a3e2 100644 --- a/libs/dyn/yamlloader/yaml_anchor_test.go +++ b/libs/dyn/yamlloader/yaml_anchor_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/yamlloader" "github.com/stretchr/testify/assert" @@ -22,7 +23,7 @@ func TestYAMLAnchor01(t *testing.T) { pattern := self.Get("shirt1").Get("pattern") assert.Equal(t, "striped", pattern.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 8, Column: 12}, pattern.Location()) + assert.Equal(t, diag.Location{File: file, Line: 8, Column: 12}, pattern.Location()) } func TestYAMLAnchor02(t *testing.T) { @@ -32,15 +33,15 @@ func TestYAMLAnchor02(t *testing.T) { color := self.Get("shirt").Get("color") assert.Equal(t, "red", color.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 4, Column: 10}, color.Location()) + assert.Equal(t, diag.Location{File: file, Line: 4, Column: 10}, color.Location()) primary := self.Get("shirt").Get("primary") assert.Equal(t, "cotton", primary.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 8, Column: 12}, primary.Location()) + assert.Equal(t, diag.Location{File: file, Line: 8, Column: 12}, primary.Location()) pattern := self.Get("shirt").Get("pattern") assert.Equal(t, "striped", pattern.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 13, Column: 12}, pattern.Location()) + assert.Equal(t, diag.Location{File: file, Line: 13, Column: 12}, pattern.Location()) } func TestYAMLAnchor03(t *testing.T) { @@ -63,11 +64,11 @@ func TestYAMLAnchor04(t *testing.T) { p1 := self.Get("person1").Get("address").Get("city") assert.Equal(t, "San Francisco", p1.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 4, Column: 9}, p1.Location()) + assert.Equal(t, diag.Location{File: file, Line: 4, Column: 9}, p1.Location()) p2 := self.Get("person2").Get("address").Get("city") assert.Equal(t, "Los Angeles", p2.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 16, Column: 11}, p2.Location()) + assert.Equal(t, diag.Location{File: file, Line: 16, Column: 11}, p2.Location()) } func TestYAMLAnchor05(t *testing.T) { @@ -77,9 +78,9 @@ func TestYAMLAnchor05(t *testing.T) { features := self.Get("phone1").Get("features") assert.Equal(t, "wifi", features.Index(0).AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 4, Column: 5}, features.Index(0).Location()) + assert.Equal(t, diag.Location{File: file, Line: 4, Column: 5}, features.Index(0).Location()) assert.Equal(t, "bluetooth", features.Index(1).AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 5, Column: 5}, features.Index(1).Location()) + assert.Equal(t, diag.Location{File: file, Line: 5, Column: 5}, features.Index(1).Location()) } func TestYAMLAnchor06(t *testing.T) { @@ -89,7 +90,7 @@ func TestYAMLAnchor06(t *testing.T) { greeting := self.Get("greeting1") assert.Equal(t, "Hello, World!", greeting.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 2, Column: 16}, greeting.Location()) + assert.Equal(t, diag.Location{File: file, Line: 2, Column: 16}, greeting.Location()) } func TestYAMLAnchor07(t *testing.T) { @@ -99,11 +100,11 @@ func TestYAMLAnchor07(t *testing.T) { name := self.Get("person1").Get("name") assert.Equal(t, "Alice", name.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 5, Column: 9}, name.Location()) + assert.Equal(t, diag.Location{File: file, Line: 5, Column: 9}, name.Location()) age := self.Get("person1").Get("age") assert.Equal(t, 25, age.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 2, Column: 13}, age.Location()) + assert.Equal(t, diag.Location{File: file, Line: 2, Column: 13}, age.Location()) } func TestYAMLAnchor08(t *testing.T) { @@ -113,11 +114,11 @@ func TestYAMLAnchor08(t *testing.T) { username := self.Get("user1").Get("username") assert.Equal(t, "user1", username.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 5, Column: 13}, username.Location()) + assert.Equal(t, diag.Location{File: file, Line: 5, Column: 13}, username.Location()) active := self.Get("user1").Get("active") assert.Equal(t, true, active.AsAny()) - assert.Equal(t, dyn.Location{File: file, Line: 2, Column: 11}, active.Location()) + assert.Equal(t, diag.Location{File: file, Line: 2, Column: 11}, active.Location()) } func TestYAMLAnchor09(t *testing.T) { diff --git a/libs/dyn/yamlloader/yaml_spec_test.go b/libs/dyn/yamlloader/yaml_spec_test.go index 9501409c92f..28ad2e7480c 100644 --- a/libs/dyn/yamlloader/yaml_spec_test.go +++ b/libs/dyn/yamlloader/yaml_spec_test.go @@ -6,6 +6,7 @@ import ( "os" "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/dynassert" "github.com/databricks/cli/libs/dyn/yamlloader" @@ -29,11 +30,11 @@ func TestYAMLSpecExample_2_1(t *testing.T) { assert.Equal(t, dyn.NewValue( []dyn.Value{ - dyn.NewValue("Mark McGwire", []dyn.Location{{File: file, Line: 3, Column: 3}}), - dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 4, Column: 3}}), - dyn.NewValue("Ken Griffey", []dyn.Location{{File: file, Line: 5, Column: 3}}), + dyn.NewValue("Mark McGwire", []diag.Location{{File: file, Line: 3, Column: 3}}), + dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 4, Column: 3}}), + dyn.NewValue("Ken Griffey", []diag.Location{{File: file, Line: 5, Column: 3}}), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -43,11 +44,11 @@ func TestYAMLSpecExample_2_2(t *testing.T) { dynassert.Equal(t, dyn.NewValue( map[string]dyn.Value{ - "hr": dyn.NewValue(65, []dyn.Location{{File: file, Line: 3, Column: 6}}), - "avg": dyn.NewValue(0.278, []dyn.Location{{File: file, Line: 4, Column: 6}}), - "rbi": dyn.NewValue(147, []dyn.Location{{File: file, Line: 5, Column: 6}}), + "hr": dyn.NewValue(65, []diag.Location{{File: file, Line: 3, Column: 6}}), + "avg": dyn.NewValue(0.278, []diag.Location{{File: file, Line: 4, Column: 6}}), + "rbi": dyn.NewValue(147, []diag.Location{{File: file, Line: 5, Column: 6}}), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -59,22 +60,22 @@ func TestYAMLSpecExample_2_3(t *testing.T) { map[string]dyn.Value{ "american": dyn.NewValue( []dyn.Value{ - dyn.NewValue("Boston Red Sox", []dyn.Location{{File: file, Line: 4, Column: 3}}), - dyn.NewValue("Detroit Tigers", []dyn.Location{{File: file, Line: 5, Column: 3}}), - dyn.NewValue("New York Yankees", []dyn.Location{{File: file, Line: 6, Column: 3}}), + dyn.NewValue("Boston Red Sox", []diag.Location{{File: file, Line: 4, Column: 3}}), + dyn.NewValue("Detroit Tigers", []diag.Location{{File: file, Line: 5, Column: 3}}), + dyn.NewValue("New York Yankees", []diag.Location{{File: file, Line: 6, Column: 3}}), }, - []dyn.Location{{File: file, Line: 4, Column: 1}}, + []diag.Location{{File: file, Line: 4, Column: 1}}, ), "national": dyn.NewValue( []dyn.Value{ - dyn.NewValue("New York Mets", []dyn.Location{{File: file, Line: 8, Column: 3}}), - dyn.NewValue("Chicago Cubs", []dyn.Location{{File: file, Line: 9, Column: 3}}), - dyn.NewValue("Atlanta Braves", []dyn.Location{{File: file, Line: 10, Column: 3}}), + dyn.NewValue("New York Mets", []diag.Location{{File: file, Line: 8, Column: 3}}), + dyn.NewValue("Chicago Cubs", []diag.Location{{File: file, Line: 9, Column: 3}}), + dyn.NewValue("Atlanta Braves", []diag.Location{{File: file, Line: 10, Column: 3}}), }, - []dyn.Location{{File: file, Line: 8, Column: 1}}, + []diag.Location{{File: file, Line: 8, Column: 1}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -86,22 +87,22 @@ func TestYAMLSpecExample_2_4(t *testing.T) { []dyn.Value{ dyn.NewValue( map[string]dyn.Value{ - "name": dyn.NewValue("Mark McGwire", []dyn.Location{{File: file, Line: 4, Column: 9}}), - "hr": dyn.NewValue(65, []dyn.Location{{File: file, Line: 5, Column: 9}}), - "avg": dyn.NewValue(0.278, []dyn.Location{{File: file, Line: 6, Column: 9}}), + "name": dyn.NewValue("Mark McGwire", []diag.Location{{File: file, Line: 4, Column: 9}}), + "hr": dyn.NewValue(65, []diag.Location{{File: file, Line: 5, Column: 9}}), + "avg": dyn.NewValue(0.278, []diag.Location{{File: file, Line: 6, Column: 9}}), }, - []dyn.Location{{File: file, Line: 4, Column: 3}}, + []diag.Location{{File: file, Line: 4, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ - "name": dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 8, Column: 9}}), - "hr": dyn.NewValue(63, []dyn.Location{{File: file, Line: 9, Column: 9}}), - "avg": dyn.NewValue(0.288, []dyn.Location{{File: file, Line: 10, Column: 9}}), + "name": dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 8, Column: 9}}), + "hr": dyn.NewValue(63, []diag.Location{{File: file, Line: 9, Column: 9}}), + "avg": dyn.NewValue(0.288, []diag.Location{{File: file, Line: 10, Column: 9}}), }, - []dyn.Location{{File: file, Line: 8, Column: 3}}, + []diag.Location{{File: file, Line: 8, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -113,30 +114,30 @@ func TestYAMLSpecExample_2_5(t *testing.T) { []dyn.Value{ dyn.NewValue( []dyn.Value{ - dyn.NewValue("name", []dyn.Location{{File: file, Line: 3, Column: 4}}), - dyn.NewValue("hr", []dyn.Location{{File: file, Line: 3, Column: 18}}), - dyn.NewValue("avg", []dyn.Location{{File: file, Line: 3, Column: 22}}), + dyn.NewValue("name", []diag.Location{{File: file, Line: 3, Column: 4}}), + dyn.NewValue("hr", []diag.Location{{File: file, Line: 3, Column: 18}}), + dyn.NewValue("avg", []diag.Location{{File: file, Line: 3, Column: 22}}), }, - []dyn.Location{{File: file, Line: 3, Column: 3}}, + []diag.Location{{File: file, Line: 3, Column: 3}}, ), dyn.NewValue( []dyn.Value{ - dyn.NewValue("Mark McGwire", []dyn.Location{{File: file, Line: 4, Column: 4}}), - dyn.NewValue(65, []dyn.Location{{File: file, Line: 4, Column: 18}}), - dyn.NewValue(0.278, []dyn.Location{{File: file, Line: 4, Column: 22}}), + dyn.NewValue("Mark McGwire", []diag.Location{{File: file, Line: 4, Column: 4}}), + dyn.NewValue(65, []diag.Location{{File: file, Line: 4, Column: 18}}), + dyn.NewValue(0.278, []diag.Location{{File: file, Line: 4, Column: 22}}), }, - []dyn.Location{{File: file, Line: 4, Column: 3}}, + []diag.Location{{File: file, Line: 4, Column: 3}}, ), dyn.NewValue( []dyn.Value{ - dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 5, Column: 4}}), - dyn.NewValue(63, []dyn.Location{{File: file, Line: 5, Column: 18}}), - dyn.NewValue(0.288, []dyn.Location{{File: file, Line: 5, Column: 22}}), + dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 5, Column: 4}}), + dyn.NewValue(63, []diag.Location{{File: file, Line: 5, Column: 18}}), + dyn.NewValue(0.288, []diag.Location{{File: file, Line: 5, Column: 22}}), }, - []dyn.Location{{File: file, Line: 5, Column: 3}}, + []diag.Location{{File: file, Line: 5, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -148,20 +149,20 @@ func TestYAMLSpecExample_2_6(t *testing.T) { map[string]dyn.Value{ "Mark McGwire": dyn.NewValue( map[string]dyn.Value{ - "hr": dyn.NewValue(65, []dyn.Location{{File: file, Line: 3, Column: 20}}), - "avg": dyn.NewValue(0.278, []dyn.Location{{File: file, Line: 3, Column: 29}}), + "hr": dyn.NewValue(65, []diag.Location{{File: file, Line: 3, Column: 20}}), + "avg": dyn.NewValue(0.278, []diag.Location{{File: file, Line: 3, Column: 29}}), }, - []dyn.Location{{File: file, Line: 3, Column: 15}}, + []diag.Location{{File: file, Line: 3, Column: 15}}, ), "Sammy Sosa": dyn.NewValue( map[string]dyn.Value{ - "hr": dyn.NewValue(63, []dyn.Location{{File: file, Line: 5, Column: 9}}), - "avg": dyn.NewValue(0.288, []dyn.Location{{File: file, Line: 6, Column: 10}}), + "hr": dyn.NewValue(63, []diag.Location{{File: file, Line: 5, Column: 9}}), + "avg": dyn.NewValue(0.288, []diag.Location{{File: file, Line: 6, Column: 10}}), }, - []dyn.Location{{File: file, Line: 4, Column: 13}}, + []diag.Location{{File: file, Line: 4, Column: 13}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -175,18 +176,18 @@ func TestYAMLSpecExample_2_7(t *testing.T) { []dyn.Value{ dyn.NewValue( "Mark McGwire", - []dyn.Location{{File: file, Line: 5, Column: 3}}, + []diag.Location{{File: file, Line: 5, Column: 3}}, ), dyn.NewValue( "Sammy Sosa", - []dyn.Location{{File: file, Line: 6, Column: 3}}, + []diag.Location{{File: file, Line: 6, Column: 3}}, ), dyn.NewValue( "Ken Griffey", - []dyn.Location{{File: file, Line: 7, Column: 3}}, + []diag.Location{{File: file, Line: 7, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 5, Column: 1}}, + []diag.Location{{File: file, Line: 5, Column: 1}}, ), self) } @@ -198,11 +199,11 @@ func TestYAMLSpecExample_2_8(t *testing.T) { dynassert.Equal(t, dyn.NewValue( map[string]dyn.Value{ - "time": dyn.NewValue("20:03:20", []dyn.Location{{File: file, Line: 4, Column: 7}}), - "player": dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 5, Column: 9}}), - "action": dyn.NewValue("strike (miss)", []dyn.Location{{File: file, Line: 6, Column: 9}}), + "time": dyn.NewValue("20:03:20", []diag.Location{{File: file, Line: 4, Column: 7}}), + "player": dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 5, Column: 9}}), + "action": dyn.NewValue("strike (miss)", []diag.Location{{File: file, Line: 6, Column: 9}}), }, - []dyn.Location{{File: file, Line: 4, Column: 1}}, + []diag.Location{{File: file, Line: 4, Column: 1}}, ), self) } @@ -216,20 +217,20 @@ func TestYAMLSpecExample_2_9(t *testing.T) { map[string]dyn.Value{ "hr": dyn.NewValue( []dyn.Value{ - dyn.NewValue("Mark McGwire", []dyn.Location{{File: file, Line: 5, Column: 3}}), - dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 6, Column: 3}}), + dyn.NewValue("Mark McGwire", []diag.Location{{File: file, Line: 5, Column: 3}}), + dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 6, Column: 3}}), }, - []dyn.Location{{File: file, Line: 5, Column: 1}}, + []diag.Location{{File: file, Line: 5, Column: 1}}, ), "rbi": dyn.NewValue( []dyn.Value{ - dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 9, Column: 3}}), - dyn.NewValue("Ken Griffey", []dyn.Location{{File: file, Line: 10, Column: 3}}), + dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 9, Column: 3}}), + dyn.NewValue("Ken Griffey", []diag.Location{{File: file, Line: 10, Column: 3}}), }, - []dyn.Location{{File: file, Line: 9, Column: 1}}, + []diag.Location{{File: file, Line: 9, Column: 1}}, ), }, - []dyn.Location{{File: file, Line: 4, Column: 1}}, + []diag.Location{{File: file, Line: 4, Column: 1}}, ), self) } @@ -241,22 +242,22 @@ func TestYAMLSpecExample_2_10(t *testing.T) { map[string]dyn.Value{ "hr": dyn.NewValue( []dyn.Value{ - dyn.NewValue("Mark McGwire", []dyn.Location{{File: file, Line: 5, Column: 3}}), - dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 7, Column: 3}}), + dyn.NewValue("Mark McGwire", []diag.Location{{File: file, Line: 5, Column: 3}}), + dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 7, Column: 3}}), }, - []dyn.Location{{File: file, Line: 5, Column: 1}}, + []diag.Location{{File: file, Line: 5, Column: 1}}, ), "rbi": dyn.NewValue( []dyn.Value{ // The location for an anchored value refers to the anchor, not the reference. // This is the same location as the anchor that appears in the "hr" mapping. - dyn.NewValue("Sammy Sosa", []dyn.Location{{File: file, Line: 7, Column: 3}}), - dyn.NewValue("Ken Griffey", []dyn.Location{{File: file, Line: 10, Column: 3}}), + dyn.NewValue("Sammy Sosa", []diag.Location{{File: file, Line: 7, Column: 3}}), + dyn.NewValue("Ken Griffey", []diag.Location{{File: file, Line: 10, Column: 3}}), }, - []dyn.Location{{File: file, Line: 9, Column: 1}}, + []diag.Location{{File: file, Line: 9, Column: 1}}, ), }, - []dyn.Location{{File: file, Line: 4, Column: 1}}, + []diag.Location{{File: file, Line: 4, Column: 1}}, ), self) } @@ -278,27 +279,27 @@ func TestYAMLSpecExample_2_12(t *testing.T) { []dyn.Value{ dyn.NewValue( map[string]dyn.Value{ - "item": dyn.NewValue("Super Hoop", []dyn.Location{{File: file, Line: 5, Column: 13}}), - "quantity": dyn.NewValue(1, []dyn.Location{{File: file, Line: 6, Column: 13}}), + "item": dyn.NewValue("Super Hoop", []diag.Location{{File: file, Line: 5, Column: 13}}), + "quantity": dyn.NewValue(1, []diag.Location{{File: file, Line: 6, Column: 13}}), }, - []dyn.Location{{File: file, Line: 5, Column: 3}}, + []diag.Location{{File: file, Line: 5, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ - "item": dyn.NewValue("Basketball", []dyn.Location{{File: file, Line: 7, Column: 13}}), - "quantity": dyn.NewValue(4, []dyn.Location{{File: file, Line: 8, Column: 13}}), + "item": dyn.NewValue("Basketball", []diag.Location{{File: file, Line: 7, Column: 13}}), + "quantity": dyn.NewValue(4, []diag.Location{{File: file, Line: 8, Column: 13}}), }, - []dyn.Location{{File: file, Line: 7, Column: 3}}, + []diag.Location{{File: file, Line: 7, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ - "item": dyn.NewValue("Big Shoes", []dyn.Location{{File: file, Line: 9, Column: 13}}), - "quantity": dyn.NewValue(1, []dyn.Location{{File: file, Line: 10, Column: 13}}), + "item": dyn.NewValue("Big Shoes", []diag.Location{{File: file, Line: 9, Column: 13}}), + "quantity": dyn.NewValue(1, []diag.Location{{File: file, Line: 10, Column: 13}}), }, - []dyn.Location{{File: file, Line: 9, Column: 3}}, + []diag.Location{{File: file, Line: 9, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 5, Column: 1}}, + []diag.Location{{File: file, Line: 5, Column: 1}}, ), self) } @@ -310,7 +311,7 @@ func TestYAMLSpecExample_2_13(t *testing.T) { ``+ `\//||\/||`+NL+ "// || ||__"+NL, - []dyn.Location{{File: file, Line: 4, Column: 5}}, + []diag.Location{{File: file, Line: 4, Column: 5}}, ), self) } @@ -320,7 +321,7 @@ func TestYAMLSpecExample_2_14(t *testing.T) { dynassert.Equal(t, dyn.NewValue( `Mark McGwire's year was crippled by a knee injury.`+NL, - []dyn.Location{{File: file, Line: 3, Column: 5}}, + []diag.Location{{File: file, Line: 3, Column: 5}}, ), self) } @@ -336,7 +337,7 @@ func TestYAMLSpecExample_2_15(t *testing.T) { ` 0.288 Batting Average`+NL+ NL+ `What a year!`+NL, - []dyn.Location{{File: file, Line: 3, Column: 5}}, + []diag.Location{{File: file, Line: 3, Column: 5}}, ), self) } @@ -348,20 +349,20 @@ func TestYAMLSpecExample_2_16(t *testing.T) { map[string]dyn.Value{ "name": dyn.NewValue( "Mark McGwire", - []dyn.Location{{File: file, Line: 3, Column: 7}}, + []diag.Location{{File: file, Line: 3, Column: 7}}, ), "accomplishment": dyn.NewValue( `Mark set a major league home run record in 1998.`+NL, - []dyn.Location{{File: file, Line: 4, Column: 17}}, + []diag.Location{{File: file, Line: 4, Column: 17}}, ), "stats": dyn.NewValue( ``+ `65 Home Runs`+NL+ `0.278 Batting Average`+NL, - []dyn.Location{{File: file, Line: 7, Column: 8}}, + []diag.Location{{File: file, Line: 7, Column: 8}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -373,30 +374,30 @@ func TestYAMLSpecExample_2_17(t *testing.T) { map[string]dyn.Value{ "unicode": dyn.NewValue( `Sosa did fine.`+"\u263A", - []dyn.Location{{File: file, Line: 3, Column: 10}}, + []diag.Location{{File: file, Line: 3, Column: 10}}, ), "control": dyn.NewValue( "\b1998\t1999\t2000\n", - []dyn.Location{{File: file, Line: 4, Column: 10}}, + []diag.Location{{File: file, Line: 4, Column: 10}}, ), "hex esc": dyn.NewValue( "\x0d\x0a is \r\n", - []dyn.Location{{File: file, Line: 5, Column: 10}}, + []diag.Location{{File: file, Line: 5, Column: 10}}, ), "single": dyn.NewValue( `"Howdy!" he cried.`, - []dyn.Location{{File: file, Line: 7, Column: 9}}, + []diag.Location{{File: file, Line: 7, Column: 9}}, ), "quoted": dyn.NewValue( ` # Not a 'comment'.`, - []dyn.Location{{File: file, Line: 8, Column: 9}}, + []diag.Location{{File: file, Line: 8, Column: 9}}, ), "tie-fighter": dyn.NewValue( `|\-*-/|`, - []dyn.Location{{File: file, Line: 9, Column: 14}}, + []diag.Location{{File: file, Line: 9, Column: 14}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -408,14 +409,14 @@ func TestYAMLSpecExample_2_18(t *testing.T) { map[string]dyn.Value{ "plain": dyn.NewValue( `This unquoted scalar spans many lines.`, - []dyn.Location{{File: file, Line: 4, Column: 3}}, + []diag.Location{{File: file, Line: 4, Column: 3}}, ), "quoted": dyn.NewValue( `So does this quoted scalar.`+NL, - []dyn.Location{{File: file, Line: 7, Column: 9}}, + []diag.Location{{File: file, Line: 7, Column: 9}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -427,26 +428,26 @@ func TestYAMLSpecExample_2_19(t *testing.T) { map[string]dyn.Value{ "canonical": dyn.NewValue( 12345, - []dyn.Location{{File: file, Line: 3, Column: 12}}, + []diag.Location{{File: file, Line: 3, Column: 12}}, ), "decimal": dyn.NewValue( 12345, - []dyn.Location{{File: file, Line: 4, Column: 10}}, + []diag.Location{{File: file, Line: 4, Column: 10}}, ), "octal": dyn.NewValue( 12, - []dyn.Location{{File: file, Line: 5, Column: 8}}, + []diag.Location{{File: file, Line: 5, Column: 8}}, ), "hexadecimal": dyn.NewValue( 12, - []dyn.Location{{File: file, Line: 6, Column: 14}}, + []diag.Location{{File: file, Line: 6, Column: 14}}, ), "octal11": dyn.NewValue( 12345, - []dyn.Location{{File: file, Line: 15, Column: 10}}, + []diag.Location{{File: file, Line: 15, Column: 10}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -469,22 +470,22 @@ func TestYAMLSpecExample_2_20(t *testing.T) { map[string]dyn.Value{ "canonical": dyn.NewValue( 1230.15, - []dyn.Location{{File: file, Line: 3, Column: 12}}, + []diag.Location{{File: file, Line: 3, Column: 12}}, ), "exponential": dyn.NewValue( 1230.15, - []dyn.Location{{File: file, Line: 4, Column: 14}}, + []diag.Location{{File: file, Line: 4, Column: 14}}, ), "fixed": dyn.NewValue( 1230.15, - []dyn.Location{{File: file, Line: 5, Column: 8}}, + []diag.Location{{File: file, Line: 5, Column: 8}}, ), "negative infinity": dyn.NewValue( math.Inf(-1), - []dyn.Location{{File: file, Line: 6, Column: 20}}, + []diag.Location{{File: file, Line: 6, Column: 20}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -496,21 +497,21 @@ func TestYAMLSpecExample_2_21(t *testing.T) { map[string]dyn.Value{ "null": dyn.NewValue( nil, - []dyn.Location{{File: file, Line: 3, Column: 6}}, + []diag.Location{{File: file, Line: 3, Column: 6}}, ), "booleans": dyn.NewValue( []dyn.Value{ - dyn.NewValue(true, []dyn.Location{{File: file, Line: 4, Column: 13}}), - dyn.NewValue(false, []dyn.Location{{File: file, Line: 4, Column: 19}}), + dyn.NewValue(true, []diag.Location{{File: file, Line: 4, Column: 13}}), + dyn.NewValue(false, []diag.Location{{File: file, Line: 4, Column: 19}}), }, - []dyn.Location{{File: file, Line: 4, Column: 11}}, + []diag.Location{{File: file, Line: 4, Column: 11}}, ), "string": dyn.NewValue( "012345", - []dyn.Location{{File: file, Line: 5, Column: 9}}, + []diag.Location{{File: file, Line: 5, Column: 9}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -522,24 +523,24 @@ func TestYAMLSpecExample_2_22(t *testing.T) { map[string]dyn.Value{ "canonical": dyn.NewValue( dyn.MustTime("2001-12-15T02:59:43.1Z"), - []dyn.Location{{File: file, Line: 3, Column: 12}}, + []diag.Location{{File: file, Line: 3, Column: 12}}, ), "iso8601": dyn.NewValue( dyn.MustTime("2001-12-14t21:59:43.10-05:00"), - []dyn.Location{{File: file, Line: 4, Column: 10}}, + []diag.Location{{File: file, Line: 4, Column: 10}}, ), "spaced": dyn.NewValue( // This is parsed as a string, not a timestamp, // both by "go.yaml.in/yaml/v3" and by our implementation. "2001-12-14 21:59:43.10 -5", - []dyn.Location{{File: file, Line: 5, Column: 9}}, + []diag.Location{{File: file, Line: 5, Column: 9}}, ), "date": dyn.NewValue( dyn.MustTime("2002-12-14"), - []dyn.Location{{File: file, Line: 6, Column: 7}}, + []diag.Location{{File: file, Line: 6, Column: 7}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 1}}, + []diag.Location{{File: file, Line: 3, Column: 1}}, ), self) } @@ -564,50 +565,50 @@ func TestYAMLSpecExample_2_24(t *testing.T) { map[string]dyn.Value{ "center": dyn.NewValue( map[string]dyn.Value{ - "x": dyn.NewValue(73, []dyn.Location{{File: file, Line: 8, Column: 23}}), - "y": dyn.NewValue(129, []dyn.Location{{File: file, Line: 8, Column: 30}}), + "x": dyn.NewValue(73, []diag.Location{{File: file, Line: 8, Column: 23}}), + "y": dyn.NewValue(129, []diag.Location{{File: file, Line: 8, Column: 30}}), }, - []dyn.Location{{File: file, Line: 8, Column: 11}}, + []diag.Location{{File: file, Line: 8, Column: 11}}, ), - "radius": dyn.NewValue(7, []dyn.Location{{File: file, Line: 9, Column: 11}}), + "radius": dyn.NewValue(7, []diag.Location{{File: file, Line: 9, Column: 11}}), }, - []dyn.Location{{File: file, Line: 7, Column: 3}}, + []diag.Location{{File: file, Line: 7, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ "start": dyn.NewValue( map[string]dyn.Value{ - "x": dyn.NewValue(73, []dyn.Location{{File: file, Line: 8, Column: 23}}), - "y": dyn.NewValue(129, []dyn.Location{{File: file, Line: 8, Column: 30}}), + "x": dyn.NewValue(73, []diag.Location{{File: file, Line: 8, Column: 23}}), + "y": dyn.NewValue(129, []diag.Location{{File: file, Line: 8, Column: 30}}), }, - []dyn.Location{{File: file, Line: 8, Column: 11}}, + []diag.Location{{File: file, Line: 8, Column: 11}}, ), "finish": dyn.NewValue( map[string]dyn.Value{ - "x": dyn.NewValue(89, []dyn.Location{{File: file, Line: 12, Column: 16}}), - "y": dyn.NewValue(102, []dyn.Location{{File: file, Line: 12, Column: 23}}), + "x": dyn.NewValue(89, []diag.Location{{File: file, Line: 12, Column: 16}}), + "y": dyn.NewValue(102, []diag.Location{{File: file, Line: 12, Column: 23}}), }, - []dyn.Location{{File: file, Line: 12, Column: 11}}, + []diag.Location{{File: file, Line: 12, Column: 11}}, ), }, - []dyn.Location{{File: file, Line: 10, Column: 3}}, + []diag.Location{{File: file, Line: 10, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ "start": dyn.NewValue( map[string]dyn.Value{ - "x": dyn.NewValue(73, []dyn.Location{{File: file, Line: 8, Column: 23}}), - "y": dyn.NewValue(129, []dyn.Location{{File: file, Line: 8, Column: 30}}), + "x": dyn.NewValue(73, []diag.Location{{File: file, Line: 8, Column: 23}}), + "y": dyn.NewValue(129, []diag.Location{{File: file, Line: 8, Column: 30}}), }, - []dyn.Location{{File: file, Line: 8, Column: 11}}, + []diag.Location{{File: file, Line: 8, Column: 11}}, ), - "color": dyn.NewValue(16772795, []dyn.Location{{File: file, Line: 15, Column: 10}}), - "text": dyn.NewValue("Pretty vector drawing.", []dyn.Location{{File: file, Line: 16, Column: 9}}), + "color": dyn.NewValue(16772795, []diag.Location{{File: file, Line: 15, Column: 10}}), + "text": dyn.NewValue("Pretty vector drawing.", []diag.Location{{File: file, Line: 16, Column: 9}}), }, - []dyn.Location{{File: file, Line: 13, Column: 3}}, + []diag.Location{{File: file, Line: 13, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 4, Column: 5}}, + []diag.Location{{File: file, Line: 4, Column: 5}}, ), self) } @@ -617,11 +618,11 @@ func TestYAMLSpecExample_2_25(t *testing.T) { dynassert.Equal(t, dyn.NewValue( map[string]dyn.Value{ - "Mark McGwire": dyn.NewValue(nil, []dyn.Location{{File: file, Line: 8, Column: 1}}), - "Sammy Sosa": dyn.NewValue(nil, []dyn.Location{{File: file, Line: 9, Column: 1}}), - "Ken Griffey": dyn.NewValue(nil, []dyn.Location{{File: file, Line: 10, Column: 1}}), + "Mark McGwire": dyn.NewValue(nil, []diag.Location{{File: file, Line: 8, Column: 1}}), + "Sammy Sosa": dyn.NewValue(nil, []diag.Location{{File: file, Line: 9, Column: 1}}), + "Ken Griffey": dyn.NewValue(nil, []diag.Location{{File: file, Line: 10, Column: 1}}), }, - []dyn.Location{{File: file, Line: 6, Column: 5}}, + []diag.Location{{File: file, Line: 6, Column: 5}}, ), self) } @@ -633,24 +634,24 @@ func TestYAMLSpecExample_2_26(t *testing.T) { []dyn.Value{ dyn.NewValue( map[string]dyn.Value{ - "Mark McGwire": dyn.NewValue(65, []dyn.Location{{File: file, Line: 7, Column: 17}}), + "Mark McGwire": dyn.NewValue(65, []diag.Location{{File: file, Line: 7, Column: 17}}), }, - []dyn.Location{{File: file, Line: 7, Column: 3}}, + []diag.Location{{File: file, Line: 7, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ - "Sammy Sosa": dyn.NewValue(63, []dyn.Location{{File: file, Line: 8, Column: 15}}), + "Sammy Sosa": dyn.NewValue(63, []diag.Location{{File: file, Line: 8, Column: 15}}), }, - []dyn.Location{{File: file, Line: 8, Column: 3}}, + []diag.Location{{File: file, Line: 8, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ - "Ken Griffey": dyn.NewValue(58, []dyn.Location{{File: file, Line: 9, Column: 16}}), + "Ken Griffey": dyn.NewValue(58, []diag.Location{{File: file, Line: 9, Column: 16}}), }, - []dyn.Location{{File: file, Line: 9, Column: 3}}, + []diag.Location{{File: file, Line: 9, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 6, Column: 5}}, + []diag.Location{{File: file, Line: 6, Column: 5}}, ), self) } @@ -662,79 +663,79 @@ func TestYAMLSpecExample_2_27(t *testing.T) { map[string]dyn.Value{ "invoice": dyn.NewValue( 34843, - []dyn.Location{{File: file, Line: 4, Column: 10}}, + []diag.Location{{File: file, Line: 4, Column: 10}}, ), "date": dyn.NewValue( dyn.MustTime("2001-01-23"), - []dyn.Location{{File: file, Line: 5, Column: 10}}, + []diag.Location{{File: file, Line: 5, Column: 10}}, ), "bill-to": dyn.NewValue( map[string]dyn.Value{ "given": dyn.NewValue( "Chris", - []dyn.Location{{File: file, Line: 7, Column: 12}}, + []diag.Location{{File: file, Line: 7, Column: 12}}, ), "family": dyn.NewValue( "Dumars", - []dyn.Location{{File: file, Line: 8, Column: 12}}, + []diag.Location{{File: file, Line: 8, Column: 12}}, ), "address": dyn.NewValue( map[string]dyn.Value{ "lines": dyn.NewValue( "458 Walkman Dr.\nSuite #292\n", - []dyn.Location{{File: file, Line: 10, Column: 12}}, + []diag.Location{{File: file, Line: 10, Column: 12}}, ), "city": dyn.NewValue( "Royal Oak", - []dyn.Location{{File: file, Line: 13, Column: 15}}, + []diag.Location{{File: file, Line: 13, Column: 15}}, ), "state": dyn.NewValue( "MI", - []dyn.Location{{File: file, Line: 14, Column: 15}}, + []diag.Location{{File: file, Line: 14, Column: 15}}, ), "postal": dyn.NewValue( 48046, - []dyn.Location{{File: file, Line: 15, Column: 15}}, + []diag.Location{{File: file, Line: 15, Column: 15}}, ), }, - []dyn.Location{{File: file, Line: 10, Column: 5}}, + []diag.Location{{File: file, Line: 10, Column: 5}}, ), }, - []dyn.Location{{File: file, Line: 6, Column: 10}}, + []diag.Location{{File: file, Line: 6, Column: 10}}, ), "ship-to": dyn.NewValue( map[string]dyn.Value{ "given": dyn.NewValue( "Chris", - []dyn.Location{{File: file, Line: 7, Column: 12}}, + []diag.Location{{File: file, Line: 7, Column: 12}}, ), "family": dyn.NewValue( "Dumars", - []dyn.Location{{File: file, Line: 8, Column: 12}}, + []diag.Location{{File: file, Line: 8, Column: 12}}, ), "address": dyn.NewValue( map[string]dyn.Value{ "lines": dyn.NewValue( "458 Walkman Dr.\nSuite #292\n", - []dyn.Location{{File: file, Line: 10, Column: 12}}, + []diag.Location{{File: file, Line: 10, Column: 12}}, ), "city": dyn.NewValue( "Royal Oak", - []dyn.Location{{File: file, Line: 13, Column: 15}}, + []diag.Location{{File: file, Line: 13, Column: 15}}, ), "state": dyn.NewValue( "MI", - []dyn.Location{{File: file, Line: 14, Column: 15}}, + []diag.Location{{File: file, Line: 14, Column: 15}}, ), "postal": dyn.NewValue( 48046, - []dyn.Location{{File: file, Line: 15, Column: 15}}, + []diag.Location{{File: file, Line: 15, Column: 15}}, ), }, - []dyn.Location{{File: file, Line: 10, Column: 5}}, + []diag.Location{{File: file, Line: 10, Column: 5}}, ), }, - []dyn.Location{{File: file, Line: 6, Column: 10}}, + []diag.Location{{File: file, Line: 6, Column: 10}}, ), "product": dyn.NewValue( []dyn.Value{ @@ -742,60 +743,60 @@ func TestYAMLSpecExample_2_27(t *testing.T) { map[string]dyn.Value{ "sku": dyn.NewValue( "BL394D", - []dyn.Location{{File: file, Line: 18, Column: 17}}, + []diag.Location{{File: file, Line: 18, Column: 17}}, ), "quantity": dyn.NewValue( 4, - []dyn.Location{{File: file, Line: 19, Column: 17}}, + []diag.Location{{File: file, Line: 19, Column: 17}}, ), "description": dyn.NewValue( "Basketball", - []dyn.Location{{File: file, Line: 20, Column: 17}}, + []diag.Location{{File: file, Line: 20, Column: 17}}, ), "price": dyn.NewValue( 450.0, - []dyn.Location{{File: file, Line: 21, Column: 17}}, + []diag.Location{{File: file, Line: 21, Column: 17}}, ), }, - []dyn.Location{{File: file, Line: 18, Column: 3}}, + []diag.Location{{File: file, Line: 18, Column: 3}}, ), dyn.NewValue( map[string]dyn.Value{ "sku": dyn.NewValue( "BL4438H", - []dyn.Location{{File: file, Line: 22, Column: 17}}, + []diag.Location{{File: file, Line: 22, Column: 17}}, ), "quantity": dyn.NewValue( 1, - []dyn.Location{{File: file, Line: 23, Column: 17}}, + []diag.Location{{File: file, Line: 23, Column: 17}}, ), "description": dyn.NewValue( "Super Hoop", - []dyn.Location{{File: file, Line: 24, Column: 17}}, + []diag.Location{{File: file, Line: 24, Column: 17}}, ), "price": dyn.NewValue( 2392.0, - []dyn.Location{{File: file, Line: 25, Column: 17}}, + []diag.Location{{File: file, Line: 25, Column: 17}}, ), }, - []dyn.Location{{File: file, Line: 22, Column: 3}}, + []diag.Location{{File: file, Line: 22, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 18, Column: 1}}, + []diag.Location{{File: file, Line: 18, Column: 1}}, ), "tax": dyn.NewValue( 251.42, - []dyn.Location{{File: file, Line: 26, Column: 8}}, + []diag.Location{{File: file, Line: 26, Column: 8}}, ), "total": dyn.NewValue( 4443.52, - []dyn.Location{{File: file, Line: 27, Column: 8}}, + []diag.Location{{File: file, Line: 27, Column: 8}}, ), "comments": dyn.NewValue( "Late afternoon is best. Backup contact is Nancy Billsmer @ 338-4338.", - []dyn.Location{{File: file, Line: 29, Column: 3}}, + []diag.Location{{File: file, Line: 29, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 3, Column: 5}}, + []diag.Location{{File: file, Line: 3, Column: 5}}, ), self) } @@ -807,17 +808,17 @@ func TestYAMLSpecExample_2_28(t *testing.T) { map[string]dyn.Value{ "Time": dyn.NewValue( "2001-11-23 15:01:42 -5", - []dyn.Location{{File: file, Line: 4, Column: 7}}, + []diag.Location{{File: file, Line: 4, Column: 7}}, ), "User": dyn.NewValue( "ed", - []dyn.Location{{File: file, Line: 5, Column: 7}}, + []diag.Location{{File: file, Line: 5, Column: 7}}, ), "Warning": dyn.NewValue( "This is an error message for the log file", - []dyn.Location{{File: file, Line: 7, Column: 3}}, + []diag.Location{{File: file, Line: 7, Column: 3}}, ), }, - []dyn.Location{{File: file, Line: 4, Column: 1}}, + []diag.Location{{File: file, Line: 4, Column: 1}}, ), self) } diff --git a/libs/dyn/yamlsaver/saver_test.go b/libs/dyn/yamlsaver/saver_test.go index 5752fb4aaa4..a4f50e0b8fb 100644 --- a/libs/dyn/yamlsaver/saver_test.go +++ b/libs/dyn/yamlsaver/saver_test.go @@ -3,6 +3,7 @@ package yamlsaver import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -60,10 +61,10 @@ func TestMarshalSequenceValue(t *testing.T) { s := NewSaver() sequenceValue := dyn.NewValue( []dyn.Value{ - dyn.NewValue("value1", []dyn.Location{{File: "file", Line: 1, Column: 2}}), - dyn.NewValue("value2", []dyn.Location{{File: "file", Line: 2, Column: 2}}), + dyn.NewValue("value1", []diag.Location{{File: "file", Line: 1, Column: 2}}), + dyn.NewValue("value2", []diag.Location{{File: "file", Line: 2, Column: 2}}), }, - []dyn.Location{{File: "file", Line: 1, Column: 2}}, + []diag.Location{{File: "file", Line: 1, Column: 2}}, ) v, err := s.toYamlNode(sequenceValue) assert.NoError(t, err) @@ -85,11 +86,11 @@ func TestMarshalMapValue(t *testing.T) { s := NewSaver() mapValue := dyn.NewValue( map[string]dyn.Value{ - "key3": dyn.NewValue("value3", []dyn.Location{{File: "file", Line: 3, Column: 2}}), - "key2": dyn.NewValue("value2", []dyn.Location{{File: "file", Line: 2, Column: 2}}), - "key1": dyn.NewValue("value1", []dyn.Location{{File: "file", Line: 1, Column: 2}}), + "key3": dyn.NewValue("value3", []diag.Location{{File: "file", Line: 3, Column: 2}}), + "key2": dyn.NewValue("value2", []diag.Location{{File: "file", Line: 2, Column: 2}}), + "key1": dyn.NewValue("value1", []diag.Location{{File: "file", Line: 1, Column: 2}}), }, - []dyn.Location{{File: "file", Line: 1, Column: 2}}, + []diag.Location{{File: "file", Line: 1, Column: 2}}, ) v, err := s.toYamlNode(mapValue) @@ -111,12 +112,12 @@ func TestMarshalNestedValues(t *testing.T) { map[string]dyn.Value{ "key1": dyn.NewValue( map[string]dyn.Value{ - "key2": dyn.NewValue("value", []dyn.Location{{File: "file", Line: 1, Column: 2}}), + "key2": dyn.NewValue("value", []diag.Location{{File: "file", Line: 1, Column: 2}}), }, - []dyn.Location{{File: "file", Line: 1, Column: 2}}, + []diag.Location{{File: "file", Line: 1, Column: 2}}, ), }, - []dyn.Location{{File: "file", Line: 1, Column: 2}}, + []diag.Location{{File: "file", Line: 1, Column: 2}}, ) v, err := s.toYamlNode(mapValue) assert.NoError(t, err) @@ -219,18 +220,18 @@ func TestCustomStylingWithNestedMap(t *testing.T) { styledMap := dyn.NewValue( map[string]dyn.Value{ - "key1": dyn.NewValue("value1", []dyn.Location{{File: "file", Line: 1, Column: 2}}), - "key2": dyn.NewValue("value2", []dyn.Location{{File: "file", Line: 2, Column: 2}}), + "key1": dyn.NewValue("value1", []diag.Location{{File: "file", Line: 1, Column: 2}}), + "key2": dyn.NewValue("value2", []diag.Location{{File: "file", Line: 2, Column: 2}}), }, - []dyn.Location{{File: "file", Line: -2, Column: 2}}, + []diag.Location{{File: "file", Line: -2, Column: 2}}, ) unstyledMap := dyn.NewValue( map[string]dyn.Value{ - "key3": dyn.NewValue("value3", []dyn.Location{{File: "file", Line: 1, Column: 2}}), - "key4": dyn.NewValue("value4", []dyn.Location{{File: "file", Line: 2, Column: 2}}), + "key3": dyn.NewValue("value3", []diag.Location{{File: "file", Line: 1, Column: 2}}), + "key4": dyn.NewValue("value4", []diag.Location{{File: "file", Line: 2, Column: 2}}), }, - []dyn.Location{{File: "file", Line: -1, Column: 2}}, + []diag.Location{{File: "file", Line: -1, Column: 2}}, ) val := dyn.NewValue( @@ -238,7 +239,7 @@ func TestCustomStylingWithNestedMap(t *testing.T) { "styled": styledMap, "unstyled": unstyledMap, }, - []dyn.Location{{File: "file", Line: 1, Column: 2}}, + []diag.Location{{File: "file", Line: 1, Column: 2}}, ) mv, err := s.toYamlNode(val) diff --git a/libs/dyn/yamlsaver/utils.go b/libs/dyn/yamlsaver/utils.go index aa1e925e559..61f41790029 100644 --- a/libs/dyn/yamlsaver/utils.go +++ b/libs/dyn/yamlsaver/utils.go @@ -4,6 +4,7 @@ import ( "fmt" "slices" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/convert" ) @@ -85,7 +86,7 @@ func skipAndOrder(mv dyn.Value, order *Order, skipFields []string, dst map[strin if order == nil { dst[k] = v } else { - dst[k] = dyn.NewValue(v.Value(), []dyn.Location{{Line: order.Get(k)}}) + dst[k] = dyn.NewValue(v.Value(), []diag.Location{{Line: order.Get(k)}}) } } diff --git a/libs/dyn/yamlsaver/utils_test.go b/libs/dyn/yamlsaver/utils_test.go index d9f81239f7e..8b056e0076f 100644 --- a/libs/dyn/yamlsaver/utils_test.go +++ b/libs/dyn/yamlsaver/utils_test.go @@ -3,6 +3,7 @@ package yamlsaver import ( "testing" + "github.com/databricks/cli/libs/diag" "github.com/databricks/cli/libs/dyn" "github.com/databricks/cli/libs/dyn/dynassert" "github.com/stretchr/testify/assert" @@ -85,19 +86,19 @@ func TestConvertToMapValueWithOrder(t *testing.T) { dyn.V("b"), dyn.V("c"), }, - []dyn.Location{{Line: -3}}, + []diag.Location{{Line: -3}}, ), "name": dyn.NewValue( "test", - []dyn.Location{{Line: -2}}, + []diag.Location{{Line: -2}}, ), "map": dyn.NewValue( map[string]dyn.Value{ "key1": dyn.V("value1"), "key2": dyn.V("value2"), }, - []dyn.Location{{Line: -1}}, + []diag.Location{{Line: -1}}, ), - "long_name_field": dyn.NewValue("long name goes here", []dyn.Location{{Line: 1}}), + "long_name_field": dyn.NewValue("long name goes here", []diag.Location{{Line: 1}}), }), result) } diff --git a/libs/flags/json_flag_test.go b/libs/flags/json_flag_test.go index 1e26d4b3d57..4e4e099dbb1 100644 --- a/libs/flags/json_flag_test.go +++ b/libs/flags/json_flag_test.go @@ -195,7 +195,7 @@ func TestJsonUnmarshalRequestMismatch(t *testing.T) { assert.Contains(t, diags, diag.Diagnostic{ Severity: diag.Warning, Summary: "unknown field: settings", - Locations: []dyn.Location{ + Locations: []diag.Location{ { File: "(inline)", Line: 3, @@ -253,7 +253,7 @@ func TestJsonUnmarshalWrongTypeReportsCorrectLocation(t *testing.T) { assert.Contains(t, diags, diag.Diagnostic{ Severity: diag.Warning, Summary: "expected int, found sequence", - Locations: []dyn.Location{ + Locations: []diag.Location{ { File: "(inline)", Line: 2, @@ -278,7 +278,7 @@ func TestJsonUnmarshalArrayInsteadOfIntReportsCorrectLocation(t *testing.T) { assert.Contains(t, diags, diag.Diagnostic{ Severity: diag.Warning, Summary: "cannot parse \"wrong_type\" as an integer", - Locations: []dyn.Location{ + Locations: []diag.Location{ { File: "(inline)", Line: 14,