report_test.go 663 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package report
  2. import (
  3. "bytes"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. const expectPath = "../testdata/expected/"
  9. const configPath = "../testdata/config/"
  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. }