forked from florianl/go-tc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
f_tcindex_test.go
50 lines (45 loc) · 1.08 KB
/
f_tcindex_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
package tc
import (
"errors"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestTcIndex(t *testing.T) {
tests := map[string]struct {
val TcIndex
err1 error
err2 error
}{
"empty": {},
"simple": {val: TcIndex{Hash: uint32Ptr(1), Mask: uint16Ptr(2), Shift: uint32Ptr(3),
FallThrough: uint32Ptr(4), ClassID: uint32Ptr(5)}},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
data, err1 := marshalTcIndex(&testcase.val)
if err1 != nil {
if testcase.err1 != nil && errors.Is(err1, testcase.err1) {
return
}
t.Fatalf("Unexpected error: %v", err1)
}
val := TcIndex{}
err2 := unmarshalTcIndex(data, &val)
if err2 != nil {
if testcase.err2 != nil && errors.Is(err2, testcase.err2) {
return
}
t.Fatalf("Unexpected error: %v", err2)
}
if diff := cmp.Diff(val, testcase.val); diff != "" {
t.Fatalf("TcIndex missmatch (-want +got):\n%s", diff)
}
})
}
t.Run("nil", func(t *testing.T) {
_, err := marshalTcIndex(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
}