github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/core/common/check/check_test.go (about)

     1  package check
     2  
     3  import (
     4  	"github.com/nyan233/littlerpc/core/middle/codec"
     5  	"github.com/stretchr/testify/assert"
     6  	"testing"
     7  )
     8  
     9  func TestCheckCoderType(t *testing.T) {
    10  	_, err := UnMarshalFromUnsafe(&codec.Json{}, nil, nil)
    11  	if err != nil {
    12  		t.Fatal(err)
    13  	}
    14  	_, err = UnMarshalFromUnsafe(&codec.Json{}, nil, map[string]string{})
    15  	if err != nil {
    16  		t.Fatal(err)
    17  	}
    18  	bytes := []byte("{\"hello\":\"123\",\"dd\":\"456\"}")
    19  	var testData map[string]string
    20  	comparaData := map[string]string{
    21  		"hello": "123",
    22  		"dd":    "456",
    23  	}
    24  	uTestData, err := UnMarshalFromUnsafe(&codec.Json{}, bytes, testData)
    25  	if err != nil {
    26  		t.Fatal(err)
    27  	}
    28  	assert.Equal(t, uTestData, comparaData)
    29  	uTestData, err = UnMarshalFromUnsafe(&codec.Json{}, bytes, &testData)
    30  	if err != nil {
    31  		t.Fatal(err)
    32  	}
    33  	assert.Equal(t, uTestData, &comparaData)
    34  	uTestData, err = UnMarshalFromUnsafe(&codec.Json{}, bytes, nil)
    35  	if err != nil {
    36  		t.Fatal(err)
    37  	}
    38  }