2021-11-08 10:04:45 +00:00
|
|
|
package object_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
v2object "github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
"github.com/nspcc-dev/neofs-sdk-go/object"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestType_ToV2(t *testing.T) {
|
|
|
|
typs := []struct {
|
|
|
|
t object.Type
|
|
|
|
t2 v2object.Type
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
t: object.TypeRegular,
|
|
|
|
t2: v2object.TypeRegular,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
t: object.TypeTombstone,
|
|
|
|
t2: v2object.TypeTombstone,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
t: object.TypeStorageGroup,
|
|
|
|
t2: v2object.TypeStorageGroup,
|
|
|
|
},
|
2022-02-15 05:41:03 +00:00
|
|
|
{
|
|
|
|
t: object.TypeLock,
|
|
|
|
t2: v2object.TypeLock,
|
|
|
|
},
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, item := range typs {
|
|
|
|
t2 := item.t.ToV2()
|
|
|
|
|
|
|
|
require.Equal(t, item.t2, t2)
|
|
|
|
|
|
|
|
require.Equal(t, item.t, object.TypeFromV2(item.t2))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestType_String(t *testing.T) {
|
|
|
|
toPtr := func(v object.Type) *object.Type {
|
|
|
|
return &v
|
|
|
|
}
|
|
|
|
|
|
|
|
testEnumStrings(t, new(object.Type), []enumStringItem{
|
|
|
|
{val: toPtr(object.TypeTombstone), str: "TOMBSTONE"},
|
|
|
|
{val: toPtr(object.TypeStorageGroup), str: "STORAGE_GROUP"},
|
|
|
|
{val: toPtr(object.TypeRegular), str: "REGULAR"},
|
2022-02-15 05:41:03 +00:00
|
|
|
{val: toPtr(object.TypeLock), str: "LOCK"},
|
2021-11-08 10:04:45 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
type enumIface interface {
|
2023-04-19 10:33:35 +00:00
|
|
|
DecodeString(string) bool
|
|
|
|
EncodeToString() string
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type enumStringItem struct {
|
|
|
|
val enumIface
|
|
|
|
str string
|
|
|
|
}
|
|
|
|
|
|
|
|
func testEnumStrings(t *testing.T, e enumIface, items []enumStringItem) {
|
|
|
|
for _, item := range items {
|
2023-04-19 10:33:35 +00:00
|
|
|
require.Equal(t, item.str, item.val.EncodeToString())
|
2021-11-08 10:04:45 +00:00
|
|
|
|
2023-04-19 10:33:35 +00:00
|
|
|
s := item.val.EncodeToString()
|
2021-11-08 10:04:45 +00:00
|
|
|
|
2023-04-19 10:33:35 +00:00
|
|
|
require.True(t, e.DecodeString(s), s)
|
2021-11-08 10:04:45 +00:00
|
|
|
|
|
|
|
require.EqualValues(t, item.val, e, item.val)
|
|
|
|
}
|
|
|
|
|
|
|
|
// incorrect strings
|
|
|
|
for _, str := range []string{
|
|
|
|
"some string",
|
|
|
|
"undefined",
|
|
|
|
} {
|
2023-04-19 10:33:35 +00:00
|
|
|
require.False(t, e.DecodeString(str))
|
2021-11-08 10:04:45 +00:00
|
|
|
}
|
|
|
|
}
|