forked from TrueCloudLab/frostfs-node
[#311] control: Cover StableMarshal methods with unit tests
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
5f22e7fac7
commit
6c9dab481c
3 changed files with 205 additions and 0 deletions
36
pkg/services/control/common_test.go
Normal file
36
pkg/services/control/common_test.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package control_test
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type protoMessage interface {
|
||||
StableMarshal([]byte) ([]byte, error)
|
||||
proto.Message
|
||||
}
|
||||
|
||||
func testStableMarshal(t *testing.T, m1, m2 protoMessage, cmp func(m1, m2 protoMessage) bool) {
|
||||
data, err := m1.StableMarshal(nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, proto.Unmarshal(data, m2))
|
||||
|
||||
require.True(t, cmp(m1, m2))
|
||||
}
|
||||
|
||||
func testData(sz int) []byte {
|
||||
d := make([]byte, sz)
|
||||
|
||||
_, _ = rand.Read(d)
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
func testString() string {
|
||||
return base58.Encode(testData(10))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue