forked from TrueCloudLab/frostfs-api-go
[#351] container: Add default value for NNS zone
Define `SysAttributeZoneDefault` constant for default zone in V2 code. Add `SetNativeName` function which sets name with default zone. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
20b863284a
commit
db1ed76473
3 changed files with 23 additions and 0 deletions
|
@ -109,11 +109,18 @@ func iterateAttributes(c *Container, f func(*Attribute) bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetNativeNameWithZone sets container native name and its zone.
|
// SetNativeNameWithZone sets container native name and its zone.
|
||||||
|
//
|
||||||
|
// Use SetNativeName to set default zone.
|
||||||
func SetNativeNameWithZone(c *Container, name, zone string) {
|
func SetNativeNameWithZone(c *Container, name, zone string) {
|
||||||
setAttribute(c, container.SysAttributeName, name)
|
setAttribute(c, container.SysAttributeName, name)
|
||||||
setAttribute(c, container.SysAttributeZone, zone)
|
setAttribute(c, container.SysAttributeZone, zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetNativeName sets container native name with default zone (container).
|
||||||
|
func SetNativeName(c *Container, name string) {
|
||||||
|
SetNativeNameWithZone(c, name, container.SysAttributeZoneDefault)
|
||||||
|
}
|
||||||
|
|
||||||
// GetNativeNameWithZone returns container native name and its zone.
|
// GetNativeNameWithZone returns container native name and its zone.
|
||||||
func GetNativeNameWithZone(c *Container) (name string, zone string) {
|
func GetNativeNameWithZone(c *Container) (name string, zone string) {
|
||||||
iterateAttributes(c, func(a *Attribute) bool {
|
iterateAttributes(c, func(a *Attribute) bool {
|
||||||
|
|
|
@ -140,3 +140,16 @@ func TestGetNameWithZone(t *testing.T) {
|
||||||
require.Equal(t, item.zone, zone, item.zone)
|
require.Equal(t, item.zone, zone, item.zone)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetNativeName(t *testing.T) {
|
||||||
|
c := container.New()
|
||||||
|
|
||||||
|
const nameDefZone = "some name"
|
||||||
|
|
||||||
|
container.SetNativeName(c, nameDefZone)
|
||||||
|
|
||||||
|
name, zone := container.GetNativeNameWithZone(c)
|
||||||
|
|
||||||
|
require.Equal(t, nameDefZone, name)
|
||||||
|
require.Equal(t, containerv2.SysAttributeZoneDefault, zone)
|
||||||
|
}
|
||||||
|
|
|
@ -13,3 +13,6 @@ const (
|
||||||
// SysAttributeZone is a string of zone for container name.
|
// SysAttributeZone is a string of zone for container name.
|
||||||
SysAttributeZone = SysAttributePrefix + "ZONE"
|
SysAttributeZone = SysAttributePrefix + "ZONE"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SysAttributeZoneDefault is a default value for SysAttributeZone attribute.
|
||||||
|
const SysAttributeZoneDefault = "container"
|
||||||
|
|
Loading…
Reference in a new issue