Skip to content
Closed
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ require (
github.com/ryanrolds/sqlclosecheck v0.5.1
github.com/sanposhiho/wastedassign/v2 v2.0.7
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/santhosh-tekuri/jsonschema/v6 v6.0.1
github.com/sashamelentyev/interfacebloat v1.1.0
github.com/sashamelentyev/usestdlibvars v1.27.0
github.com/securego/gosec/v2 v2.20.1-0.20240525090044-5f0084eb01a9
Expand Down
4 changes: 4 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions pkg/printers/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,38 @@ package printers
import (
"bytes"
"go/token"
"io"
"testing"

"github.com/santhosh-tekuri/jsonschema/v6"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/golangci/golangci-lint/pkg/result"
)

var sarifSchema *jsonschema.Schema

func RequireSarifSchema(t *testing.T) *jsonschema.Schema {
t.Helper()
if sarifSchema == nil {
c := jsonschema.NewCompiler()
var err error
sarifSchema, err = c.Compile("./testdata/sarif-2.1.0-rtm.6.json")
require.NoError(t, err)
}
return sarifSchema
}

func ValidateSarifSchema(t *testing.T, reader io.Reader) {
t.Helper()
inst, err := jsonschema.UnmarshalJSON(reader)
require.NoError(t, err)

err = RequireSarifSchema(t).Validate(inst)
require.NoError(t, err)
}

func TestSarif_Print(t *testing.T) {
issues := []result.Issue{
{
Expand Down Expand Up @@ -74,6 +98,7 @@ func TestSarif_Print(t *testing.T) {
`

assert.Equal(t, expected, buf.String())
ValidateSarifSchema(t, buf)
}

func TestSarif_Print_empty(t *testing.T) {
Expand All @@ -88,4 +113,5 @@ func TestSarif_Print_empty(t *testing.T) {
`

assert.Equal(t, expected, buf.String())
ValidateSarifSchema(t, buf)
}
Loading