Skip to content

Commit 731d0d5

Browse files
authored
Results must always be present in the SARIF report (#650)
* Don't omit empty results * Add tests
1 parent 3c230ac commit 731d0d5

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

report/sarif/sarif_suite_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package sarif_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestRules(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "Sarif Formatters Suite")
13+
}

report/sarif/sarif_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package sarif_test
2+
3+
import (
4+
"bytes"
5+
6+
. "github.com/onsi/ginkgo"
7+
. "github.com/onsi/gomega"
8+
"github.com/securego/gosec/v2"
9+
"github.com/securego/gosec/v2/report/sarif"
10+
)
11+
12+
var _ = Describe("Sarif Formatter", func() {
13+
BeforeEach(func() {
14+
})
15+
Context("when converting to Sarif issues", func() {
16+
It("sarif formatted report should contain the result", func() {
17+
buf := new(bytes.Buffer)
18+
reportInfo := gosec.NewReportInfo([]*gosec.Issue{}, &gosec.Metrics{}, map[string][]gosec.Error{}).WithVersion("v2.7.0")
19+
err := sarif.WriteReport(buf, reportInfo, []string{})
20+
result := buf.String()
21+
Expect(err).ShouldNot(HaveOccurred())
22+
Expect(result).To(ContainSubstring("\"results\": ["))
23+
})
24+
})
25+
})

report/sarif/types.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)