-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrokers_test.go
More file actions
128 lines (118 loc) 路 3.01 KB
/
Copy pathbrokers_test.go
File metadata and controls
128 lines (118 loc) 路 3.01 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package matcher
import (
"context"
"testing"
)
func TestRedisEventBrokerCreation(t *testing.T) {
// Test invalid configurations
testCases := []struct {
name string
config RedisEventBrokerConfig
expectError bool
}{
{
name: "Empty redis address",
config: RedisEventBrokerConfig{
RedisAddr: "",
StreamName: "test-stream",
ConsumerGroup: "test-group",
ConsumerName: "test-consumer",
NodeID: "test-node",
},
expectError: true,
},
{
name: "Empty stream name",
config: RedisEventBrokerConfig{
RedisAddr: "localhost:6379",
StreamName: "",
ConsumerGroup: "test-group",
ConsumerName: "test-consumer",
NodeID: "test-node",
},
expectError: true,
},
{
name: "Empty consumer group",
config: RedisEventBrokerConfig{
RedisAddr: "localhost:6379",
StreamName: "test-stream",
ConsumerGroup: "",
ConsumerName: "test-consumer",
NodeID: "test-node",
},
expectError: true,
},
{
name: "Empty consumer name",
config: RedisEventBrokerConfig{
RedisAddr: "localhost:6379",
StreamName: "test-stream",
ConsumerGroup: "test-group",
ConsumerName: "",
NodeID: "test-node",
},
expectError: true,
},
{
name: "Empty node ID",
config: RedisEventBrokerConfig{
RedisAddr: "localhost:6379",
StreamName: "test-stream",
ConsumerGroup: "test-group",
ConsumerName: "test-consumer",
NodeID: "",
},
expectError: true,
},
{
name: "Valid config but no Redis server",
config: RedisEventBrokerConfig{
RedisAddr: "localhost:6379",
StreamName: "test-stream",
ConsumerGroup: "test-group",
ConsumerName: "test-consumer",
NodeID: "test-node",
},
expectError: true, // Will fail to connect
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
broker, err := NewRedisEventBroker(tc.config)
if tc.expectError && err == nil {
t.Error("Expected error but got none")
}
if !tc.expectError && err != nil {
t.Errorf("Expected no error but got: %v", err)
}
if broker != nil {
broker.Close()
}
})
}
}
func TestMockEventSubscriberBranches(t *testing.T) {
subscriber := NewMockEventSubscriber()
defer subscriber.Close()
// Test health check
ctx := context.Background()
if err := subscriber.Health(ctx); err != nil {
t.Errorf("Health check failed: %v", err)
}
// Test publishing to trigger different branches in Publish method
events := []*Event{
{Type: EventTypeRuleAdded, NodeID: "test-node"},
{Type: EventTypeRuleUpdated, NodeID: "test-node"},
{Type: EventTypeRuleDeleted, NodeID: "test-node"},
{Type: EventTypeDimensionAdded, NodeID: "test-node"},
{Type: EventTypeDimensionUpdated, NodeID: "test-node"},
{Type: EventTypeDimensionDeleted, NodeID: "test-node"},
}
for _, event := range events {
err := subscriber.Publish(ctx, event)
if err != nil {
t.Errorf("Failed to publish event %s: %v", event.Type, err)
}
}
}