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.

30 lines
602 B

  1. package jsonrpc
  2. import (
  3. "testing"
  4. "github.com/intel-go/fastjson"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. )
  8. func TestUnmarshal(t *testing.T) {
  9. err := Unmarshal(nil, nil)
  10. require.IsType(t, &Error{}, err)
  11. assert.Equal(t, ErrorCodeInvalidParams, err.Code)
  12. src := fastjson.RawMessage([]byte(`{"name":"john"}`))
  13. Unmarshal(&src, nil)
  14. require.IsType(t, &Error{}, err)
  15. assert.Equal(t, ErrorCodeInvalidParams, err.Code)
  16. dst := struct {
  17. Name string `json:"name"`
  18. }{}
  19. err = Unmarshal(&src, &dst)
  20. require.Nil(t, err)
  21. assert.Equal(t, "john", dst.Name)
  22. }