forked from florianl/go-tc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ematch_cmp_test.go
44 lines (40 loc) · 909 Bytes
/
ematch_cmp_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
package tc
import (
"errors"
"io"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestCmpMatch(t *testing.T) {
// cmp(u16 at 3 layer 2 mask 0xff00 gt 20)
in := CmpMatch{
Val: 20,
Mask: 0xff00,
Off: 3,
Align: CmpMatchU16,
Layer: EmatchLayerTransport,
Opnd: EmatchOpndGt,
}
data, err := marshalCmpMatch(&in)
if err != nil {
t.Fatal(err)
}
out := CmpMatch{}
if err := unmarshalCmpMatch(data, &out); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(in, out); diff != "" {
t.Fatalf("CmpMatch missmatch (-want +got):\n%s", diff)
}
t.Run("nil-marshalCmpMatch", func(t *testing.T) {
_, err := marshalCmpMatch(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("nil-unmarshalCmpMatch", func(t *testing.T) {
if err := unmarshalCmpMatch([]byte{}, nil); !errors.Is(err, io.EOF) {
t.Fatalf("unexpected error: %v", err)
}
})
}