From db1ed764733b5c8e89b857a4c4c19c238552fb81 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 14 Oct 2021 11:50:05 +0300 Subject: [PATCH] [#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 --- pkg/container/attribute.go | 7 +++++++ pkg/container/attribute_test.go | 13 +++++++++++++ v2/container/attributes.go | 3 +++ 3 files changed, 23 insertions(+) diff --git a/pkg/container/attribute.go b/pkg/container/attribute.go index 0219005..fc87062 100644 --- a/pkg/container/attribute.go +++ b/pkg/container/attribute.go @@ -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 { diff --git a/pkg/container/attribute_test.go b/pkg/container/attribute_test.go index 65967c4..4078c64 100644 --- a/pkg/container/attribute_test.go +++ b/pkg/container/attribute_test.go @@ -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) +} diff --git a/v2/container/attributes.go b/v2/container/attributes.go index 467be48..9f90edb 100644 --- a/v2/container/attributes.go +++ b/v2/container/attributes.go @@ -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"