github.com/kiali/kiali@v1.84.0/tracing/tempo/tempopb/prealloc_test.go (about) 1 package tempopb 2 3 import ( 4 crand "crypto/rand" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestUnmarshal(t *testing.T) { 12 dummyData := make([]byte, 10) 13 _, err := crand.Read(dummyData) 14 require.NoError(t, err) 15 16 preallocReq := &PreallocBytes{} 17 err = preallocReq.Unmarshal(dummyData) 18 assert.NoError(t, err) 19 20 assert.Equal(t, dummyData, preallocReq.Slice) 21 } 22 23 func TestMarshal(t *testing.T) { 24 preallocReq := &PreallocBytes{ 25 Slice: make([]byte, 10), 26 } 27 _, err := crand.Read(preallocReq.Slice) 28 require.NoError(t, err) 29 30 dummyData := make([]byte, 10) 31 _, err = preallocReq.MarshalTo(dummyData) 32 assert.NoError(t, err) 33 34 assert.Equal(t, preallocReq.Slice, dummyData) 35 } 36 37 func TestSize(t *testing.T) { 38 preallocReq := &PreallocBytes{ 39 Slice: make([]byte, 10), 40 } 41 assert.Equal(t, 10, preallocReq.Size()) 42 }