2021-04-12 16:52:10 +03:00
|
|
|
package yaml
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"testing"
|
2021-09-24 00:16:06 +03:00
|
|
|
|
2021-10-25 20:30:38 +03:00
|
|
|
"go.unistack.org/micro/v3/codec"
|
2021-04-12 16:52:10 +03:00
|
|
|
)
|
|
|
|
|
2021-09-24 00:16:06 +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 `yaml:"name" codec:"flatten"`
|
|
|
|
}{
|
|
|
|
One: "xx",
|
|
|
|
Name: &codec.Frame{Data: []byte("test")},
|
|
|
|
}
|
|
|
|
|
2024-09-17 12:16:07 +03:00
|
|
|
buf, err := NewCodec(codec.Flatten(true)).Marshal(s)
|
2021-09-24 00:16:06 +03:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !bytes.Equal(buf, []byte(`test`)) {
|
|
|
|
t.Fatalf("bytes not equal %s != %s", buf, `test`)
|
|
|
|
}
|
|
|
|
}
|
2024-09-30 20:21:09 +03:00
|
|
|
|
|
|
|
func TestNativeYamlTags(t *testing.T) {
|
|
|
|
s := &struct {
|
|
|
|
One string `yaml:"first"`
|
|
|
|
}{
|
|
|
|
One: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
err := NewCodec().Unmarshal([]byte(`first: "val"`), s)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if s.One != "val" {
|
|
|
|
t.Fatalf("XXX %#+v\n", s)
|
|
|
|
}
|
|
|
|
}
|