(t *testing.T)
| 1616 | } |
| 1617 | |
| 1618 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…