forked from florianl/go-tc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ematch_test.go
73 lines (69 loc) · 2.07 KB
/
ematch_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package tc
import (
"errors"
"testing"
)
func TestEmatch(t *testing.T) {
/*
tests := map[string]struct {
val Ematch
err1 error
err2 error
}{
"empty": {err1: fmt.Errorf("Ematch options are missing")},
"match 'meta(priority eq 0)'": {
val: Ematch{
Hdr: &EmatchTreeHdr{NMatches: 1, ProgID: 42},
Matches: &[]EmatchMatch{
{Hdr: EmatchHdr{MatchID: 0, Kind: 0x4, Flags: 0x0, Pad: 0x0},
Data: []byte{0xc, 0x0, 0x1, 0x0, 0x6, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x8, 0x0, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0}},
},
},
},
"match 'u32(u16 0x1122 0xffff at nexthdr+4)' and 'cmp(u16 at 3 layer 2 mask 0xff00 gt 20)'": {
val: Ematch{
Hdr: &EmatchTreeHdr{NMatches: 2},
Matches: &[]EmatchMatch{
{Hdr: EmatchHdr{MatchID: 0x0, Kind: 0x3, Flags: 0x1, Pad: 0x0},
Data: []byte{0xff, 0xff, 0x0, 0x0, 0x11, 0x22, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff}},
{Hdr: EmatchHdr{MatchID: 0x0, Kind: 0x1, Flags: 0x0, Pad: 0x0},
Data: []byte{0x14, 0x0, 0x0, 0x0, 0x0, 0xff, 0x0, 0x0, 0x3, 0x0, 0x2, 0x12}}},
},
},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
data, err1 := marshalEmatch(&testcase.val)
if err1 != nil {
if testcase.err1 != nil && testcase.err1.Error() == err1.Error() {
return
}
t.Fatalf("Unexpected error: %v", err1)
}
val := Ematch{}
err2 := unmarshalEmatch(data, &val)
if err2 != nil {
if testcase.err2 != nil && testcase.err2.Error() == err2.Error() {
return
}
t.Fatalf("Unexpected error: %v", err2)
}
if diff := cmp.Diff(val, testcase.val); diff != "" {
t.Fatalf("Ematch missmatch (want +got):\n%s", diff)
}
})
}
*/
t.Run("marshal(nil)", func(t *testing.T) {
_, err := marshalEmatch(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("unmarshal(0x0)", func(t *testing.T) {
val := Ematch{}
if err := unmarshalEmatch([]byte{0x00}, &val); err == nil {
t.Fatalf("expected error but got nil")
}
})
}