forked from TrueCloudLab/frostfs-api-go
[#189] sdk/netmap: Refactor Clause enum
Replace alias to v2 type Clause with v2-compatible implementation. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
6d8612fd51
commit
8c1afc6bab
3 changed files with 85 additions and 1 deletions
54
pkg/netmap/clause.go
Normal file
54
pkg/netmap/clause.go
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Clause is an enumeration of selector modifiers
|
||||||
|
// that shows how the node set will be formed.
|
||||||
|
type Clause uint32
|
||||||
|
|
||||||
|
const (
|
||||||
|
_ Clause = iota
|
||||||
|
|
||||||
|
// ClauseSame is a selector modifier to select only nodes having the same value of bucket attribute.
|
||||||
|
ClauseSame
|
||||||
|
|
||||||
|
// ClauseDistinct is a selector modifier to select nodes having different values of bucket attribute.
|
||||||
|
ClauseDistinct
|
||||||
|
)
|
||||||
|
|
||||||
|
// ClauseFromV2 converts v2 Clause to Clause.
|
||||||
|
func ClauseFromV2(c netmap.Clause) Clause {
|
||||||
|
switch c {
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
case netmap.Same:
|
||||||
|
return ClauseSame
|
||||||
|
case netmap.Distinct:
|
||||||
|
return ClauseDistinct
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToV2 converts Clause to v2 Clause.
|
||||||
|
func (c Clause) ToV2() netmap.Clause {
|
||||||
|
switch c {
|
||||||
|
default:
|
||||||
|
return netmap.UnspecifiedClause
|
||||||
|
case ClauseDistinct:
|
||||||
|
return netmap.Distinct
|
||||||
|
case ClauseSame:
|
||||||
|
return netmap.Same
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Clause) String() string {
|
||||||
|
switch c {
|
||||||
|
default:
|
||||||
|
return "UNSPECIFIED"
|
||||||
|
case ClauseDistinct:
|
||||||
|
return "DISTINCT"
|
||||||
|
case ClauseSame:
|
||||||
|
return "SAME"
|
||||||
|
}
|
||||||
|
}
|
31
pkg/netmap/clause_test.go
Normal file
31
pkg/netmap/clause_test.go
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
package netmap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-api-go/v2/netmap"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestClauseFromV2(t *testing.T) {
|
||||||
|
for _, item := range []struct {
|
||||||
|
c Clause
|
||||||
|
cV2 netmap.Clause
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
c: 0,
|
||||||
|
cV2: netmap.UnspecifiedClause,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
c: ClauseSame,
|
||||||
|
cV2: netmap.Same,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
c: ClauseDistinct,
|
||||||
|
cV2: netmap.Distinct,
|
||||||
|
},
|
||||||
|
} {
|
||||||
|
require.Equal(t, item.c, ClauseFromV2(item.cV2))
|
||||||
|
require.Equal(t, item.cV2, item.c.ToV2())
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,7 +9,6 @@ type PlacementPolicy = netmap.PlacementPolicy
|
||||||
type Selector = netmap.Selector
|
type Selector = netmap.Selector
|
||||||
type Filter = netmap.Filter
|
type Filter = netmap.Filter
|
||||||
type Replica = netmap.Replica
|
type Replica = netmap.Replica
|
||||||
type Clause = netmap.Clause
|
|
||||||
|
|
||||||
func PlacementPolicyToJSON(p *PlacementPolicy) ([]byte, error) {
|
func PlacementPolicyToJSON(p *PlacementPolicy) ([]byte, error) {
|
||||||
return netmap.PlacementPolicyToJSON(p)
|
return netmap.PlacementPolicyToJSON(p)
|
||||||
|
|
Loading…
Reference in a new issue