MCPcopy
hub / github.com/crowdsecurity/crowdsec / TestRCMetrics

Function TestRCMetrics

pkg/apiserver/usage_metrics_test.go:217–387  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

215}
216
217func TestRCMetrics(t *testing.T) {
218 ctx := t.Context()
219
220 tests := []struct {
221 name string
222 body string
223 expectedStatusCode int
224 expectedResponse string
225 expectedMetricsCount int
226 expectedOSName string
227 expectedOSVersion string
228 expectedFeatureFlags string
229 authType string
230 }{
231 {
232 name: "empty metrics for RC",
233 body: `{
234 }`,
235 expectedStatusCode: http.StatusBadRequest,
236 expectedResponse: "Missing remediation component data",
237 authType: APIKEY,
238 },
239 {
240 name: "basic metrics with empty dynamic metrics for RC",
241 body: `
242{
243 "remediation_components": [
244 {
245 "version": "1.42",
246 "os": {"name":"foo", "version": "42"},
247 "utc_startup_timestamp": 42,
248 "metrics": [],
249 "feature_flags": ["a", "b", "c"]
250 }
251 ]
252}`,
253 expectedStatusCode: http.StatusCreated,
254 expectedMetricsCount: 1,
255 expectedResponse: "",
256 expectedOSName: "foo",
257 expectedOSVersion: "42",
258 expectedFeatureFlags: "a,b,c",
259 authType: APIKEY,
260 },
261 {
262 name: "basic metrics with dynamic metrics for RC",
263 body: `
264{
265 "remediation_components": [
266 {
267 "version": "1.42",
268 "os": {"name":"foo", "version": "42"},
269 "utc_startup_timestamp": 42,
270 "metrics": [{"meta":{"utc_now_timestamp":42, "window_size_seconds": 42}, "items": [{"name": "foo", "value": 42, "unit": "bla"}] }, {"meta":{"utc_now_timestamp":43, "window_size_seconds": 42}, "items": [{"name": "foo", "value": 42, "unit": "bla"}] }],
271 "feature_flags": ["a", "b", "c"]
272 }
273 ]
274}`,

Callers

nothing calls this directly

Calls 10

SelectBouncerByNameMethod · 0.95
NewClientFunction · 0.92
GeneratedTypeTypeAlias · 0.92
SetupLAPITestFunction · 0.85
RecordResponseMethod · 0.80
NewReaderMethod · 0.80
RunMethod · 0.65
StringMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…