feat(report): allow user-defined templates (#1650)

This commit is contained in:
Richard Gomez authored and GitHub committed 2024-12-10 18:56:11 -06:00
1 parent e393d299bc
commit 83e99bacf1
72 files changed
+586 -549

No files matched your search

+18 -97
View File
@@ -6,110 +6,31 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zricethezav/gitleaks/v8/config"
)
const (
expectPath = "../testdata/expected/"
)
const expectPath = "../testdata/expected/"
const configPath = "../testdata/config/"
const templatePath = "../testdata/report/"
func TestReport(t *testing.T) {
tests := []struct {
findings []Finding
ext string
wantEmpty bool
}{
func TestWriteStdout(t *testing.T) {
// Arrange
reporter := JsonReporter{}
buf := testWriter{
bytes.NewBuffer(nil),
}
findings := []Finding{
{
ext: "json",
findings: []Finding{
{
RuleID: "test-rule",
},
},
RuleID: "test-rule",
},
{
ext: ".json",
findings: []Finding{
{
RuleID: "test-rule",
},
},
},
{
ext: ".jsonj",
findings: []Finding{
{
RuleID: "test-rule",
},
},
wantEmpty: true,
},
{
ext: ".csv",
findings: []Finding{
{
RuleID: "test-rule",
},
},
},
{
ext: "csv",
findings: []Finding{
{
RuleID: "test-rule",
},
},
},
{
ext: "CSV",
findings: []Finding{
{
RuleID: "test-rule",
},
},
},
{
ext: ".xml",
findings: []Finding{
{
RuleID: "test-rule",
},
},
},
{
ext: "junit",
findings: []Finding{
{
RuleID: "test-rule",
},
},
},
// {
// ext: "SARIF",
// findings: []Finding{
// {
// RuleID: "test-rule",
// },
// },
// },
}
for _, test := range tests {
t.Run(test.ext, func(t *testing.T) {
buf := testWriter{
bytes.NewBuffer(nil),
}
err := Write(test.findings, config.Config{}, test.ext, buf)
require.NoError(t, err)
got := buf.Bytes()
if test.wantEmpty {
assert.Empty(t, got)
return
}
assert.NotEmpty(t, got)
})
}
// Act
err := reporter.Write(buf, findings)
require.NoError(t, err)
got := buf.Bytes()
// Assert
assert.NotEmpty(t, got)
}
type testWriter struct {