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