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

Function TestGetDecisionsSinceCount

pkg/exprhelpers/exprlib_test.go:1493–1616  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1491}
1492
1493func TestGetDecisionsSinceCount(t *testing.T) {
1494 ctx := t.Context()
1495
1496 existingIP := "1.2.3.4"
1497 unknownIP := "1.2.3.5"
1498
1499 rng, err := csnet.NewRange(existingIP)
1500 if err != nil {
1501 t.Errorf("unable to convert '%s' to int: %s", existingIP, err)
1502 }
1503 // Add sample data to DB
1504 dbClient = getDBClient(t)
1505
1506 decision := dbClient.Ent.Decision.Create().
1507 SetUntil(time.Now().Add(time.Hour)).
1508 SetScenario("crowdsec/test").
1509 SetStartIP(rng.Start.Addr).
1510 SetStartSuffix(rng.Start.Sfx).
1511 SetEndIP(rng.End.Addr).
1512 SetEndSuffix(rng.End.Sfx).
1513 SetIPSize(int64(rng.Size())).
1514 SetType("ban").
1515 SetScope("IP").
1516 SetValue(existingIP).
1517 SetOrigin("CAPI").
1518 SaveX(ctx)
1519 if decision == nil {
1520 require.Error(t, errors.New("Failed to create sample decision"))
1521 }
1522
1523 decision2 := dbClient.Ent.Decision.Create().
1524 SetCreatedAt(time.Now().AddDate(0, 0, -1)).
1525 SetUntil(time.Now().AddDate(0, 0, -1)).
1526 SetScenario("crowdsec/test").
1527 SetStartIP(rng.Start.Addr).
1528 SetStartSuffix(rng.Start.Sfx).
1529 SetEndIP(rng.End.Addr).
1530 SetEndSuffix(rng.End.Sfx).
1531 SetIPSize(int64(rng.Size())).
1532 SetType("ban").
1533 SetScope("IP").
1534 SetValue(existingIP).
1535 SetOrigin("CAPI").
1536 SaveX(ctx)
1537
1538 if decision2 == nil {
1539 require.Error(t, errors.New("Failed to create sample decision"))
1540 }
1541
1542 err = Init(dbClient)
1543 require.NoError(t, err)
1544
1545 tests := []struct {
1546 name string
1547 env map[string]any
1548 code string
1549 result string
1550 err string

Callers

nothing calls this directly

Calls 15

SizeMethod · 0.95
NewRangeFunction · 0.92
InitFunction · 0.85
GetExprOptionsFunction · 0.85
getDBClientFunction · 0.70
ErrorMethod · 0.65
RunMethod · 0.65
SaveXMethod · 0.45
SetOriginMethod · 0.45
SetValueMethod · 0.45
SetScopeMethod · 0.45
SetTypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…