github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/lsmkv/segment_serialization_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package lsmkv 13 14 import ( 15 "bytes" 16 "testing" 17 18 "github.com/stretchr/testify/assert" 19 "github.com/stretchr/testify/require" 20 ) 21 22 func Test_SerializeAndParseCollectionNode(t *testing.T) { 23 before := segmentCollectionNode{ 24 primaryKey: []byte("this-is-my-primary-key"), 25 values: []value{{ 26 value: []byte("the-first-value"), 27 }, { 28 value: []byte("the-second-value-with-a-tombstone"), 29 tombstone: true, 30 }}, 31 } 32 33 buf := &bytes.Buffer{} 34 _, err := before.KeyIndexAndWriteTo(buf) 35 require.Nil(t, err) 36 encoded := buf.Bytes() 37 38 expected := segmentCollectionNode{ 39 primaryKey: []byte("this-is-my-primary-key"), 40 values: []value{{ 41 value: []byte("the-first-value"), 42 }, { 43 value: []byte("the-second-value-with-a-tombstone"), 44 tombstone: true, 45 }}, 46 offset: buf.Len(), 47 } 48 49 t.Run("parse using the _regular_ way", func(t *testing.T) { 50 after, err := ParseCollectionNode(bytes.NewReader(encoded)) 51 assert.Nil(t, err) 52 assert.Equal(t, expected, after) 53 }) 54 55 t.Run("parse using the reusable way", func(t *testing.T) { 56 var node segmentCollectionNode 57 err := ParseCollectionNodeInto(bytes.NewReader(encoded), &node) 58 assert.Nil(t, err) 59 assert.Equal(t, expected, node) 60 }) 61 }