MCPcopy
hub / github.com/cilium/ebpf / TestIterateEmptyMap

Function TestIterateEmptyMap

map_test.go:883–934  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

881}
882
883func TestIterateEmptyMap(t *testing.T) {
884 makeMap := func(t *testing.T, mapType MapType) *Map {
885 m, err := newMap(t, &MapSpec{
886 Type: mapType,
887 KeySize: 4,
888 ValueSize: 8,
889 MaxEntries: 2,
890 }, nil)
891 if errors.Is(err, unix.EINVAL) {
892 t.Skip(mapType, "is not supported")
893 }
894 qt.Assert(t, qt.IsNil(err))
895 return m
896 }
897
898 for _, mapType := range []MapType{
899 Hash,
900 SockHash,
901 } {
902 t.Run(mapType.String(), func(t *testing.T) {
903 m := makeMap(t, mapType)
904 entries := m.Iterate()
905
906 var key string
907 var value uint64
908 if entries.Next(&key, &value) {
909 t.Error("Empty hash should not be iterable")
910 }
911 if err := entries.Err(); err != nil {
912 t.Error("Empty hash shouldn't return an error:", err)
913 }
914 })
915 }
916
917 for _, mapType := range []MapType{
918 Array,
919 SockMap,
920 } {
921 t.Run(mapType.String(), func(t *testing.T) {
922 m := makeMap(t, mapType)
923 entries := m.Iterate()
924 var key string
925 var value uint64
926 for entries.Next(&key, &value) {
927 // Some empty arrays like sockmap don't return any keys.
928 }
929 if err := entries.Err(); err != nil {
930 t.Error("Empty array shouldn't return an error:", err)
931 }
932 })
933 }
934}
935
936func TestMapIterate(t *testing.T) {
937 hash := createMap(t, Hash, 2)

Callers

nothing calls this directly

Calls 9

newMapFunction · 0.85
IsNilMethod · 0.80
RunMethod · 0.65
IsMethod · 0.45
StringMethod · 0.45
IterateMethod · 0.45
NextMethod · 0.45
ErrorMethod · 0.45
ErrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…