You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.0 KiB

  1. package jsonrpc
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestError(t *testing.T) {
  8. var err interface{} = &Error{}
  9. _, ok := err.(error)
  10. require.True(t, ok)
  11. }
  12. func TestError_Error(t *testing.T) {
  13. err := &Error{
  14. Code: ErrorCode(100),
  15. Message: "test",
  16. Data: map[string]string{
  17. "test": "test",
  18. },
  19. }
  20. assert.Equal(t, "jsonrpc: code: 100, message: test, data: map[test:test]", err.Error())
  21. }
  22. func TestErrParse(t *testing.T) {
  23. err := ErrParse()
  24. require.Equal(t, ErrorCodeParse, err.Code)
  25. }
  26. func TestErrInvalidRequest(t *testing.T) {
  27. err := ErrInvalidRequest()
  28. require.Equal(t, ErrorCodeInvalidRequest, err.Code)
  29. }
  30. func TestErrMethodNotFound(t *testing.T) {
  31. err := ErrMethodNotFound()
  32. require.Equal(t, ErrorCodeMethodNotFound, err.Code)
  33. }
  34. func TestErrInvalidParams(t *testing.T) {
  35. err := ErrInvalidParams()
  36. require.Equal(t, ErrorCodeInvalidParams, err.Code)
  37. }
  38. func TestErrInternal(t *testing.T) {
  39. err := ErrInternal()
  40. require.Equal(t, ErrorCodeInternal, err.Code)
  41. }