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

Function TestGetActiveDecisionsTimeLeft

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

Source from the content-addressed store, hash-verified

1724}
1725
1726func TestGetActiveDecisionsTimeLeft(t *testing.T) {
1727 ctx := t.Context()
1728
1729 existingIP := "1.2.3.4"
1730 unknownIP := "1.2.3.5"
1731
1732 rng, err := csnet.NewRange(existingIP)
1733 if err != nil {
1734 t.Errorf("unable to convert '%s' to int: %s", existingIP, err)
1735 }
1736
1737 // Add sample data to DB
1738 dbClient = getDBClient(t)
1739
1740 decision := dbClient.Ent.Decision.Create().
1741 SetUntil(time.Now().UTC().Add(time.Hour)).
1742 SetScenario("crowdsec/test").
1743 SetStartIP(rng.Start.Addr).
1744 SetStartSuffix(rng.Start.Sfx).
1745 SetEndIP(rng.End.Addr).
1746 SetEndSuffix(rng.End.Sfx).
1747 SetIPSize(int64(rng.Size())).
1748 SetType("ban").
1749 SetScope("IP").
1750 SetValue(existingIP).
1751 SetOrigin("CAPI").
1752 SaveX(ctx)
1753
1754 if decision == nil {
1755 require.Error(t, errors.New("Failed to create sample decision"))
1756 }
1757
1758 longerDecision := dbClient.Ent.Decision.Create().
1759 SetUntil(time.Now().UTC().Add(2 * time.Hour)).
1760 SetScenario("crowdsec/test").
1761 SetStartIP(rng.Start.Addr).
1762 SetStartSuffix(rng.Start.Sfx).
1763 SetEndIP(rng.End.Addr).
1764 SetEndSuffix(rng.End.Sfx).
1765 SetIPSize(int64(rng.Size())).
1766 SetType("ban").
1767 SetScope("IP").
1768 SetValue(existingIP).
1769 SetOrigin("CAPI").
1770 SaveX(ctx)
1771
1772 if longerDecision == nil {
1773 require.Error(t, errors.New("Failed to create sample decision"))
1774 }
1775
1776 err = Init(dbClient)
1777 require.NoError(t, err)
1778
1779 tests := []struct {
1780 name string
1781 env map[string]any
1782 code string
1783 min float64

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…