From ae52d5360984f9c184c0ac8fc3aa2bba76704a81 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 26 Aug 2022 13:37:03 +0300 Subject: [PATCH] [#1698] pilorama: Add a test for the empty FileName Signed-off-by: Evgenii Stratonikov --- pkg/local_object_storage/pilorama/forest_test.go | 14 ++++++++++++++ pkg/local_object_storage/pilorama/meta_test.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/pkg/local_object_storage/pilorama/forest_test.go b/pkg/local_object_storage/pilorama/forest_test.go index 53868fbf..98eaf05d 100644 --- a/pkg/local_object_storage/pilorama/forest_test.go +++ b/pkg/local_object_storage/pilorama/forest_test.go @@ -312,6 +312,20 @@ func testForestTreeAddByPath(t *testing.T, s Forest) { require.Equal(t, lm[1].Child, nodes[0]) }) }) + + t.Run("empty component", func(t *testing.T) { + meta := []KeyValue{ + {Key: AttributeVersion, Value: []byte("XXX")}, + {Key: AttributeFilename, Value: []byte{}}} + lm, err := s.TreeAddByPath(d, treeID, AttributeFilename, []string{"path", "to"}, meta) + require.NoError(t, err) + require.Equal(t, 1, len(lm)) + + nodes, err := s.TreeGetByPath(d.CID, treeID, AttributeFilename, []string{"path", "to", ""}, false) + require.NoError(t, err) + require.Equal(t, 1, len(nodes)) + require.Equal(t, lm[0].Child, nodes[0]) + }) } func TestForest_Apply(t *testing.T) { diff --git a/pkg/local_object_storage/pilorama/meta_test.go b/pkg/local_object_storage/pilorama/meta_test.go index 2e10649f..7adb97ab 100644 --- a/pkg/local_object_storage/pilorama/meta_test.go +++ b/pkg/local_object_storage/pilorama/meta_test.go @@ -15,6 +15,20 @@ func TestMeta_Bytes(t *testing.T) { require.Equal(t, uint64(0), m.Time) require.Equal(t, []byte{0, 0}, m.Bytes()) }) + t.Run("empty attribute value", func(t *testing.T) { + expected := Meta{ + Time: 123, + Items: []KeyValue{ + {"abc", []byte{1, 2, 3}}, + {AttributeFilename, []byte{}}, + }} + + data := expected.Bytes() + + var actual Meta + require.NoError(t, actual.FromBytes(data)) + require.Equal(t, expected, actual) + }) t.Run("filled", func(t *testing.T) { expected := Meta{ Time: 123,