github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/util/serialization/metadata_test.go (about) 1 package serialization 2 3 import ( 4 "bufio" 5 "bytes" 6 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("metadata", func() { 12 in := map[string]interface{}{ 13 "foo": 1.0, 14 "bar": "baz", 15 } 16 out := "\x15{\"bar\":\"baz\",\"foo\":1}" 17 18 Describe("WriteMetadata", func() { 19 It("serializes metadata", func() { 20 b := &bytes.Buffer{} 21 WriteMetadata(b, in) 22 Expect(b.String()).To(Equal(out)) 23 }) 24 }) 25 26 Describe("ReadMetadata", func() { 27 It("deserializes metadata", func() { 28 b := bufio.NewReader(bytes.NewReader([]byte(out))) 29 res, err := ReadMetadata(b) 30 Expect(err).ToNot(HaveOccurred()) 31 Expect(res["foo"]).To(Equal(in["foo"])) 32 Expect(res["bar"]).To(Equal(in["bar"])) 33 }) 34 }) 35 })