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.
35 lines
635 B
35 lines
635 B
package proto
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
|
|
testData "github.com/go-kratos/kratos/v2/internal/testdata/encoding"
|
|
)
|
|
|
|
func TestName(t *testing.T) {
|
|
c := new(codec)
|
|
assert.Equal(t, c.Name(), "proto")
|
|
}
|
|
|
|
func TestCodec(t *testing.T) {
|
|
c := new(codec)
|
|
|
|
model := testData.TestModel{
|
|
Id: 1,
|
|
Name: "kratos",
|
|
Hobby: []string{"study", "eat", "play"},
|
|
}
|
|
|
|
m, err := c.Marshal(&model)
|
|
assert.Nil(t, err)
|
|
|
|
var res testData.TestModel
|
|
|
|
err = c.Unmarshal(m, &res)
|
|
assert.Nil(t, err)
|
|
|
|
assert.Equal(t, res.Id, model.Id)
|
|
assert.Equal(t, res.Name, model.Name)
|
|
assert.Equal(t, res.Hobby, model.Hobby)
|
|
}
|
|
|