2021-04-12 17:16:09 +03:00
|
|
|
package toml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2021-09-24 00:29:28 +03:00
|
|
|
|
2021-10-25 20:26:12 +03:00
|
|
|
"go.unistack.org/micro/v3/codec"
|
2021-04-12 17:16:09 +03:00
|
|
|
)
|
|
|
|
|
2021-09-24 00:29:28 +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 `toml:"name" codec:"flatten"`
|
|
|
|
}{
|
|
|
|
One: "xx",
|
|
|
|
Name: &codec.Frame{Data: []byte("test")},
|
|
|
|
}
|
|
|
|
|
2024-09-17 12:23:05 +03:00
|
|
|
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
2021-09-24 00:29:28 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(buf, []byte(`test`)) {
|
|
|
|
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
|
|
|
}
|
|
|
|
}
|