diff --git a/bundle/config/loader/process_include.go b/bundle/config/loader/process_include.go index 1e1a62147..411279d71 100644 --- a/bundle/config/loader/process_include.go +++ b/bundle/config/loader/process_include.go @@ -131,7 +131,7 @@ func validateSingleResourceDefined(configRoot dyn.Value, ext, typ string) diag.D 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), Detail: detail.String(), Locations: locations, diff --git a/bundle/config/loader/process_include_test.go b/bundle/config/loader/process_include_test.go index 1b90b19a0..b9c84b6d4 100644 --- a/bundle/config/loader/process_include_test.go +++ b/bundle/config/loader/process_include_test.go @@ -65,7 +65,7 @@ func TestProcessIncludeFormatFail(t *testing.T) { for fileName, expectedDiags := range map[string]diag.Diagnostics{ "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.", Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n", Locations: []dyn.Location{ @@ -80,12 +80,12 @@ func TestProcessIncludeFormatFail(t *testing.T) { }, "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.", Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - pipeline1 (pipeline)\n", 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: 5, Column: 7}, + {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: 4, Column: 7}, }, Paths: []dyn.Path{ dyn.MustPathFromString("resources.pipelines.pipeline1"), @@ -95,12 +95,12 @@ func TestProcessIncludeFormatFail(t *testing.T) { }, "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.", Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - pipeline1 (pipeline)\n", 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: 5, Column: 7}, + {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: 4, Column: 7}, }, Paths: []dyn.Path{ dyn.MustPathFromString("resources.pipelines.pipeline1"), @@ -110,12 +110,12 @@ func TestProcessIncludeFormatFail(t *testing.T) { }, "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.", Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n", 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: 8, 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: 7, Column: 7}, }, Paths: []dyn.Path{ dyn.MustPathFromString("resources.jobs.job1"), @@ -125,12 +125,12 @@ func TestProcessIncludeFormatFail(t *testing.T) { }, "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.", Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n", 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: 5, Column: 7}, + {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: 4, Column: 7}, }, Paths: []dyn.Path{ dyn.MustPathFromString("resources.jobs.job1"), @@ -140,7 +140,7 @@ func TestProcessIncludeFormatFail(t *testing.T) { }, "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.", Detail: "The following resources are defined or configured in this file:\n - job1 (job)\n - job2 (job)\n", Locations: []dyn.Location{ @@ -154,19 +154,21 @@ func TestProcessIncludeFormatFail(t *testing.T) { }, }, } { - b := &bundle.Bundle{ - RootPath: "testdata/format_fail", - Config: config.Root{ - Bundle: config.Bundle{ - Name: "format_test", + t.Run(fileName, func(t *testing.T) { + b := &bundle.Bundle{ + RootPath: "testdata/format_fail", + Config: config.Root{ + Bundle: config.Bundle{ + Name: "format_test", + }, }, - }, - } + } - m := ProcessInclude(filepath.Join(b.RootPath, fileName), fileName) - diags := bundle.Apply(context.Background(), b, m) - require.Len(t, diags, 1) - assert.Equal(t, expectedDiags, diags) + m := ProcessInclude(filepath.Join(b.RootPath, fileName), fileName) + diags := bundle.Apply(context.Background(), b, m) + require.Len(t, diags, 1) + assert.Equal(t, expectedDiags, diags) + }) } } diff --git a/bundle/render/render_text_output.go b/bundle/render/render_text_output.go index 529be8073..772781d7a 100644 --- a/bundle/render/render_text_output.go +++ b/bundle/render/render_text_output.go @@ -56,7 +56,7 @@ const warningTemplate = `{{ "Warning" | yellow }}: {{ .Summary }} ` -const infoTemplate = `{{ "Info" | blue }}: {{ .Summary }} +const infoTemplate = `{{ "Recommendation" | blue }}: {{ .Summary }} {{- range $index, $element := .Paths }} {{ if eq $index 0 }}at {{else}} {{ end}}{{ $element.String | green }} {{- end }} @@ -108,8 +108,8 @@ func buildTrailer(diags diag.Diagnostics) string { if warnings := len(diags.Filter(diag.Warning)); warnings > 0 { parts = append(parts, color.YellowString(pluralize(warnings, "warning", "warnings"))) } - if infos := len(diags.Filter(diag.Info)); infos > 0 { - parts = append(parts, color.BlueString(pluralize(infos, "info", "infos"))) + if recommendations := len(diags.Filter(diag.Recommendation)); recommendations > 0 { + parts = append(parts, color.BlueString(pluralize(recommendations, "recommendation", "recommendations"))) } if len(parts) > 0 { 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 { errorT := template.Must(template.New("error").Funcs(renderFuncMap).Parse(errorTemplate)) 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. for _, d := range diags { @@ -157,8 +157,8 @@ func renderDiagnostics(out io.Writer, b *bundle.Bundle, diags diag.Diagnostics) t = errorT case diag.Warning: t = warningT - case diag.Info: - t = infoT + case diag.Recommendation: + t = recommendationT } for i := range d.Locations { diff --git a/bundle/render/render_text_output_test.go b/bundle/render/render_text_output_test.go index 8d72298f4..86321e0f1 100644 --- a/bundle/render/render_text_output_test.go +++ b/bundle/render/render_text_output_test.go @@ -49,14 +49,14 @@ func TestRenderTextOutput(t *testing.T) { name: "nil bundle and 1 info", diags: diag.Diagnostics{ { - Severity: diag.Info, - Summary: "info", + Severity: diag.Recommendation, + Summary: "recommendation", }, }, opts: RenderOptions{RenderSummaryTable: true}, - expected: "Info: info\n" + + expected: "Recommendation: recommendation\n" + "\n" + - "Found 1 info\n", + "Found 1 recommendation\n", }, { 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}}, }, diag.Diagnostic{ - Severity: diag.Info, - Summary: "info (4)", + Severity: diag.Recommendation, + Summary: "recommendation (4)", Detail: "detail (4)", Locations: []dyn.Location{{File: "foo.py", Line: 4, Column: 1}}, }, @@ -141,7 +141,7 @@ func TestRenderTextOutput(t *testing.T) { "\n" + "detail (3)\n" + "\n" + - "Info: info (4)\n" + + "Recommendation: recommendation (4)\n" + " in foo.py:4:1\n" + "\n" + "detail (4)\n" + @@ -149,7 +149,7 @@ func TestRenderTextOutput(t *testing.T) { "Name: test-bundle\n" + "Target: test-target\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'", @@ -198,8 +198,8 @@ func TestRenderTextOutput(t *testing.T) { Locations: []dyn.Location{{File: "foo.py", Line: 3, Column: 1}}, }, diag.Diagnostic{ - Severity: diag.Info, - Summary: "info (3)", + Severity: diag.Recommendation, + Summary: "recommendation (3)", Detail: "detail (3)", Locations: []dyn.Location{{File: "foo.py", Line: 5, Column: 1}}, }, @@ -215,7 +215,7 @@ func TestRenderTextOutput(t *testing.T) { "\n" + "detail (2)\n" + "\n" + - "Info: info (3)\n" + + "Recommendation: recommendation (3)\n" + " in foo.py:5:1\n" + "\n" + "detail (3)\n" + @@ -343,7 +343,7 @@ func TestRenderDiagnostics(t *testing.T) { name: "info with multiple paths and locations", diags: diag.Diagnostics{ { - Severity: diag.Info, + Severity: diag.Recommendation, Summary: "summary", Detail: "detail", 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" + " resources.jobs.yyy\n" + " in foo.yaml:1:2\n" + diff --git a/libs/diag/severity.go b/libs/diag/severity.go index d25c12806..0e88085f5 100644 --- a/libs/diag/severity.go +++ b/libs/diag/severity.go @@ -6,4 +6,5 @@ const ( Error Severity = iota Warning Info + Recommendation )