Skip to content

Commit

Permalink
add test to assert MapIterator failure against keyless (queues) maps
Browse files Browse the repository at this point in the history
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 <simone.magnani@isovalent.com>
  • Loading branch information
smagnani96 authored and ti-mo committed Sep 12, 2024
1 parent f8b5f21 commit 88736f4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 88736f4

Please sign in to comment.