mirror of https://github.com/databricks/cli.git
fix failing tests
This commit is contained in:
parent
4734249854
commit
d9cf582287
|
@ -131,7 +131,7 @@ func validateSingleResourceDefined(configRoot dyn.Value, ext, typ string) diag.D
|
||||||
|
|
||||||
return diag.Diagnostics{
|
return diag.Diagnostics{
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: fmt.Sprintf("We recommend only defining a single %s in a file with the %s extension.", typ, ext),
|
Summary: fmt.Sprintf("We recommend only defining a single %s in a file with the %s extension.", typ, ext),
|
||||||
Detail: detail.String(),
|
Detail: detail.String(),
|
||||||
Locations: locations,
|
Locations: locations,
|
||||||
|
|
|
@ -65,7 +65,7 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
for fileName, expectedDiags := range map[string]diag.Diagnostics{
|
for fileName, expectedDiags := range map[string]diag.Diagnostics{
|
||||||
"single_job.pipeline.yaml": {
|
"single_job.pipeline.yaml": {
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "We recommend only defining a single pipeline in a file with the .pipeline.yaml extension.",
|
Summary: "We recommend only defining 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",
|
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n",
|
||||||
Locations: []dyn.Location{
|
Locations: []dyn.Location{
|
||||||
|
@ -80,12 +80,12 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
},
|
},
|
||||||
"job_and_pipeline.job.yml": {
|
"job_and_pipeline.job.yml": {
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "We recommend only defining a single job in a file with the .job.yml extension.",
|
Summary: "We recommend only defining 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",
|
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - pipeline1 (pipeline)\n",
|
||||||
Locations: []dyn.Location{
|
Locations: []dyn.Location{
|
||||||
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.job.yml"), Line: 12, Column: 11},
|
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.job.yml"), Line: 11, Column: 11},
|
||||||
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.job.yml"), Line: 5, Column: 7},
|
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.job.yml"), Line: 4, Column: 7},
|
||||||
},
|
},
|
||||||
Paths: []dyn.Path{
|
Paths: []dyn.Path{
|
||||||
dyn.MustPathFromString("resources.pipelines.pipeline1"),
|
dyn.MustPathFromString("resources.pipelines.pipeline1"),
|
||||||
|
@ -95,12 +95,12 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
},
|
},
|
||||||
"job_and_pipeline.experiment.yml": {
|
"job_and_pipeline.experiment.yml": {
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "We recommend only defining a single experiment in a file with the .experiment.yml extension.",
|
Summary: "We recommend only defining 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",
|
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - pipeline1 (pipeline)\n",
|
||||||
Locations: []dyn.Location{
|
Locations: []dyn.Location{
|
||||||
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.experiment.yml"), Line: 12, Column: 11},
|
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.experiment.yml"), Line: 11, Column: 11},
|
||||||
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.experiment.yml"), Line: 5, Column: 7},
|
{File: filepath.FromSlash("testdata/format_fail/job_and_pipeline.experiment.yml"), Line: 4, Column: 7},
|
||||||
},
|
},
|
||||||
Paths: []dyn.Path{
|
Paths: []dyn.Path{
|
||||||
dyn.MustPathFromString("resources.pipelines.pipeline1"),
|
dyn.MustPathFromString("resources.pipelines.pipeline1"),
|
||||||
|
@ -110,12 +110,12 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
},
|
},
|
||||||
"two_jobs.job.yml": {
|
"two_jobs.job.yml": {
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "We recommend only defining a single job in a file with the .job.yml extension.",
|
Summary: "We recommend only defining 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",
|
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n",
|
||||||
Locations: []dyn.Location{
|
Locations: []dyn.Location{
|
||||||
{File: filepath.FromSlash("testdata/format_fail/two_jobs.job.yml"), Line: 5, Column: 7},
|
{File: filepath.FromSlash("testdata/format_fail/two_jobs.job.yml"), Line: 4, Column: 7},
|
||||||
{File: filepath.FromSlash("testdata/format_fail/two_jobs.job.yml"), Line: 8, Column: 7},
|
{File: filepath.FromSlash("testdata/format_fail/two_jobs.job.yml"), Line: 7, Column: 7},
|
||||||
},
|
},
|
||||||
Paths: []dyn.Path{
|
Paths: []dyn.Path{
|
||||||
dyn.MustPathFromString("resources.jobs.job1"),
|
dyn.MustPathFromString("resources.jobs.job1"),
|
||||||
|
@ -125,12 +125,12 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
},
|
},
|
||||||
"second_job_in_target.job.yml": {
|
"second_job_in_target.job.yml": {
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "We recommend only defining a single job in a file with the .job.yml extension.",
|
Summary: "We recommend only defining 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",
|
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n",
|
||||||
Locations: []dyn.Location{
|
Locations: []dyn.Location{
|
||||||
{File: filepath.FromSlash("testdata/format_fail/second_job_in_target.job.yml"), Line: 12, Column: 11},
|
{File: filepath.FromSlash("testdata/format_fail/second_job_in_target.job.yml"), Line: 11, Column: 11},
|
||||||
{File: filepath.FromSlash("testdata/format_fail/second_job_in_target.job.yml"), Line: 5, Column: 7},
|
{File: filepath.FromSlash("testdata/format_fail/second_job_in_target.job.yml"), Line: 4, Column: 7},
|
||||||
},
|
},
|
||||||
Paths: []dyn.Path{
|
Paths: []dyn.Path{
|
||||||
dyn.MustPathFromString("resources.jobs.job1"),
|
dyn.MustPathFromString("resources.jobs.job1"),
|
||||||
|
@ -140,7 +140,7 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
},
|
},
|
||||||
"two_jobs_in_target.job.yml": {
|
"two_jobs_in_target.job.yml": {
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "We recommend only defining a single job in a file with the .job.yml extension.",
|
Summary: "We recommend only defining 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",
|
Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n",
|
||||||
Locations: []dyn.Location{
|
Locations: []dyn.Location{
|
||||||
|
@ -154,19 +154,21 @@ func TestProcessIncludeFormatFail(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
b := &bundle.Bundle{
|
t.Run(fileName, func(t *testing.T) {
|
||||||
RootPath: "testdata/format_fail",
|
b := &bundle.Bundle{
|
||||||
Config: config.Root{
|
RootPath: "testdata/format_fail",
|
||||||
Bundle: config.Bundle{
|
Config: config.Root{
|
||||||
Name: "format_test",
|
Bundle: config.Bundle{
|
||||||
|
Name: "format_test",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
}
|
|
||||||
|
|
||||||
m := ProcessInclude(filepath.Join(b.RootPath, fileName), fileName)
|
m := ProcessInclude(filepath.Join(b.RootPath, fileName), fileName)
|
||||||
diags := bundle.Apply(context.Background(), b, m)
|
diags := bundle.Apply(context.Background(), b, m)
|
||||||
require.Len(t, diags, 1)
|
require.Len(t, diags, 1)
|
||||||
assert.Equal(t, expectedDiags, diags)
|
assert.Equal(t, expectedDiags, diags)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }}
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
const infoTemplate = `{{ "Info" | blue }}: {{ .Summary }}
|
const infoTemplate = `{{ "Recommendation" | blue }}: {{ .Summary }}
|
||||||
{{- range $index, $element := .Paths }}
|
{{- range $index, $element := .Paths }}
|
||||||
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }}
|
{{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@ -108,8 +108,8 @@ func buildTrailer(diags diag.Diagnostics) string {
|
||||||
if warnings := len(diags.Filter(diag.Warning)); warnings > 0 {
|
if warnings := len(diags.Filter(diag.Warning)); warnings > 0 {
|
||||||
parts = append(parts, color.YellowString(pluralize(warnings, "warning", "warnings")))
|
parts = append(parts, color.YellowString(pluralize(warnings, "warning", "warnings")))
|
||||||
}
|
}
|
||||||
if infos := len(diags.Filter(diag.Info)); infos > 0 {
|
if recommendations := len(diags.Filter(diag.Recommendation)); recommendations > 0 {
|
||||||
parts = append(parts, color.BlueString(pluralize(infos, "info", "infos")))
|
parts = append(parts, color.BlueString(pluralize(recommendations, "recommendation", "recommendations")))
|
||||||
}
|
}
|
||||||
if len(parts) > 0 {
|
if len(parts) > 0 {
|
||||||
return fmt.Sprintf("Found %s", strings.Join(parts, " and "))
|
return fmt.Sprintf("Found %s", strings.Join(parts, " and "))
|
||||||
|
@ -147,7 +147,7 @@ func renderSummaryTemplate(out io.Writer, b *bundle.Bundle, diags diag.Diagnosti
|
||||||
func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
|
func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) error {
|
||||||
errorT := template.Must(template.New("error").Funcs(renderFuncMap).Parse(errorTemplate))
|
errorT := template.Must(template.New("error").Funcs(renderFuncMap).Parse(errorTemplate))
|
||||||
warningT := template.Must(template.New("warning").Funcs(renderFuncMap).Parse(warningTemplate))
|
warningT := template.Must(template.New("warning").Funcs(renderFuncMap).Parse(warningTemplate))
|
||||||
infoT := template.Must(template.New("info").Funcs(renderFuncMap).Parse(infoTemplate))
|
recommendationT := template.Must(template.New("info").Funcs(renderFuncMap).Parse(infoTemplate))
|
||||||
|
|
||||||
// Print errors and warnings.
|
// Print errors and warnings.
|
||||||
for _, d := range diags {
|
for _, d := range diags {
|
||||||
|
@ -157,8 +157,8 @@ func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics)
|
||||||
t = errorT
|
t = errorT
|
||||||
case diag.Warning:
|
case diag.Warning:
|
||||||
t = warningT
|
t = warningT
|
||||||
case diag.Info:
|
case diag.Recommendation:
|
||||||
t = infoT
|
t = recommendationT
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range d.Locations {
|
for i := range d.Locations {
|
||||||
|
|
|
@ -49,14 +49,14 @@ func TestRenderTextOutput(t *testing.T) {
|
||||||
name: "nil bundle and 1 info",
|
name: "nil bundle and 1 info",
|
||||||
diags: diag.Diagnostics{
|
diags: diag.Diagnostics{
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "info",
|
Summary: "recommendation",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
opts: RenderOptions{RenderSummaryTable: true},
|
opts: RenderOptions{RenderSummaryTable: true},
|
||||||
expected: "Info: info\n" +
|
expected: "Recommendation: recommendation\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Found 1 info\n",
|
"Found 1 recommendation\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bundle during 'load' and 1 error",
|
name: "bundle during 'load' and 1 error",
|
||||||
|
@ -119,8 +119,8 @@ func TestRenderTextOutput(t *testing.T) {
|
||||||
Locations: []dyn.Location{{File: "foo.py", Line: 3, Column: 1}},
|
Locations: []dyn.Location{{File: "foo.py", Line: 3, Column: 1}},
|
||||||
},
|
},
|
||||||
diag.Diagnostic{
|
diag.Diagnostic{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "info (4)",
|
Summary: "recommendation (4)",
|
||||||
Detail: "detail (4)",
|
Detail: "detail (4)",
|
||||||
Locations: []dyn.Location{{File: "foo.py", Line: 4, Column: 1}},
|
Locations: []dyn.Location{{File: "foo.py", Line: 4, Column: 1}},
|
||||||
},
|
},
|
||||||
|
@ -141,7 +141,7 @@ func TestRenderTextOutput(t *testing.T) {
|
||||||
"\n" +
|
"\n" +
|
||||||
"detail (3)\n" +
|
"detail (3)\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Info: info (4)\n" +
|
"Recommendation: recommendation (4)\n" +
|
||||||
" in foo.py:4:1\n" +
|
" in foo.py:4:1\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"detail (4)\n" +
|
"detail (4)\n" +
|
||||||
|
@ -149,7 +149,7 @@ func TestRenderTextOutput(t *testing.T) {
|
||||||
"Name: test-bundle\n" +
|
"Name: test-bundle\n" +
|
||||||
"Target: test-target\n" +
|
"Target: test-target\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Found 2 errors and 1 warning and 1 info\n",
|
"Found 2 errors and 1 warning and 1 recommendation\n",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "bundle during 'init'",
|
name: "bundle during 'init'",
|
||||||
|
@ -198,8 +198,8 @@ func TestRenderTextOutput(t *testing.T) {
|
||||||
Locations: []dyn.Location{{File: "foo.py", Line: 3, Column: 1}},
|
Locations: []dyn.Location{{File: "foo.py", Line: 3, Column: 1}},
|
||||||
},
|
},
|
||||||
diag.Diagnostic{
|
diag.Diagnostic{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "info (3)",
|
Summary: "recommendation (3)",
|
||||||
Detail: "detail (3)",
|
Detail: "detail (3)",
|
||||||
Locations: []dyn.Location{{File: "foo.py", Line: 5, Column: 1}},
|
Locations: []dyn.Location{{File: "foo.py", Line: 5, Column: 1}},
|
||||||
},
|
},
|
||||||
|
@ -215,7 +215,7 @@ func TestRenderTextOutput(t *testing.T) {
|
||||||
"\n" +
|
"\n" +
|
||||||
"detail (2)\n" +
|
"detail (2)\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"Info: info (3)\n" +
|
"Recommendation: recommendation (3)\n" +
|
||||||
" in foo.py:5:1\n" +
|
" in foo.py:5:1\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"detail (3)\n" +
|
"detail (3)\n" +
|
||||||
|
@ -343,7 +343,7 @@ func TestRenderDiagnostics(t *testing.T) {
|
||||||
name: "info with multiple paths and locations",
|
name: "info with multiple paths and locations",
|
||||||
diags: diag.Diagnostics{
|
diags: diag.Diagnostics{
|
||||||
{
|
{
|
||||||
Severity: diag.Info,
|
Severity: diag.Recommendation,
|
||||||
Summary: "summary",
|
Summary: "summary",
|
||||||
Detail: "detail",
|
Detail: "detail",
|
||||||
Paths: []dyn.Path{
|
Paths: []dyn.Path{
|
||||||
|
@ -356,7 +356,7 @@ func TestRenderDiagnostics(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
expected: "Info: summary\n" +
|
expected: "Recommendation: summary\n" +
|
||||||
" at resources.jobs.xxx\n" +
|
" at resources.jobs.xxx\n" +
|
||||||
" resources.jobs.yyy\n" +
|
" resources.jobs.yyy\n" +
|
||||||
" in foo.yaml:1:2\n" +
|
" in foo.yaml:1:2\n" +
|
||||||
|
|
|
@ -6,4 +6,5 @@ const (
|
||||||
Error Severity = iota
|
Error Severity = iota
|
||||||
Warning
|
Warning
|
||||||
Info
|
Info
|
||||||
|
Recommendation
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue