reporter.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package httpexpect
  2. import (
  3. "fmt"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. )
  7. // AssertReporter implements Reporter interface using `testify/assert'
  8. // package. Failures are non-fatal with this reporter.
  9. type AssertReporter struct {
  10. backend *assert.Assertions
  11. }
  12. // NewAssertReporter returns a new AssertReporter object.
  13. func NewAssertReporter(t assert.TestingT) *AssertReporter {
  14. return &AssertReporter{assert.New(t)}
  15. }
  16. // Errorf implements Reporter.Errorf.
  17. func (r *AssertReporter) Errorf(message string, args ...interface{}) {
  18. r.backend.Fail(fmt.Sprintf(message, args...))
  19. }
  20. // RequireReporter implements Reporter interface using `testify/require'
  21. // package. Failures fatal with this reporter.
  22. type RequireReporter struct {
  23. backend *require.Assertions
  24. }
  25. // NewRequireReporter returns a new RequireReporter object.
  26. func NewRequireReporter(t require.TestingT) *RequireReporter {
  27. return &RequireReporter{require.New(t)}
  28. }
  29. // Errorf implements Reporter.Errorf.
  30. func (r *RequireReporter) Errorf(message string, args ...interface{}) {
  31. r.backend.FailNow(fmt.Sprintf(message, args...))
  32. }