github.com/cilium/cilium@v1.16.2/pkg/maps/nat/nat_batch_test.go (about) 1 // SPDX-License-Identifier: Apache-2.0 2 // Copyright Authors of Cilium 3 4 package nat 5 6 import ( 7 "testing" 8 9 "github.com/cilium/cilium/pkg/testutils" 10 "github.com/cilium/cilium/pkg/tuple" 11 "github.com/cilium/cilium/pkg/types" 12 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestApplyPatch(t *testing.T) { 17 testutils.PrivilegedTest(t) 18 m := NewMap("test_snat_map", IPv4, 1<<18) // approximate default map size. 19 m.family = IPv4 20 err := m.OpenOrCreate() 21 assert.NoError(t, err) 22 defer assert.NoError(t, m.UnpinIfExists()) 23 for i := 0; i < 1024+1; i++ { 24 var ip types.IPv4 25 ip[0] = byte(i) 26 ip[1] = byte(i >> 8) 27 ip[2] = byte(i >> 16) 28 ip[3] = byte(i >> 24) 29 30 mapKey := &NatKey4{} 31 mapKey.TupleKey4.DestAddr = ip 32 mapKey.TupleKey4.DestPort = uint16(i) 33 mapKey.Flags = tuple.TUPLE_F_IN 34 mapValue := &NatEntry4{} 35 err := m.Update(mapKey, mapValue) 36 assert.NoError(t, err) 37 } 38 count := 0 39 m.ApplyBatch4(func(tk []tuple.TupleKey4, ne []NatEntry4, c int) { 40 count += int(c) 41 }) 42 assert.Equal(t, count, 1024+1) 43 }