github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/tree/serialize_nodict_test.go (about)

     1  package tree
     2  
     3  import (
     4  	"bytes"
     5  
     6  	. "github.com/onsi/ginkgo/v2/dsl/core"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var serializationExample = []byte("\x00\x00\x01\x01a\x00\x02\x01b\x01\x00\x01c\x02\x00")
    11  
    12  var _ = Describe("tree package", func() {
    13  	Describe("SerializeNoDict", func() {
    14  		It("returns correct results", func() {
    15  			tree := New()
    16  			tree.Insert([]byte("a;b"), uint64(1))
    17  			tree.Insert([]byte("a;c"), uint64(2))
    18  
    19  			var buf bytes.Buffer
    20  			tree.SerializeTruncateNoDict(1024, &buf)
    21  			Expect(buf.Bytes()).To(Equal(serializationExample))
    22  		})
    23  	})
    24  
    25  	Describe("DeserializeNoDict", func() {
    26  		It("returns correct results", func() {
    27  			r := bytes.NewReader(serializationExample)
    28  			t, err := DeserializeNoDict(r)
    29  			Expect(err).ToNot(HaveOccurred())
    30  
    31  			Expect(string(t.root.Name)).To(Equal(""))
    32  			Expect(string(t.root.ChildrenNodes[0].Name)).To(Equal("a"))
    33  			Expect(string(t.root.ChildrenNodes[0].ChildrenNodes[0].Name)).To(Equal("b"))
    34  			Expect(string(t.root.ChildrenNodes[0].ChildrenNodes[1].Name)).To(Equal("c"))
    35  		})
    36  	})
    37  })