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

Function TestIP6SetAddElements

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

Source from the content-addressed store, hash-verified

3813}
3814
3815func TestIP6SetAddElements(t *testing.T) {
3816 // Create a new network namespace to test these operations,
3817 // and tear down the namespace at test completion.
3818 c, newNS := nftest.OpenSystemConn(t, *enableSysTests)
3819 defer nftest.CleanupSystemConn(t, newNS)
3820 // Clear all rules at the beginning + end of the test.
3821 c.FlushRuleset()
3822 defer c.FlushRuleset()
3823
3824 filter := c.AddTable(&nftables.Table{
3825 Family: nftables.TableFamilyIPv6,
3826 Name: "filter",
3827 })
3828 portSet := &nftables.Set{
3829 Table: filter,
3830 Name: "ports",
3831 KeyType: nftables.TypeInetService,
3832 }
3833 if err := c.AddSet(portSet, nil); err != nil {
3834 t.Errorf("c.AddSet(portSet) failed: %v", err)
3835 }
3836 if err := c.SetAddElements(portSet, []nftables.SetElement{
3837 {Key: binaryutil.BigEndian.PutUint16(22)},
3838 {Key: binaryutil.BigEndian.PutUint16(80)},
3839 }); err != nil {
3840 t.Errorf("c.SetVal(portSet) failed: %v", err)
3841 }
3842
3843 if err := c.Flush(); err != nil {
3844 t.Errorf("c.Flush() failed: %v", err)
3845 }
3846
3847 sets, err := c.GetSets(filter)
3848 if err != nil {
3849 t.Errorf("c.GetSets() failed: %v", err)
3850 }
3851 if len(sets) != 1 {
3852 t.Fatalf("len(sets) = %d, want 1", len(sets))
3853 }
3854
3855 elements, err := c.GetSetElements(sets[0])
3856 if err != nil {
3857 t.Errorf("c.GetSetElements(portSet) failed: %v", err)
3858 }
3859 if len(elements) != 2 {
3860 t.Fatalf("len(portSetElements) = %d, want 2", len(sets))
3861 }
3862}
3863
3864func TestCreateUseCounterSet(t *testing.T) {
3865 // Create a new network namespace to test these operations,

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…