-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change JUnit terraform test
output to include test failure details inside <failure>
elements, use the error message as the message
attribute
#36316
Conversation
fb0eeb7
to
1437843
Compare
Questions for the reviewer:
|
@@ -1,17 +1,16 @@ | |||
<?xml version="1.0" encoding="UTF-8"?><testsuites> | |||
<testsuite name="main.tftest.hcl" tests="2" skipped="0" failures="1" errors="0"> | |||
<testcase name="failing_assertion" classname="main.tftest.hcl" time="TIME_REDACTED" timestamp="TIMESTAMP_REDACTED"> | |||
<failure message="Test run failed"></failure> | |||
<failure message="local variable 'number' has a value greater than zero, so assertion 2 will fail"><![CDATA[Test failed on assertion 2 of 3]]></failure> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings will contain HTML character references, depending on the message. I assume the tools using the XML will parse this fine.
terraform test
output to include test failure details in <failure>
elementsterraform test
output to include test failure details inside <failure>
elements, use the error message as the message
attribute
… attribute is set
338114b
to
080505c
Compare
// From internal/backend/remote-state/s3/testing_test.go | ||
// diagnosticComparer is a Comparer function for use with cmp.Diff to compare two tfdiags.Diagnostic values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should/could this be moved into the tfdiags package? Or are there other ways that diagnostics are compared in the code base that are a better option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think moving it into tfdiags
is a good idea!
We could follow the pattern of ctydebug - https://github.com/zclconf/go-cty-debug/blob/0d6042c539401a57fc0cca85ded2861d4a5173c4/ctydebug/cmp.go#L19-L42 I don't mean the implementation necessarily but more the fact that it exports a cmp.Option
variable which can be directly used as an argument in cmp.Diff
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Feel free to merge and leave the in-line comments for a separate PR at some point later.
// From internal/backend/remote-state/s3/testing_test.go | ||
// diagnosticComparer is a Comparer function for use with cmp.Diff to compare two tfdiags.Diagnostic values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think moving it into tfdiags
is a good idea!
We could follow the pattern of ctydebug - https://github.com/zclconf/go-cty-debug/blob/0d6042c539401a57fc0cca85ded2861d4a5173c4/ctydebug/cmp.go#L19-L42 I don't mean the implementation necessarily but more the fact that it exports a cmp.Option
variable which can be directly used as an argument in cmp.Diff
.
@@ -67,6 +70,65 @@ func Test_TestJUnitXMLFile_save(t *testing.T) { | |||
} | |||
} | |||
|
|||
func Test_getWarnings(t *testing.T) { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func getWarnings(diags tfdiags.Diagnostics) tfdiags.Diagnostics { | ||
// Collect warnings | ||
warnDiags := tfdiags.Diagnostics{} | ||
if diags.HasWarnings() { | ||
for _, d := range diags { | ||
if d.Severity() == tfdiags.Warning { | ||
warnDiags = warnDiags.Append(d) | ||
} | ||
} | ||
} | ||
return warnDiags | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick - AFAICT the code here would work just as well without HasWarnings()
- it would return empty slice as nothing would be appended.
On a separate note I am somewhat surprised we don't have Warnings()
method yet on tfdiags.Diagnostics
- so I think it may be another candidate for logic to extract there and just call from here but feel free to leave this for another PR if you like.
Thanks! I'll address those in follow-up PRs like you suggested; as long as this PR's changes are in 1.11 then any refactors can be kept on main/in 1.12. As well as those comments I'll address this feedback about making test assertion failure diags more easily identify-able. |
This PR
message
attribute on a<failure>
element to summarise how many assertions are failing out of a given total, and includes the first failed assertion's error message.Related:
Target Release
1.11.x
CHANGELOG entry
This change relates to a feature that isn't released yet