Skip to content
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

Prevent adding both skipped and failure elements #1123

Merged
merged 2 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions pkg/writer/junit_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,22 @@ func violationsToTestCases(violations []*results.Violation, isSkipped bool) []JU
for _, v := range violations {
var testCase JUnitTestCase
if isSkipped {
testCase = JUnitTestCase{Failure: new(JUnitFailure), SkipMessage: new(JUnitSkipMessage)}
testCase.SkipMessage.Message = v.Comment
testCase = JUnitTestCase{SkipMessage: new(JUnitSkipMessage)}
// since junitXML doesn't contain the attributes we want to show as violations
// we would add details of violations in the skip message, with any provided skip comment
if v.Comment != "" {
testCase.SkipMessage.Message = v.Comment
}
} else {
testCase = JUnitTestCase{Failure: new(JUnitFailure)}
// since junitXML doesn't contain the attributes we want to show as violations
// we would add details of violations in the failure message
testCase.Failure.Message = getViolationString(*v)
}
testCase.Classname = v.File
testCase.Name = fmt.Sprintf(testNameFormatFailed, v.ResourceName, v.LineNumber, v.RuleID)
testCase.Severity = v.Severity
testCase.Category = v.Category
// since junitXML doesn't contain the attributes we want to show as violations
// we would add details of violations in the failure message
testCase.Failure.Message = getViolationString(*v)
testCases = append(testCases, testCase)
}
return testCases
Expand Down
1 change: 0 additions & 1 deletion pkg/writer/junit_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func TestJUnitXMLWriter(t *testing.T) {
</testcase>
<testcase classname="modules/m1/main.tf" name="[ERROR] resource: &#34;bucket&#34; at line: 20, violates: RULE - AWS.S3Bucket.DS.High.1043" severity="HIGH" category="S3">
<skipped message=""></skipped>
<failure message="Description: S3 bucket Access is allowed to all AWS Account Users., File: modules/m1/main.tf, Line: 20, Severity: HIGH, Rule Name: s3EnforceUserACL, Rule ID: AWS.S3Bucket.DS.High.1043, Resource Name: bucket, Resource Type: aws_s3_bucket, Category: S3" type=""></failure>
</testcase>
</testsuite>
</testsuites>
Expand Down