From 1c0d42f863b108a1cf098a460220c58f4443021d Mon Sep 17 00:00:00 2001 From: Will Scott Date: Wed, 28 Apr 2021 11:29:56 -0700 Subject: [PATCH] secondary round-trip test --- codec/dagjson/roundtripBytes_test.go | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/codec/dagjson/roundtripBytes_test.go b/codec/dagjson/roundtripBytes_test.go index cd0f28f..df4e9f6 100644 --- a/codec/dagjson/roundtripBytes_test.go +++ b/codec/dagjson/roundtripBytes_test.go @@ -40,3 +40,35 @@ func TestRoundtripBytes(t *testing.T) { Wish(t, nb.Build(), ShouldEqual, byteNode) }) } + +var encapsulatedNode = fluent.MustBuildMap(basicnode.Prototype__Map{}, 1, func(na fluent.MapAssembler) { + na.AssembleEntry("/").CreateMap(1, func(sa fluent.MapAssembler) { + sa.AssembleEntry("bytes").AssignBytes([]byte("deadbeef")) + }) +}) +var encapsulatedSerial = `{ + "/": { + "bytes": { + "/": { + "bytes": "ZGVhZGJlZWY=" + } + } + } +} +` + +func TestEncapsulatedBytes(t *testing.T) { + t.Run("encoding", func(t *testing.T) { + var buf bytes.Buffer + err := Encode(encapsulatedNode, &buf) + Require(t, err, ShouldEqual, nil) + Wish(t, buf.String(), ShouldEqual, encapsulatedSerial) + }) + t.Run("decoding", func(t *testing.T) { + buf := strings.NewReader(encapsulatedSerial) + nb := basicnode.Prototype__Map{}.NewBuilder() + err := Decode(nb, buf) + Require(t, err, ShouldEqual, nil) + Wish(t, nb.Build(), ShouldEqual, encapsulatedNode) + }) +} -- GitLab