(t *testing.T)
| 3862 | } |
| 3863 | |
| 3864 | func 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 | |
| 3907 | func TestCreateDeleteNamedSet(t *testing.T) { |
| 3908 | // Create a new network namespace to test these operations, |
nothing calls this directly
no test coverage detected
searching dependent graphs…