forked from TrueCloudLab/frostfs-api-go
[#147] Work around object package
- implement Stringer interface and Parse method for object.ID - increase test coverage closes #147 Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
f5388b553e
commit
f5b442fe3b
2 changed files with 71 additions and 0 deletions
|
@ -3,8 +3,10 @@ package object
|
|||
import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/mr-tron/base58"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -38,3 +40,46 @@ func TestID_Equal(t *testing.T) {
|
|||
require.True(t, id1.Equal(id2))
|
||||
require.False(t, id1.Equal(id3))
|
||||
}
|
||||
|
||||
func TestID_Parse(t *testing.T) {
|
||||
t.Run("should parse successful", func(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
cs := randSHA256Checksum(t)
|
||||
str := base58.Encode(cs[:])
|
||||
oid := NewID()
|
||||
|
||||
require.NoError(t, oid.Parse(str))
|
||||
require.Equal(t, cs[:], oid.ToV2().GetValue())
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("should failure on parse", func(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
j := i
|
||||
t.Run(strconv.Itoa(j), func(t *testing.T) {
|
||||
cs := []byte{1, 2, 3, 4, 5, byte(j)}
|
||||
str := base58.Encode(cs)
|
||||
oid := NewID()
|
||||
|
||||
require.EqualError(t, oid.Parse(str), ErrBadID.Error())
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestID_String(t *testing.T) {
|
||||
t.Run("should be equal", func(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
t.Run(strconv.Itoa(i), func(t *testing.T) {
|
||||
cs := randSHA256Checksum(t)
|
||||
str := base58.Encode(cs[:])
|
||||
oid := NewID()
|
||||
|
||||
require.NoError(t, oid.Parse(str))
|
||||
require.Equal(t, str, oid.String())
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue