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

Function TestUserDataComment

userdata/userdata_test.go:26–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestUserDataComment(t *testing.T) {
27 r := nftables.Rule{}
28
29 wantComment := "this is my comment"
30 want := []byte{
31 byte(userdata.TypeComment), // Type
32 byte(len(wantComment) + 1), // Length (including terminating null byte)
33 }
34 want = append(want, []byte(wantComment)...) // Payload
35 want = append(want, 0) // Terminating null byte
36
37 r.UserData = userdata.AppendString(r.UserData, userdata.TypeComment, wantComment)
38
39 if !bytes.Equal(r.UserData, want) {
40 t.Fatalf("UserData mismatch: %s != %s",
41 hex.EncodeToString(r.UserData),
42 hex.EncodeToString(want))
43 }
44
45 if comment, ok := userdata.GetString(r.UserData, userdata.TypeComment); !ok {
46 t.Fatalf("failed to get comment")
47 } else if comment != wantComment {
48 t.Fatalf("comment does not match: %s != %s", comment, wantComment)
49 }
50}
51
52func TestUint32(t *testing.T) {
53 // Define a custom type for storing a rule ID

Callers

nothing calls this directly

Calls 2

AppendStringFunction · 0.92
GetStringFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…