-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve converter diagnostic output (#6549)
* Improve converter diagnostic output by including a Footer and removing lower level diagnostics when a configuration fails to generate. Signed-off-by: erikbaranowski <[email protected]> --------- Signed-off-by: erikbaranowski <[email protected]>
- Loading branch information
1 parent
d550490
commit 24c0432
Showing
5 changed files
with
133 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package diag | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDiagReporting(t *testing.T) { | ||
var ( | ||
criticalDiagnostic = Diagnostic{ | ||
Severity: SeverityLevelCritical, | ||
Summary: "this is a critical diag", | ||
} | ||
errorDiagnostic = Diagnostic{ | ||
Severity: SeverityLevelError, | ||
Summary: "this is an error diag", | ||
} | ||
warnDiagnostic = Diagnostic{ | ||
Severity: SeverityLevelWarn, | ||
Summary: "this is a warn diag", | ||
} | ||
infoDiagnostic = Diagnostic{ | ||
Severity: SeverityLevelInfo, | ||
Summary: "this is an info diag", | ||
} | ||
) | ||
|
||
tt := []struct { | ||
name string | ||
diags Diagnostics | ||
bypassErrors bool | ||
expectedMessage string | ||
}{ | ||
{ | ||
name: "Empty", | ||
diags: Diagnostics{}, | ||
expectedMessage: successFooter, | ||
}, | ||
{ | ||
name: "Critical", | ||
diags: Diagnostics{criticalDiagnostic, errorDiagnostic, warnDiagnostic, infoDiagnostic}, | ||
expectedMessage: `(Critical) this is a critical diag` + criticalErrorFooter, | ||
}, | ||
{ | ||
name: "Error", | ||
diags: Diagnostics{errorDiagnostic, warnDiagnostic, infoDiagnostic}, | ||
expectedMessage: `(Error) this is an error diag` + errorFooter, | ||
}, | ||
{ | ||
name: "Bypass Error", | ||
diags: Diagnostics{errorDiagnostic, warnDiagnostic, infoDiagnostic}, | ||
bypassErrors: true, | ||
expectedMessage: `(Error) this is an error diag | ||
(Warning) this is a warn diag | ||
(Info) this is an info diag` + successFooter, | ||
}, | ||
{ | ||
name: "Warn", | ||
diags: Diagnostics{warnDiagnostic, infoDiagnostic}, | ||
expectedMessage: `(Warning) this is a warn diag | ||
(Info) this is an info diag` + successFooter, | ||
}, | ||
{ | ||
name: "Info", | ||
diags: Diagnostics{infoDiagnostic}, | ||
expectedMessage: `(Info) this is an info diag` + successFooter, | ||
}, | ||
} | ||
|
||
for _, tc := range tt { | ||
t.Run(tc.name, func(t *testing.T) { | ||
var buf bytes.Buffer | ||
err := generateTextReport(&buf, tc.diags, tc.bypassErrors) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, tc.expectedMessage, buf.String()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters