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

package jsonrpc
import (
"testing"
"github.com/intel-go/fastjson"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUnmarshal(t *testing.T) {
err := Unmarshal(nil, nil)
require.IsType(t, &Error{}, err)
assert.Equal(t, ErrorCodeInvalidParams, err.Code)
src := fastjson.RawMessage([]byte(`{"name":"john"}`))
Unmarshal(&src, nil)
require.IsType(t, &Error{}, err)
assert.Equal(t, ErrorCodeInvalidParams, err.Code)
dst := struct {
Name string `json:"name"`
}{}
err = Unmarshal(&src, &dst)
require.Nil(t, err)
assert.Equal(t, "john", dst.Name)
}