4
0

report_test.go 793 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package report
  2. import (
  3. "bytes"
  4. "strings"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. const expectPath = "../testdata/expected/"
  10. const templatePath = "../testdata/report/"
  11. func TestWriteStdout(t *testing.T) {
  12. // Arrange
  13. reporter := JsonReporter{}
  14. buf := testWriter{
  15. bytes.NewBuffer(nil),
  16. }
  17. findings := []Finding{
  18. {
  19. RuleID: "test-rule",
  20. },
  21. }
  22. // Act
  23. err := reporter.Write(buf, findings)
  24. require.NoError(t, err)
  25. got := buf.Bytes()
  26. // Assert
  27. assert.NotEmpty(t, got)
  28. }
  29. type testWriter struct {
  30. *bytes.Buffer
  31. }
  32. func (t testWriter) Close() error {
  33. return nil
  34. }
  35. // lineEndingReplacer normalizes CRLF to LF so tests pass on Windows.
  36. var lineEndingReplacer = strings.NewReplacer(
  37. "\\r\\n", "\\n",
  38. "\r", "",
  39. "\\r", "",
  40. )