fix: init empty result slice for SARIF printer (#4758)
Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
parent
6456cbda82
commit
817316680f
@ -70,6 +70,7 @@ func NewSarif(w io.Writer) *Sarif {
|
||||
func (p Sarif) Print(issues []result.Issue) error {
|
||||
run := sarifRun{}
|
||||
run.Tool.Driver.Name = "golangci-lint"
|
||||
run.Results = make([]sarifResult, 0)
|
||||
|
||||
for i := range issues {
|
||||
issue := issues[i]
|
||||
|
@ -65,3 +65,17 @@ func TestSarif_Print(t *testing.T) {
|
||||
|
||||
assert.Equal(t, expected, buf.String())
|
||||
}
|
||||
|
||||
func TestSarif_Print_empty(t *testing.T) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
printer := NewSarif(buf)
|
||||
|
||||
err := printer.Print(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
expected := `{"version":"2.1.0","$schema":"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json","runs":[{"tool":{"driver":{"name":"golangci-lint"}},"results":[]}]}
|
||||
`
|
||||
|
||||
assert.Equal(t, expected, buf.String())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user