-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
220 lines (214 loc) · 8.94 KB
/
main_test.go
File metadata and controls
220 lines (214 loc) · 8.94 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package main
import (
"github.com/steadybit/action-kit/go/action_kit_sdk"
"github.com/steadybit/discovery-kit/go/discovery_kit_sdk"
"github.com/steadybit/extension-aws/v2/config"
"github.com/stretchr/testify/assert"
"golang.org/x/exp/slices"
"net/http"
"testing"
)
func createConfig(ec2 bool, ecs bool, elasticache bool, elb bool, fis bool, msk bool, lambda bool, rds bool, subnet bool, zone bool, vpc bool) config.Specification {
return config.Specification{
EnrichEc2DataForTargetTypes: []string{"com.steadybit.extension_aws.test"},
DiscoveryDisabledEc2: ec2,
DiscoveryIntervalEc2: 10,
DiscoveryDisabledEcs: ecs,
DiscoveryIntervalEcsTask: 10,
DiscoveryIntervalEcsService: 10,
DiscoveryDisabledElasticache: elasticache,
DiscoveryIntervalElasticacheReplicationGroup: 10,
DiscoveryDisabledElb: elb,
DiscoveryIntervalElbAlb: 10,
DiscoveryDisabledFis: fis,
DiscoveryIntervalFis: 10,
DiscoveryDisabledMsk: msk,
DiscoveryIntervalMsk: 10,
DiscoveryDisabledLambda: lambda,
DiscoveryIntervalLambda: 10,
DiscoveryDisabledRds: rds,
DiscoveryIntervalRds: 10,
DiscoveryDisabledSubnet: subnet,
DiscoveryIntervalSubnet: 10,
DiscoveryDisabledZone: zone,
DiscoveryIntervalZone: 10,
DiscoveryDisabledVpc: vpc,
// Modules added after the original test was written. All default to disabled here so that
// existing tests (which assert exact route lists) keep working without per-test wiring.
DiscoveryDisabledApigateway: true,
DiscoveryDisabledAsg: true,
DiscoveryDisabledDynamodb: true,
DiscoveryDisabledEbs: true,
DiscoveryDisabledEks: true,
DiscoveryDisabledEventbridge: true,
DiscoveryDisabledMq: true,
DiscoveryDisabledNatGateway: true,
DiscoveryDisabledSqs: true,
}
}
func Test_getExtensionList(t *testing.T) {
tests := []struct {
name string
config config.Specification
wantedRoutes []string
}{
{
name: "disabled all but ec2",
config: createConfig(false, true, true, true, true, true, true, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.ec2_instance.state",
"/com.steadybit.extension_aws.ec2-instance/discovery",
"/com.steadybit.extension_aws.ec2-instance/discovery/target-description",
"/discovery/attributes",
"/discovery/enrichment-rules/com.steadybit.extension_aws.ec2-instance-to-com.steadybit.extension_aws.test",
"/discovery/enrichment-rules/com.steadybit.extension_aws.ec2-instance-to-com.steadybit.extension_host.host",
"/discovery/enrichment-rules/com.steadybit.extension_aws.ec2-instance-to-com.steadybit.extension_host_windows.host",
"/discovery/enrichment-rules/com.steadybit.extension_aws.ec2-instance-to-com.steadybit.extension_kubernetes.kubernetes-node",
},
},
{
name: "disabled all but subnet",
config: createConfig(true, true, true, true, true, true, true, true, false, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.ec2-subnet.blackhole",
"/com.steadybit.extension_aws.ec2-subnet/discovery",
"/com.steadybit.extension_aws.ec2-subnet/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but ecs",
config: createConfig(true, false, true, true, true, true, true, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.ecs-task.stop",
"/com.steadybit.extension_aws.ecs-task.stop-process",
"/com.steadybit.extension_aws.ecs-service.event_log",
"/com.steadybit.extension_aws.ecs-service.scale",
"/com.steadybit.extension_aws.ecs-service.task_count_check",
"/com.steadybit.extension_aws.ecs-task.fill_disk",
"/com.steadybit.extension_aws.ecs-task.network_blackhole_port",
"/com.steadybit.extension_aws.ecs-task.network_dns",
"/com.steadybit.extension_aws.ecs-task.network_delay",
"/com.steadybit.extension_aws.ecs-task.network_loss",
"/com.steadybit.extension_aws.ecs-task.stress_cpu",
"/com.steadybit.extension_aws.ecs-task.stress_mem",
"/com.steadybit.extension_aws.ecs-task.stress_io",
"/com.steadybit.extension_aws.ecs-task/discovery",
"/com.steadybit.extension_aws.ecs-task/discovery/target-description",
"/com.steadybit.extension_aws.ecs-service/discovery",
"/com.steadybit.extension_aws.ecs-service/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but elb",
config: createConfig(true, true, true, false, true, true, true, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.alb.static_response",
"/com.steadybit.extension_aws.alb/discovery",
"/com.steadybit.extension_aws.alb/discovery/target-description",
"/com.steadybit.extension_aws.nlb/discovery",
"/com.steadybit.extension_aws.nlb/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but elasticache",
config: createConfig(true, true, false, true, true, true, true, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.elasticache.node-group.failover",
"/com.steadybit.extension_aws.elasticache.node-group/discovery",
"/com.steadybit.extension_aws.elasticache.node-group/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but fis",
config: createConfig(true, true, true, true, false, true, true, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.fis.start_experiment",
"/com.steadybit.extension_aws.fis-experiment-template/discovery",
"/com.steadybit.extension_aws.fis-experiment-template/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but msk",
config: createConfig(true, true, true, true, true, false, true, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.msk.cluster.broker.reboot-broker",
"/com.steadybit.extension_aws.msk.cluster.broker/discovery",
"/com.steadybit.extension_aws.msk.cluster.broker/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but lambda",
config: createConfig(true, true, true, true, true, true, false, true, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.lambda.denylist",
"/com.steadybit.extension_aws.lambda.diskspace",
"/com.steadybit.extension_aws.lambda.exception",
"/com.steadybit.extension_aws.lambda.latency",
"/com.steadybit.extension_aws.lambda.statusCode",
"/com.steadybit.extension_aws.lambda/discovery",
"/com.steadybit.extension_aws.lambda/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but rds",
config: createConfig(true, true, true, true, true, true, true, false, true, true, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.rds.cluster.failover",
"/com.steadybit.extension_aws.rds.instance.reboot",
"/com.steadybit.extension_aws.rds.instance.stop",
"/com.steadybit.extension_aws.rds.cluster/discovery",
"/com.steadybit.extension_aws.rds.cluster/discovery/target-description",
"/com.steadybit.extension_aws.rds.instance/discovery",
"/com.steadybit.extension_aws.rds.instance/discovery/target-description",
"/discovery/attributes",
},
},
{
name: "disabled all but zone",
config: createConfig(true, true, true, true, true, true, true, true, true, false, true),
wantedRoutes: []string{
"/com.steadybit.extension_aws.az.blackhole",
"/com.steadybit.extension_aws.zone/discovery",
"/com.steadybit.extension_aws.zone/discovery/target-description",
"/discovery/attributes",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
action_kit_sdk.ClearRegisteredActions()
discovery_kit_sdk.ClearRegisteredDiscoveries()
http.DefaultServeMux = http.NewServeMux()
config.Config = tt.config
background := t.Context()
registerHandlers(background)
got := getExtensionList()
routes := make([]string, 0)
for _, route := range got.Actions {
routes = append(routes, route.Path)
}
for _, route := range got.Discoveries {
routes = append(routes, route.Path)
}
for _, route := range got.TargetTypes {
routes = append(routes, route.Path)
}
for _, route := range got.TargetAttributes {
routes = append(routes, route.Path)
}
for _, route := range got.TargetEnrichmentRules {
routes = append(routes, route.Path)
}
slices.Sort(routes)
slices.Sort(tt.wantedRoutes)
assert.Equal(t, tt.wantedRoutes, routes)
})
}
}