Skip to content

Commit

Permalink
acl,object: Add new MatchType enum values after protocol extension
Browse files Browse the repository at this point in the history
Make codegen from nspcc-dev/neofs-api@541cd3c.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Feb 13, 2024
1 parent 70b1ffb commit 2e32ff6
Show file tree
Hide file tree
Showing 8 changed files with 183 additions and 51 deletions.
26 changes: 18 additions & 8 deletions acl/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ func HeaderTypeFromGRPCField(t acl.HeaderType) HeaderType {
// MatchTypeToGRPCField converts unified match type enum into grpc enum.
func MatchTypeToGRPCField(t MatchType) acl.MatchType {
switch t {
case MatchTypeStringEqual:
return acl.MatchType_STRING_EQUAL
case MatchTypeStringNotEqual:
return acl.MatchType_STRING_NOT_EQUAL
case
MatchTypeStringEqual,
MatchTypeStringNotEqual,
MatchTypeNotPresent,
MatchTypeNumGT,
MatchTypeNumGE,
MatchTypeNumLT,
MatchTypeNumLE:
return acl.MatchType(t)
default:
return acl.MatchType_MATCH_TYPE_UNSPECIFIED
}
Expand All @@ -147,10 +152,15 @@ func MatchTypeToGRPCField(t MatchType) acl.MatchType {
// MatchTypeFromGRPCField converts grpc enum into unified match type enum.
func MatchTypeFromGRPCField(t acl.MatchType) MatchType {
switch t {
case acl.MatchType_STRING_EQUAL:
return MatchTypeStringEqual
case acl.MatchType_STRING_NOT_EQUAL:
return MatchTypeStringNotEqual
case
acl.MatchType_STRING_EQUAL,
acl.MatchType_STRING_NOT_EQUAL,
acl.MatchType_NOT_PRESENT,
acl.MatchType_NUM_GT,
acl.MatchType_NUM_GE,
acl.MatchType_NUM_LT,
acl.MatchType_NUM_LE:
return MatchType(t)
default:
return MatchTypeUnknown
}
Expand Down
88 changes: 60 additions & 28 deletions acl/grpc/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions acl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ const (
MatchTypeUnknown MatchType = iota
MatchTypeStringEqual
MatchTypeStringNotEqual
MatchTypeNotPresent
MatchTypeNumGT
MatchTypeNumGE
MatchTypeNumLT
MatchTypeNumLE
matchTypeLast // for testing
)

const (
Expand Down
30 changes: 30 additions & 0 deletions acl/types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package acl

import (
"testing"

acl "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc"
"github.com/stretchr/testify/require"
)

func TestMatchTypeToGRPCField(t *testing.T) {
require.Equal(t, MatchTypeUnknown, MatchTypeFromGRPCField(acl.MatchType_NUM_LE+1))
require.Equal(t, acl.MatchType_MATCH_TYPE_UNSPECIFIED, MatchTypeToGRPCField(matchTypeLast))

for _, tc := range []struct {
m MatchType
g acl.MatchType
}{
{MatchTypeUnknown, acl.MatchType_MATCH_TYPE_UNSPECIFIED},
{MatchTypeStringEqual, acl.MatchType_STRING_EQUAL},
{MatchTypeStringNotEqual, acl.MatchType_STRING_NOT_EQUAL},
{MatchTypeNotPresent, acl.MatchType_NOT_PRESENT},
{MatchTypeNumGT, acl.MatchType_NUM_GT},
{MatchTypeNumGE, acl.MatchType_NUM_GE},
{MatchTypeNumLT, acl.MatchType_NUM_LT},
{MatchTypeNumLE, acl.MatchType_NUM_LE},
} {
require.Equal(t, tc.g, MatchTypeToGRPCField(tc.m), tc)
require.Equal(t, tc.m, MatchTypeFromGRPCField(tc.g), tc)
}
}
28 changes: 28 additions & 0 deletions object/convert_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package object

import (
"testing"

object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
"github.com/stretchr/testify/require"
)

func TestMatchTypeToGRPCField(t *testing.T) {
for _, tc := range []struct {
m MatchType
g object.MatchType
}{
{MatchUnknown, object.MatchType_MATCH_TYPE_UNSPECIFIED},
{MatchStringEqual, object.MatchType_STRING_EQUAL},
{MatchStringNotEqual, object.MatchType_STRING_NOT_EQUAL},
{MatchNotPresent, object.MatchType_NOT_PRESENT},
{MatchCommonPrefix, object.MatchType_COMMON_PREFIX},
{MatchNumGT, object.MatchType_NUM_GT},
{MatchNumGE, object.MatchType_NUM_GE},
{MatchNumLT, object.MatchType_NUM_LT},
{MatchNumLE, object.MatchType_NUM_LE},
} {
require.Equal(t, tc.g, MatchTypeToGRPCField(tc.m), tc)
require.Equal(t, tc.m, MatchTypeFromGRPCField(tc.g), tc)
}
}
3 changes: 3 additions & 0 deletions object/grpc/service.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 34 additions & 15 deletions object/grpc/types.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions object/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ const (
MatchStringNotEqual
MatchNotPresent
MatchCommonPrefix
MatchNumGT
MatchNumGE
MatchNumLT
MatchNumLE
)

func (h *ShortHeader) GetVersion() *refs.Version {
Expand Down

0 comments on commit 2e32ff6

Please sign in to comment.