From 88736f4226e0abe3eebcf7d820516cd36a771ff7 Mon Sep 17 00:00:00 2001 From: Simone Magnani Date: Tue, 3 Sep 2024 19:23:51 +0200 Subject: [PATCH] add test to assert MapIterator failure against keyless (queues) maps This commit introduces the `TestIterateWrongMap` test, which should assert that the `MapIterator` fails while called on keyless maps such as queues. We do not expect different behaviours, as the `MapIterator.Next` relies on the presence of a key for which it lookups the value. A different method can be later introduces to also traverse a queue, but in that case we'd need to additionally remove the value. Signed-off-by: Simone Magnani --- map_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/map_test.go b/map_test.go index e472e97b3..f70e6e627 100644 --- a/map_test.go +++ b/map_test.go @@ -1123,6 +1123,28 @@ func TestMapIterate(t *testing.T) { qt.Assert(t, qt.DeepEquals(keys, data)) } +func TestIterateWrongMap(t *testing.T) { + testutils.SkipOnOldKernel(t, "4.20", "map type queue") + + m, err := NewMap(&MapSpec{ + Type: Queue, + ValueSize: 4, + MaxEntries: 2, + Contents: []MapKV{ + {nil, uint32(0)}, + {nil, uint32(1)}, + }, + }) + qt.Assert(t, qt.IsNil(err)) + defer m.Close() + + var value uint32 + entries := m.Iterate() + + qt.Assert(t, qt.IsFalse(entries.Next(nil, &value))) + qt.Assert(t, qt.IsNotNil(entries.Err())) +} + func TestMapIteratorAllocations(t *testing.T) { arr, err := NewMap(&MapSpec{ Type: Array,