custom_error_test.go 521 B

123456789101112131415161718192021222324
  1. package xerr
  2. import (
  3. "io"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestCustomError(t *testing.T) {
  9. _, got := IsCustomError(Custom("test"))
  10. assert.True(t, got)
  11. _, got = IsCustomError(Customf("test %d", time.Now().Unix()))
  12. assert.True(t, got)
  13. _, got = IsCustomError(io.EOF)
  14. assert.False(t, got)
  15. assert.Error(t, IgnoreDuplicateEntryError(io.EOF))
  16. assert.NoError(t, IgnoreDuplicateEntryError(Custom("Duplicate entry UQE-x-y"), "a"))
  17. assert.NoError(t, IgnoreDuplicateEntryError(nil))
  18. }