RawMessage support

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2026-03-09 18:52:37 +03:00
parent 73d616e3d0
commit 35d22d9f8b
4 changed files with 61 additions and 40 deletions

View File

@@ -4,7 +4,9 @@ import (
"bytes"
"testing"
yamlc "github.com/goccy/go-yaml"
"go.unistack.org/micro/v4/codec"
utime "go.unistack.org/micro/v4/util/time"
)
func TestFrame(t *testing.T) {
@@ -52,3 +54,33 @@ func TestNativeYamlTags(t *testing.T) {
t.Fatalf("XXX %#+v\n", s)
}
}
func TestDuration(t *testing.T) {
s := &struct {
One utime.Duration `yaml:"timeout"`
}{
One: 0,
}
err := NewCodec().Unmarshal([]byte(`timeout: "5s"`), s)
if err != nil {
t.Fatal(err)
}
if s.One != 5000000000 {
t.Fatal("invalid duration parsed")
}
}
func TestRawMessage(t *testing.T) {
s := &struct {
One *yamlc.RawMessage `yaml:"one"`
}{}
err := NewCodec().Unmarshal([]byte(`---
one:
two:
- test`), s)
if err != nil {
t.Fatal(err)
}
t.Logf("s %s", s.One)
}