-
Notifications
You must be signed in to change notification settings - Fork 49
/
chain_test.go
91 lines (78 loc) · 1.86 KB
/
chain_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package tc
import (
"errors"
"testing"
"github.com/florianl/go-tc/core"
"github.com/florianl/go-tc/internal/unix"
)
func TestChain(t *testing.T) {
tcSocket, done := testConn(t)
defer done()
if err := tcSocket.Chain().Add(nil); err != ErrNoArg {
t.Fatalf("expected ErrNoArg, received: %v", err)
}
tcMsg := Msg{
Family: unix.AF_UNSPEC,
Ifindex: 1337,
Handle: core.BuildHandle(0xFFFF, 0x0000),
Parent: 0xFFFFFFF1,
Info: 0,
}
testQdisc := Object{
tcMsg,
Attribute{
Kind: "clsact",
},
}
if err := tcSocket.Qdisc().Add(&testQdisc); err != nil {
t.Fatalf("could not add new qdisc: %v", err)
}
tests := map[string]struct {
chain uint32
errAdd error
}{
"simple": {chain: 42},
}
for name, testcase := range tests {
t.Run(name, func(t *testing.T) {
testChain := Object{
tcMsg,
Attribute{
Chain: &testcase.chain,
},
}
if err := tcSocket.Chain().Add(&testChain); err != nil {
if testcase.errAdd == nil {
t.Fatalf("could not add new chain: %v", err)
}
// TODO: compare the returned error with the expected one
return
}
chains, err := tcSocket.Chain().Get(&tcMsg)
if err != nil {
t.Fatalf("could not get chains: %v", err)
}
for _, chain := range chains {
t.Logf("%#v\n", chain)
}
if err := tcSocket.Chain().Delete(&testChain); err != nil {
t.Fatalf("could not delete chain: %v", err)
}
})
}
t.Run("delete nil", func(t *testing.T) {
if err := tcSocket.Chain().Delete(nil); !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("add nil", func(t *testing.T) {
if err := tcSocket.Chain().Add(nil); !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
t.Run("get nil", func(t *testing.T) {
if _, err := tcSocket.Chain().Get(nil); !errors.Is(err, ErrNoArg) {
t.Fatalf("unexpected error: %v", err)
}
})
}