Skip to content

Commit ef3a9b3

Browse files
committed
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 <[email protected]>
1 parent 5b04c1a commit ef3a9b3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

map_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,29 @@ func TestMapIterate(t *testing.T) {
11251125
qt.Assert(t, qt.DeepEquals(keys, data))
11261126
}
11271127

1128+
func TestIterateWrongMap(t *testing.T) {
1129+
testutils.SkipOnOldKernel(t, "4.20", "map type queue")
1130+
1131+
m, err := NewMap(&MapSpec{
1132+
Type: Queue,
1133+
ValueSize: 4,
1134+
MaxEntries: 2,
1135+
})
1136+
qt.Assert(t, qt.IsNil(err))
1137+
defer m.Close()
1138+
1139+
for _, v := range []uint32{0, 1} {
1140+
err := m.Put(nil, uint32(v))
1141+
qt.Assert(t, qt.IsNil(err))
1142+
}
1143+
1144+
var value uint32
1145+
entries := m.Iterate()
1146+
1147+
qt.Assert(t, qt.IsFalse(entries.Next(nil, &value)))
1148+
qt.Assert(t, qt.IsNotNil(entries.Err()))
1149+
}
1150+
11281151
func TestMapIteratorAllocations(t *testing.T) {
11291152
arr, err := NewMap(&MapSpec{
11301153
Type: Array,

0 commit comments

Comments
 (0)