-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrules_test.go
53 lines (43 loc) · 1.02 KB
/
rules_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
package goaway2
import "testing"
/***Variables***/
var exampleRule = &fwRule{
Zone: zone("any"),
SrcIP: convertIPs("192.168.200.114"),
SrcPort: convertPorts("any"),
DstIP: convertIPs("8.8.8.8"),
DstPort: convertPorts("53"),
}
var examplePktData = &PacketData{
SrcIP: "192.168.200.114",
SrcPort: 10048,
DstIP: "8.8.8.8",
DstPort: 53,
}
/***Benchmarks***/
func BenchmarkRuleValidate(b *testing.B) {
for i := 0; i < b.N; i++ {
exampleRule.Validate(examplePktData)
}
}
func BenchmarkZoneValidate(b *testing.B) {
for i := 0; i < b.N; i++ {
exampleRule.Zone.Validate(examplePktData.SrcIP)
}
}
func BenchmarkIPValidate(b *testing.B) {
for i := 0; i < b.N; i++ {
exampleRule.SrcIP.Validate(examplePktData.SrcIP)
}
}
func BenchmarkPortValidate(b *testing.B) {
for i := 0; i < b.N; i++ {
exampleRule.SrcPort.Validate(examplePktData.SrcPort)
}
}
/***Unit-Tests***/
func TestRuleVerification(t *testing.T) {
if !exampleRule.Validate(examplePktData) {
t.Fatalf("Unable to validate packet against rule!\n")
}
}