MCPcopy Create free account
hub / github.com/google/nftables / TestCreateUseCounterSet

Function TestCreateUseCounterSet

nftables_test.go:3864–3905  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3862}
3863
3864func TestCreateUseCounterSet(t *testing.T) {
3865 // Create a new network namespace to test these operations,
3866 // and tear down the namespace at test completion.
3867 c, newNS := nftest.OpenSystemConn(t, *enableSysTests)
3868 defer nftest.CleanupSystemConn(t, newNS)
3869 // Clear all rules at the beginning + end of the test.
3870 c.FlushRuleset()
3871 defer c.FlushRuleset()
3872
3873 filter := c.AddTable(&nftables.Table{
3874 Family: nftables.TableFamilyIPv4,
3875 Name: "filter",
3876 })
3877
3878 portSet := &nftables.Set{
3879 Table: filter,
3880 Name: "test",
3881 KeyType: nftables.TypeInetService,
3882 Counter: true,
3883 }
3884 if err := c.AddSet(portSet, nil); err != nil {
3885 t.Errorf("c.AddSet(portSet) failed: %v", err)
3886 }
3887 if err := c.SetAddElements(portSet, []nftables.SetElement{{Key: binaryutil.BigEndian.PutUint16(22)}}); err != nil {
3888 t.Errorf("c.SetVal(portSet) failed: %v", err)
3889 }
3890
3891 if err := c.Flush(); err != nil {
3892 t.Errorf("c.Flush() failed: %v", err)
3893 }
3894
3895 sets, err := c.GetSets(filter)
3896 if err != nil {
3897 t.Errorf("c.GetSets() failed: %v", err)
3898 }
3899 if len(sets) != 1 {
3900 t.Fatalf("len(sets) = %d, want 1", len(sets))
3901 }
3902 if sets[0].Name != "test" {
3903 t.Errorf("set[0].Name = %q, want test", sets[0].Name)
3904 }
3905}
3906
3907func TestCreateDeleteNamedSet(t *testing.T) {
3908 // Create a new network namespace to test these operations,

Callers

nothing calls this directly

Calls 9

OpenSystemConnFunction · 0.92
CleanupSystemConnFunction · 0.92
FlushRulesetMethod · 0.80
AddTableMethod · 0.80
AddSetMethod · 0.80
SetAddElementsMethod · 0.80
FlushMethod · 0.80
GetSetsMethod · 0.80
PutUint16Method · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…