| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- package report
- import (
- "os"
- "path/filepath"
- "strconv"
- "testing"
- "github.com/stretchr/testify/assert"
- "github.com/stretchr/testify/require"
- "github.com/zricethezav/gitleaks/v8/config"
- )
- const (
- expectPath = "../testdata/expected/"
- )
- func TestReport(t *testing.T) {
- tests := []struct {
- findings []Finding
- ext string
- wantEmpty bool
- }{
- {
- ext: "json",
- findings: []Finding{
- {
- 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 i, test := range tests {
- t.Run(test.ext, func(t *testing.T) {
- tmpfile, err := os.Create(filepath.Join(t.TempDir(), strconv.Itoa(i)+test.ext))
- require.NoError(t, err)
- err = Write(test.findings, config.Config{}, test.ext, tmpfile.Name())
- require.NoError(t, err)
- got, err := os.ReadFile(tmpfile.Name())
- require.NoError(t, err)
- assert.FileExists(t, tmpfile.Name())
- if test.wantEmpty {
- assert.Empty(t, got)
- return
- }
- assert.NotEmpty(t, got)
- })
- }
- }
|