Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
[#351] container: Add default value for NNS zone
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Leonard Lyubich authored and alexvanin committed Oct 14, 2021
1 parent 20b8632 commit db1ed76
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/container/attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,18 @@ func iterateAttributes(c *Container, f func(*Attribute) bool) {
}

// SetNativeNameWithZone sets container native name and its zone.
//
// Use SetNativeName to set default zone.
func SetNativeNameWithZone(c *Container, name, zone string) {
setAttribute(c, container.SysAttributeName, name)
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.
func GetNativeNameWithZone(c *Container) (name string, zone string) {
iterateAttributes(c, func(a *Attribute) bool {
Expand Down
13 changes: 13 additions & 0 deletions pkg/container/attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,16 @@ func TestGetNameWithZone(t *testing.T) {
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)
}
3 changes: 3 additions & 0 deletions v2/container/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ const (
// SysAttributeZone is a string of zone for container name.
SysAttributeZone = SysAttributePrefix + "ZONE"
)

// SysAttributeZoneDefault is a default value for SysAttributeZone attribute.
const SysAttributeZoneDefault = "container"

0 comments on commit db1ed76

Please sign in to comment.