95 lines
2.6 KiB
Go
95 lines
2.6 KiB
Go
package container_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
containerAPI "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestContainer_Attributes(t *testing.T) {
|
|
t.Run("empty", func(t *testing.T) {
|
|
var n container.Container
|
|
t.Run("attributes", func(t *testing.T) {
|
|
for range n.Attributes() {
|
|
t.Fatalf("handler is called, but it shouldn't")
|
|
}
|
|
})
|
|
t.Run("user attributes", func(t *testing.T) {
|
|
for range n.UserAttributes() {
|
|
t.Fatalf("handler is called, but it shouldn't")
|
|
}
|
|
})
|
|
})
|
|
|
|
var n container.Container
|
|
n.SetAttribute(containerAPI.SysAttributeName, "myname")
|
|
n.SetAttribute("key1", "value1")
|
|
n.SetAttribute("key2", "value2")
|
|
n.SetAttribute(containerAPI.SysAttributeZone, "test")
|
|
|
|
t.Run("break", func(t *testing.T) {
|
|
t.Run("attributes", func(t *testing.T) {
|
|
var res [][2]string
|
|
for key, value := range n.Attributes() {
|
|
if key == "key2" {
|
|
break
|
|
}
|
|
res = append(res, [2]string{key, value})
|
|
}
|
|
require.Equal(t, [][2]string{{containerAPI.SysAttributeName, "myname"}, {"key1", "value1"}}, res)
|
|
})
|
|
t.Run("user attributes", func(t *testing.T) {
|
|
var res [][2]string
|
|
for key, value := range n.UserAttributes() {
|
|
if key == "key2" {
|
|
break
|
|
}
|
|
res = append(res, [2]string{key, value})
|
|
}
|
|
require.Equal(t, [][2]string{{"key1", "value1"}}, res)
|
|
})
|
|
})
|
|
t.Run("continue", func(t *testing.T) {
|
|
t.Run("attributes", func(t *testing.T) {
|
|
var res [][2]string
|
|
for key, value := range n.Attributes() {
|
|
if key == "key2" {
|
|
continue
|
|
}
|
|
res = append(res, [2]string{key, value})
|
|
}
|
|
require.Equal(t, [][2]string{{containerAPI.SysAttributeName, "myname"}, {"key1", "value1"}, {containerAPI.SysAttributeZone, "test"}}, res)
|
|
})
|
|
t.Run("user attributes", func(t *testing.T) {
|
|
var res [][2]string
|
|
for key, value := range n.UserAttributes() {
|
|
if key == "key2" {
|
|
continue
|
|
}
|
|
res = append(res, [2]string{key, value})
|
|
}
|
|
require.Equal(t, [][2]string{{"key1", "value1"}}, res)
|
|
})
|
|
})
|
|
t.Run("attributes", func(t *testing.T) {
|
|
var res [][2]string
|
|
for key, value := range n.Attributes() {
|
|
res = append(res, [2]string{key, value})
|
|
}
|
|
require.Equal(t, [][2]string{
|
|
{containerAPI.SysAttributeName, "myname"},
|
|
{"key1", "value1"},
|
|
{"key2", "value2"},
|
|
{containerAPI.SysAttributeZone, "test"},
|
|
}, res)
|
|
})
|
|
t.Run("user attributes", func(t *testing.T) {
|
|
var res [][2]string
|
|
for key, value := range n.UserAttributes() {
|
|
res = append(res, [2]string{key, value})
|
|
}
|
|
require.Equal(t, [][2]string{{"key1", "value1"}, {"key2", "value2"}}, res)
|
|
})
|
|
}
|