2021-04-12 17:13:42 +03:00
|
|
|
package proto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2021-09-24 00:24:58 +03:00
|
|
|
|
2023-04-30 10:58:16 +03:00
|
|
|
"go.unistack.org/micro/v4/codec"
|
2021-04-12 17:13:42 +03:00
|
|
|
)
|
|
|
|
|
2021-09-24 00:24:58 +03:00
|
|
|
func TestFrame(t *testing.T) {
|
|
|
|
s := &codec.Frame{Data: []byte("test")}
|
|
|
|
|
|
|
|
buf, err := NewCodec().Marshal(s)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(buf, []byte(`test`)) {
|
|
|
|
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFrameFlatten(t *testing.T) {
|
|
|
|
s := &struct {
|
|
|
|
One string
|
|
|
|
Name *codec.Frame `json:"name" codec:"flatten"`
|
|
|
|
}{
|
|
|
|
One: "xx",
|
|
|
|
Name: &codec.Frame{Data: []byte("test")},
|
|
|
|
}
|
|
|
|
|
|
|
|
buf, err := NewCodec().Marshal(s)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(buf, []byte(`test`)) {
|
|
|
|
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-12 17:13:42 +03:00
|
|
|
func TestReadBody(t *testing.T) {
|
|
|
|
t.Skip("skip as no proto")
|
|
|
|
s := &struct {
|
|
|
|
Name string
|
|
|
|
}{}
|
|
|
|
c := NewCodec()
|
|
|
|
b := bytes.NewReader(nil)
|
|
|
|
err := c.ReadBody(b, s)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|