1
0

errutil_test.go 859 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package errutil
  2. import (
  3. "testing"
  4. "github.com/cockroachdb/errors"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. type notFoundError struct {
  8. val bool
  9. }
  10. func (notFoundError) Error() string {
  11. return "not found"
  12. }
  13. func (e notFoundError) NotFound() bool {
  14. return e.val
  15. }
  16. func TestIsNotFound(t *testing.T) {
  17. tests := []struct {
  18. name string
  19. err error
  20. expVal bool
  21. }{
  22. {
  23. name: "error does not implement NotFound",
  24. err: errors.New("a simple error"),
  25. expVal: false,
  26. },
  27. {
  28. name: "error implements NotFound but not a not found",
  29. err: notFoundError{val: false},
  30. expVal: false,
  31. },
  32. {
  33. name: "error implements NotFound",
  34. err: notFoundError{val: true},
  35. expVal: true,
  36. },
  37. }
  38. for _, test := range tests {
  39. t.Run(test.name, func(t *testing.T) {
  40. assert.Equal(t, test.expVal, IsNotFound(test.err))
  41. })
  42. }
  43. }