Skip to content

Commit

Permalink
extend tests
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Lehner <[email protected]>
  • Loading branch information
florianl committed Sep 7, 2024
1 parent 673f10e commit 826fc26
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
17 changes: 16 additions & 1 deletion ematch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestEmatch(t *testing.T) {
Hdr: &EmatchTreeHdr{NMatches: 1, ProgID: 42},
Matches: &[]EmatchMatch{
{
Hdr: EmatchHdr{MatchID: 0, Kind: 0x9, Flags: EmatchRelEnd, Pad: 0x0},
Hdr: EmatchHdr{MatchID: 0, Kind: EmatchIPT, Flags: EmatchRelEnd, Pad: 0x0},
IptMatch: &IptMatch{
MatchName: stringPtr("foobar"),
NFProto: uint8Ptr(10),
Expand All @@ -81,6 +81,21 @@ func TestEmatch(t *testing.T) {
},
},
},
"match nbyte(\"ababa\" at 12 layer 1)": {
val: Ematch{
Hdr: &EmatchTreeHdr{NMatches: 1, ProgID: 42},
Matches: &[]EmatchMatch{
{
Hdr: EmatchHdr{MatchID: 0, Kind: EmatchNByte},
NByteMatch: &NByteMatch{
Layer: 1,
Offset: 12,
Needle: []byte("ababa"),
},
},
},
},
},

// A AND (B1 OR B2) AND NOT C
// EmatchHMatch:
Expand Down
33 changes: 33 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,39 @@ func TestValidateFilterObject(t *testing.T) {
},
},
},
"invalid stats arg": {
action: unix.RTM_NEWTFILTER,
info: Object{
Msg: Msg{
Ifindex: 42,
},
Attribute: Attribute{
Kind: "basic",
Stats: &Stats{
Qlen: 3,
},
},
},
err: ErrInvalidArg,
},
"optional arguments": {
action: unix.RTM_NEWTFILTER,
info: Object{
Msg: Msg{
Ifindex: 42,
},
Attribute: Attribute{
Kind: "basic",
Basic: &Basic{
ClassID: uint32Ptr(42),
},
EgressBlock: uint32Ptr(2),
IngressBlock: uint32Ptr(3),
HwOffload: uint8Ptr(5),
Chain: uint32Ptr(7),
},
},
},
}
for name, test := range tests {
name := name
Expand Down
5 changes: 3 additions & 2 deletions m_ctinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ func TestCtInfo(t *testing.T) {
}

val := CtInfo{}
err2 := unmarshalCtInfo(data, &val)
newData, tm := injectTcft(t, data, tcaCtInfoTm)
err2 := unmarshalCtInfo(newData, &val)
if !errors.Is(err2, testcase.err2) {
t.Fatalf("Unexpected error: %v", err2)
}

testcase.val.Tm = tm
if diff := cmp.Diff(val, testcase.val); diff != "" {
t.Fatalf("CtInfo missmatch (want +got):\n%s", diff)
}
Expand Down

0 comments on commit 826fc26

Please sign in to comment.