From 2fb1547cd87a9de03f84c72fd222b0c0e501a797 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 22 Sep 2020 14:01:10 +0300 Subject: [PATCH] [#155] sdk/object: Define object types Signed-off-by: Leonard Lyubich --- pkg/object/type.go | 35 +++++++++++++++++++++++++++++++++++ pkg/object/type_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 pkg/object/type.go create mode 100644 pkg/object/type_test.go diff --git a/pkg/object/type.go b/pkg/object/type.go new file mode 100644 index 00000000..afcbdf28 --- /dev/null +++ b/pkg/object/type.go @@ -0,0 +1,35 @@ +package object + +import ( + "github.com/nspcc-dev/neofs-api-go/v2/object" +) + +type Type uint8 + +const ( + TypeRegular Type = iota + TypeTombstone + TypeStorageGroup +) + +func (t Type) ToV2() object.Type { + switch t { + case TypeTombstone: + return object.TypeTombstone + case TypeStorageGroup: + return object.TypeStorageGroup + default: + return object.TypeRegular + } +} + +func TypeFromV2(t object.Type) Type { + switch t { + case object.TypeTombstone: + return TypeTombstone + case object.TypeStorageGroup: + return TypeStorageGroup + default: + return TypeRegular + } +} diff --git a/pkg/object/type_test.go b/pkg/object/type_test.go new file mode 100644 index 00000000..82f8bf22 --- /dev/null +++ b/pkg/object/type_test.go @@ -0,0 +1,36 @@ +package object + +import ( + "testing" + + "github.com/nspcc-dev/neofs-api-go/v2/object" + "github.com/stretchr/testify/require" +) + +func TestType_ToV2(t *testing.T) { + typs := []struct { + t Type + t2 object.Type + }{ + { + t: TypeRegular, + t2: object.TypeRegular, + }, + { + t: TypeTombstone, + t2: object.TypeTombstone, + }, + { + t: TypeStorageGroup, + t2: object.TypeStorageGroup, + }, + } + + for _, item := range typs { + t2 := item.t.ToV2() + + require.Equal(t, item.t2, t2) + + require.Equal(t, item.t, TypeFromV2(item.t2)) + } +}