-
Notifications
You must be signed in to change notification settings - Fork 51
/
test_utils.go
52 lines (39 loc) · 1.11 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
package nfqdatapath
import (
"fmt"
"github.com/golang/mock/gomock"
"go.aporeto.io/trireme-lib/collector"
)
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}
}