error_test.go 786 B

1234567891011121314151617181920212223
  1. package krberror
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestErrorf(t *testing.T) {
  8. err := fmt.Errorf("an error")
  9. var a Krberror
  10. a = Errorf(err, "cause", "some text")
  11. assert.Equal(t, "[Root cause: cause] cause: some text: an error", a.Error())
  12. a = Errorf(err, "cause", "arg1=%d arg2=%s", 123, "arg")
  13. assert.Equal(t, "[Root cause: cause] cause: arg1=123 arg2=arg: an error", a.Error())
  14. err = NewErrorf("another error", "some text")
  15. a = Errorf(err, "cause", "some text")
  16. assert.Equal(t, "[Root cause: another error] cause: some text < another error: some text", a.Error())
  17. a = Errorf(err, "cause", "arg1=%d arg2=%s", 123, "arg")
  18. assert.Equal(t, "[Root cause: another error] cause: arg1=123 arg2=arg < another error: some text", a.Error())
  19. }