(t *testing.T)
| 5962 | } |
| 5963 | |
| 5964 | func TestSetComment(t *testing.T) { |
| 5965 | want := [][]byte{ |
| 5966 | // batch begin |
| 5967 | []byte("\x00\x00\x00\x0a"), |
| 5968 | // nft flush ruleset |
| 5969 | []byte("\x00\x00\x00\x00"), |
| 5970 | // nft add table inet filter |
| 5971 | []byte("\x01\x00\x00\x00\x0b\x00\x01\x00\x66\x69\x6c\x74\x65\x72\x00\x00\x08\x00\x02\x00\x00\x00\x00\x00"), |
| 5972 | // nft add set inet filter setname { type ipv4_addr\; comment \"test comment\" \; } |
| 5973 | []byte("\x01\x00\x00\x00\x0b\x00\x01\x00\x66\x69\x6c\x74\x65\x72\x00\x00\x0c\x00\x02\x00\x73\x65\x74\x6e\x61\x6d\x65\x00\x08\x00\x03\x00\x00\x00\x00\x00\x08\x00\x04\x00\x00\x00\x00\x07\x08\x00\x05\x00\x00\x00\x00\x04\x08\x00\x0a\x00\x00\x00\x00\x02\x13\x00\x0d\x00\x07\x0d\x74\x65\x73\x74\x20\x63\x6f\x6d\x6d\x65\x6e\x74\x00\x00"), |
| 5974 | // batch end |
| 5975 | []byte("\x00\x00\x00\x0a"), |
| 5976 | } |
| 5977 | |
| 5978 | c, err := nftables.New(nftables.WithTestDial( |
| 5979 | func(req []netlink.Message) ([]netlink.Message, error) { |
| 5980 | for idx, msg := range req { |
| 5981 | b, err := msg.MarshalBinary() |
| 5982 | if err != nil { |
| 5983 | t.Fatal(err) |
| 5984 | } |
| 5985 | if len(b) < 16 { |
| 5986 | continue |
| 5987 | } |
| 5988 | b = b[16:] |
| 5989 | if len(want) == 0 { |
| 5990 | t.Errorf("no want entry for message %d: %x", idx, b) |
| 5991 | continue |
| 5992 | } |
| 5993 | if got, want := b, want[0]; !bytes.Equal(got, want) { |
| 5994 | t.Errorf("message %d: %s", idx, linediff(nfdump(got), nfdump(want))) |
| 5995 | } |
| 5996 | want = want[1:] |
| 5997 | } |
| 5998 | return req, nil |
| 5999 | })) |
| 6000 | if err != nil { |
| 6001 | t.Fatal(err) |
| 6002 | } |
| 6003 | |
| 6004 | c.FlushRuleset() |
| 6005 | |
| 6006 | filter := c.AddTable(&nftables.Table{ |
| 6007 | Family: nftables.TableFamilyINet, |
| 6008 | Name: "filter", |
| 6009 | }) |
| 6010 | |
| 6011 | if err := c.AddSet(&nftables.Set{ |
| 6012 | ID: 2, |
| 6013 | Table: filter, |
| 6014 | Name: "setname", |
| 6015 | KeyType: nftables.TypeIPAddr, |
| 6016 | Comment: "test comment", |
| 6017 | }, nil); err != nil { |
| 6018 | t.Fatal(err) |
| 6019 | } |
| 6020 | |
| 6021 | if err := c.Flush(); err != nil { |
nothing calls this directly
no test coverage detected
searching dependent graphs…