(t *testing.T)
| 24 | ) |
| 25 | |
| 26 | func 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 | |
| 52 | func TestUint32(t *testing.T) { |
| 53 | // Define a custom type for storing a rule ID |
nothing calls this directly
no test coverage detected
searching dependent graphs…