forked from florianl/go-tc
-
Notifications
You must be signed in to change notification settings - Fork 2
/
q_cake_test.go
66 lines (61 loc) · 1.54 KB
/
q_cake_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
package tc
import (
"errors"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestCake(t *testing.T) {
tests := map[string]struct {
val Cake
err1 error
err2 error
}{
"simple": {val: Cake{BaseRate: uint64Ptr(123),
DiffServMode: uint32Ptr(23),
Atm: uint32Ptr(34),
FlowMode: uint32Ptr(45),
Overhead: uint32Ptr(56),
Rtt: uint32Ptr(67),
Target: uint32Ptr(78),
Autorate: uint32Ptr(89),
Memory: uint32Ptr(90),
Nat: uint32Ptr(11),
Raw: uint32Ptr(22),
Wash: uint32Ptr(33),
Mpu: uint32Ptr(44),
Ingress: uint32Ptr(55),
AckFilter: uint32Ptr(66),
SplitGso: uint32Ptr(77),
FwMark: uint32Ptr(88),
}},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
data, err1 := marshalCake(&testcase.val)
if err1 != nil {
if testcase.err1 != nil && testcase.err1.Error() == err1.Error() {
return
}
t.Fatalf("Unexpected error: %v", err1)
}
newData := injectAttribute(t, data, []byte{}, tcaCakePad)
val := Cake{}
err2 := unmarshalCake(newData, &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("Netem missmatch (-want +got):\n%s", diff)
}
})
}
t.Run("nil", func(t *testing.T) {
_, err := marshalCake(nil)
if !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
}