-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime_test.go
More file actions
71 lines (62 loc) · 1.95 KB
/
Copy pathruntime_test.go
File metadata and controls
71 lines (62 loc) · 1.95 KB
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
package vmflow
import (
"errors"
"testing"
"github.com/cloudapp3/vmflow/engine"
)
func TestRuntimeApplyAndClose(t *testing.T) {
rt := New()
defer rt.Close()
result := rt.Apply([]engine.Rule{{
RuleID: "disabled-rule",
Name: "disabled-rule",
Protocol: engine.ProtocolTCP,
ListenAddr: "127.0.0.1",
ListenPort: 18080,
TargetAddr: "127.0.0.1",
TargetPort: 18081,
Enabled: false,
}})
if result.FailedRules != 0 {
t.Fatalf("expected no failed rules, got %+v", result)
}
if rt.RunningCount() != 0 {
t.Fatalf("expected no running rules, got %d", rt.RunningCount())
}
if len(rt.SnapshotAll()) != 1 {
t.Fatalf("expected disabled rule counter to exist")
}
if err := rt.Close(); err != nil {
t.Fatalf("close: %v", err)
}
if err := rt.StartRule(engine.Rule{}); !errors.Is(err, ErrRuntimeClosed) {
t.Fatalf("expected ErrRuntimeClosed, got %v", err)
}
closedResult := rt.Apply(nil)
if closedResult.FailedRules != 0 || closedResult.TotalRules != 0 || len(closedResult.Items) != 0 {
t.Fatalf("unexpected closed empty apply result: %+v", closedResult)
}
closedResult = rt.Apply([]engine.Rule{{RuleID: "x", Name: "x", Protocol: engine.ProtocolTCP, ListenPort: 1, TargetAddr: "127.0.0.1", TargetPort: 2}})
if closedResult.FailedRules != 1 || closedResult.TotalRules != 1 || len(closedResult.Items) != 1 {
t.Fatalf("unexpected closed apply result: %+v", closedResult)
}
}
func TestRuntimeWithCollector(t *testing.T) {
collector := engine.NewCollector()
rt := NewRuntime(Options{Collector: collector})
defer rt.Close()
if rt.Collector() != collector {
t.Fatalf("expected supplied collector")
}
if rt.Manager() == nil {
t.Fatalf("expected manager")
}
}
func TestRuntimeConfiguresUDPMaxSessions(t *testing.T) {
rt := NewRuntime(Options{UDPMaxSessions: 123})
defer rt.Close()
limit, active := rt.Manager().UDPMaxSessions()
if limit != 123 || active != 0 {
t.Fatalf("UDPMaxSessions = (%d, %d), want (123, 0)", limit, active)
}
}