2021-04-30 18:57:23 +05:30
|
|
|
package tempopb
|
|
|
|
|
|
|
|
import (
|
2023-02-10 22:47:40 +09:00
|
|
|
crand "crypto/rand"
|
2021-04-30 18:57:23 +05:30
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-02-10 22:47:40 +09:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-04-30 18:57:23 +05:30
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnmarshal(t *testing.T) {
|
2023-07-20 16:02:05 +00:00
|
|
|
dummyData := make([]byte, 10)
|
2023-02-10 22:47:40 +09:00
|
|
|
_, err := crand.Read(dummyData)
|
|
|
|
require.NoError(t, err)
|
2021-04-30 18:57:23 +05:30
|
|
|
|
2021-05-12 16:08:01 -04:00
|
|
|
preallocReq := &PreallocBytes{}
|
2023-02-10 22:47:40 +09:00
|
|
|
err = preallocReq.Unmarshal(dummyData)
|
2021-04-30 18:57:23 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-05-12 16:08:01 -04:00
|
|
|
assert.Equal(t, dummyData, preallocReq.Slice)
|
2021-04-30 18:57:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarshal(t *testing.T) {
|
2021-05-12 16:08:01 -04:00
|
|
|
preallocReq := &PreallocBytes{
|
|
|
|
Slice: make([]byte, 10),
|
2021-04-30 18:57:23 +05:30
|
|
|
}
|
2023-02-10 22:47:40 +09:00
|
|
|
_, err := crand.Read(preallocReq.Slice)
|
|
|
|
require.NoError(t, err)
|
2021-04-30 18:57:23 +05:30
|
|
|
|
2023-07-20 16:02:05 +00:00
|
|
|
dummyData := make([]byte, 10)
|
2023-02-10 22:47:40 +09:00
|
|
|
_, err = preallocReq.MarshalTo(dummyData)
|
2021-04-30 18:57:23 +05:30
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2021-05-12 16:08:01 -04:00
|
|
|
assert.Equal(t, preallocReq.Slice, dummyData)
|
2021-04-30 18:57:23 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestSize(t *testing.T) {
|
2021-05-12 16:08:01 -04:00
|
|
|
preallocReq := &PreallocBytes{
|
|
|
|
Slice: make([]byte, 10),
|
2021-04-30 18:57:23 +05:30
|
|
|
}
|
|
|
|
assert.Equal(t, 10, preallocReq.Size())
|
|
|
|
}
|