-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathematch_meta_test.go
More file actions
67 lines (62 loc) · 1.3 KB
/
ematch_meta_test.go
File metadata and controls
67 lines (62 loc) · 1.3 KB
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
package tc
import (
"errors"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestMetaMatch(t *testing.T) {
tests := map[string]struct {
val MetaMatch
err1 error
err2 error
}{
"simple": {val: MetaMatch{
Hdr: &MetaHdr{
Left: MetaValue{
Kind: 1<<12 | 1,
Shift: 2,
Op: 3,
},
Right: MetaValue{
Kind: 1<<12 | 4,
Shift: 5,
Op: 6,
},
},
Left: &MetaValueType{
Int: uint32Ptr(42),
},
Right: &MetaValueType{
Int: uint32Ptr(73),
},
}},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
data, err1 := marshalMetaMatch(&testcase.val)
if !errors.Is(err1, testcase.err1) {
t.Fatalf("Unexpected error: %v", err1)
}
val := MetaMatch{}
err2 := unmarshalMetaMatch(data, &val)
if !errors.Is(err2, testcase.err2) {
t.Fatalf("Unexpected error: %v", err2)
}
if diff := cmp.Diff(val, testcase.val); diff != "" {
t.Fatalf("MetaMatch missmatch (want +got):\n%s", diff)
}
})
}
t.Run("nil", func(t *testing.T) {
_, err := marshalMetaMatch(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("unmarshalIptMatch()", func(t *testing.T) {
err := unmarshalMetaMatch([]byte{0x0}, nil)
if err == nil {
t.Fatalf("expected error but got none")
}
})
}