[#787] util/attributes: Reuse attribute struct to update parents list
Parser should reuse existing attributes from the cache to update list of the parent links in it. Parent links should be unique. Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
c1326efaf5
commit
d8a04726ad
2 changed files with 51 additions and 10 deletions
|
@ -25,7 +25,6 @@ func TestParseV2Attributes(t *testing.T) {
|
|||
bad := append(good, "StorageType:SSD/Cell:QLC")
|
||||
_, err = attributes.ParseV2Attributes(bad, nil)
|
||||
require.Error(t, err)
|
||||
|
||||
})
|
||||
|
||||
t.Run("malformed", func(t *testing.T) {
|
||||
|
@ -69,4 +68,30 @@ func TestParseV2Attributes(t *testing.T) {
|
|||
require.Equal(t, attrs[1].Key(), `Ke/y2`)
|
||||
require.Equal(t, attrs[1].Value(), `Va:lue`)
|
||||
})
|
||||
|
||||
t.Run("same attributes", func(t *testing.T) {
|
||||
from := []string{"/a:b", "/a:b"}
|
||||
attrs, err := attributes.ParseV2Attributes(from, nil)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, attrs, 1)
|
||||
})
|
||||
|
||||
t.Run("multiple parents", func(t *testing.T) {
|
||||
from := []string{
|
||||
"/parent1:x/child:x",
|
||||
"/parent2:x/child:x",
|
||||
"/parent2:x/child:x/subchild:x",
|
||||
}
|
||||
attrs, err := attributes.ParseV2Attributes(from, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
var flag bool
|
||||
for _, attr := range attrs {
|
||||
if attr.Key() == "child" {
|
||||
flag = true
|
||||
require.Equal(t, attr.ParentKeys(), []string{"parent1", "parent2"})
|
||||
}
|
||||
}
|
||||
require.True(t, flag)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue