feat: use STDOUT when report file not specified (#1642)

* feat: use STDOUT when report file not specified

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

* fix: update tests

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

* fix: use only '-' for stdout report

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>

---------

Signed-off-by: Bryce Thuilot <bryce@thuilot.io>
This commit is contained in:
Bryce Thuilot authored and GitHub committed 2024-12-05 09:44:07 -06:00
1 parent ed205a5f63
commit f3adda07ca
3 files changed
+33 -22

No files matched your search

+15 -10
View File
@@ -1,9 +1,7 @@
package report
import (
"os"
"path/filepath"
"strconv"
"bytes"
"testing"
"github.com/stretchr/testify/assert"
@@ -97,15 +95,14 @@ func TestReport(t *testing.T) {
// },
}
for i, test := range tests {
for _, test := range tests {
t.Run(test.ext, func(t *testing.T) {
tmpfile, err := os.Create(filepath.Join(t.TempDir(), strconv.Itoa(i)+test.ext))
buf := testWriter{
bytes.NewBuffer(nil),
}
err := Write(test.findings, config.Config{}, test.ext, buf)
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())
got := buf.Bytes()
if test.wantEmpty {
assert.Empty(t, got)
return
@@ -114,3 +111,11 @@ func TestReport(t *testing.T) {
})
}
}
type testWriter struct {
*bytes.Buffer
}
func (t testWriter) Close() error {
return nil
}