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

Function TestGetActiveDecisionsCount

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

Source from the content-addressed store, hash-verified

1616}
1617
1618func TestGetActiveDecisionsCount(t *testing.T) {
1619 ctx := t.Context()
1620
1621 existingIP := "1.2.3.4"
1622 unknownIP := "1.2.3.5"
1623
1624 rng, err := csnet.NewRange(existingIP)
1625 if err != nil {
1626 t.Errorf("unable to convert '%s' to int: %s", existingIP, err)
1627 }
1628
1629 // Add sample data to DB
1630 dbClient = getDBClient(t)
1631
1632 decision := dbClient.Ent.Decision.Create().
1633 SetUntil(time.Now().UTC().Add(time.Hour)).
1634 SetScenario("crowdsec/test").
1635 SetStartIP(rng.Start.Addr).
1636 SetStartSuffix(rng.Start.Sfx).
1637 SetEndIP(rng.End.Addr).
1638 SetEndSuffix(rng.End.Sfx).
1639 SetIPSize(int64(rng.Size())).
1640 SetType("ban").
1641 SetScope("IP").
1642 SetValue(existingIP).
1643 SetOrigin("CAPI").
1644 SaveX(ctx)
1645
1646 if decision == nil {
1647 require.Error(t, errors.New("Failed to create sample decision"))
1648 }
1649
1650 expiredDecision := dbClient.Ent.Decision.Create().
1651 SetUntil(time.Now().UTC().Add(-time.Hour)).
1652 SetScenario("crowdsec/test").
1653 SetStartIP(rng.Start.Addr).
1654 SetStartSuffix(rng.Start.Sfx).
1655 SetEndIP(rng.End.Addr).
1656 SetEndSuffix(rng.End.Sfx).
1657 SetIPSize(int64(rng.Size())).
1658 SetType("ban").
1659 SetScope("IP").
1660 SetValue(existingIP).
1661 SetOrigin("CAPI").
1662 SaveX(ctx)
1663
1664 if expiredDecision == nil {
1665 require.Error(t, errors.New("Failed to create sample decision"))
1666 }
1667
1668 err = Init(dbClient)
1669 require.NoError(t, err)
1670
1671 tests := []struct {
1672 name string
1673 env map[string]any
1674 code string
1675 result 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…