github.com/ipld/go-ipld-prime@v0.21.0/node/tests/byteSpecs.go (about) 1 package tests 2 3 import ( 4 "io" 5 "testing" 6 7 qt "github.com/frankban/quicktest" 8 9 "github.com/ipld/go-ipld-prime/datamodel" 10 ) 11 12 func SpecTestBytes(t *testing.T, np datamodel.NodePrototype) { 13 t.Run("byte node", func(t *testing.T) { 14 nb := np.NewBuilder() 15 err := nb.AssignBytes([]byte("asdf")) 16 qt.Check(t, err, qt.IsNil) 17 n := nb.Build() 18 19 qt.Check(t, n.Kind(), qt.Equals, datamodel.Kind_Bytes) 20 qt.Check(t, n.IsNull(), qt.IsFalse) 21 x, err := n.AsBytes() 22 qt.Check(t, err, qt.IsNil) 23 qt.Check(t, x, qt.DeepEquals, []byte("asdf")) 24 25 lbn, ok := n.(datamodel.LargeBytesNode) 26 if ok { 27 str, err := lbn.AsLargeBytes() 28 qt.Check(t, err, qt.IsNil) 29 bytes, err := io.ReadAll(str) 30 qt.Check(t, err, qt.IsNil) 31 qt.Check(t, bytes, qt.DeepEquals, []byte("asdf")) 32 } 33 }) 34 }