forked from TrueCloudLab/frostfs-sdk-go
[#352] container: Implement iterators over attributes
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
88bc9eeb26
commit
a0e4d16dbb
3 changed files with 133 additions and 7 deletions
95
container/iterators_test.go
Normal file
95
container/iterators_test.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
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)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue