-
Notifications
You must be signed in to change notification settings - Fork 51
/
test_utils.go
77 lines (58 loc) · 1.71 KB
/
test_utils.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
package nfqdatapath
import (
"fmt"
"github.com/golang/mock/gomock"
"go.aporeto.io/trireme-lib/collector"
"go.aporeto.io/trireme-lib/controller/pkg/pucontext"
)
type myMatcher struct {
x interface{}
}
func (m *myMatcher) Matches(x interface{}) bool {
f1 := m.x.(*collector.FlowRecord)
f2 := x.(*collector.FlowRecord)
if f1.Destination.IP == f2.Destination.IP && f1.Source.IP == f2.Source.IP && f1.Destination.Port == f2.Destination.Port && f1.Action == f2.Action && f1.Count == f2.Count {
return true
}
return false
}
func (m *myMatcher) String() string {
return fmt.Sprintf("is equal to %v", m.x)
}
// MyMatcher returns gomock matcher
func MyMatcher(x interface{}) gomock.Matcher {
return &myMatcher{x: x}
}
type packetEventMatcher struct {
x interface{}
}
func (p *packetEventMatcher) Matches(x interface{}) bool {
f1 := p.x.(*collector.PacketReport)
f2 := x.(*collector.PacketReport)
return f1.DestinationIP == f2.DestinationIP
}
func (p *packetEventMatcher) String() string {
return fmt.Sprintf("is equal to %v", p.x)
}
// PacketEventMatcher return gomock matcher
func PacketEventMatcher(x interface{}) gomock.Matcher {
return &packetEventMatcher{x: x}
}
type myCounterMatcher struct {
x interface{}
}
func (m *myCounterMatcher) Matches(x interface{}) bool {
f1 := m.x.(*collector.CounterReport)
f2 := x.(*collector.CounterReport)
if f2.Namespace != "/ns1" {
return true
}
return f1.ContextID == f2.ContextID && f1.Counters[pucontext.ErrNonPUTraffic].Value == 0
}
func (m *myCounterMatcher) String() string {
return fmt.Sprintf("is equal to %v", m.x)
}
// MyCounterMatcher custom matcher for counter record
func MyCounterMatcher(x interface{}) gomock.Matcher {
return &myCounterMatcher{x: x}
}