Files
Charon/backend/integration/rate_limit_integration_test.go
GitHub Actions 697ef6d200 feat: implement comprehensive test optimization
- Add gotestsum for real-time test progress visibility
- Parallelize 174 tests across 14 files for faster execution
- Add -short mode support skipping 21 heavy integration tests
- Create testutil/db.go helper for future transaction rollbacks
- Fix data race in notification_service_test.go
- Fix 4 CrowdSec LAPI test failures with permissive validator

Performance improvements:
- Tests now run in parallel (174 tests with t.Parallel())
- Quick feedback loop via -short mode
- Zero race conditions detected
- Coverage maintained at 87.7%

Closes test optimization initiative
2026-01-03 19:42:53 +00:00

52 lines
1.5 KiB
Go

//go:build integration
// +build integration
package integration
import (
"context"
"os/exec"
"strings"
"testing"
"time"
)
// TestRateLimitIntegration runs the scripts/rate_limit_integration.sh and ensures it completes successfully.
// This test requires Docker and docker compose access locally; it is gated behind build tag `integration`.
//
// The test verifies:
// - Rate limiting is correctly applied to proxy hosts
// - Requests within the limit return HTTP 200
// - Requests exceeding the limit return HTTP 429
// - Rate limit window resets correctly
func TestRateLimitIntegration(t *testing.T) {
if testing.Short() {
t.Skip("Skipping integration test in short mode")
}
t.Parallel()
// Set a timeout for the entire test (rate limit tests need time for window resets)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
defer cancel()
// Run the integration script from the repo root
cmd := exec.CommandContext(ctx, "bash", "../scripts/rate_limit_integration.sh")
cmd.Dir = ".." // Run from repo root
out, err := cmd.CombinedOutput()
t.Logf("rate_limit_integration script output:\n%s", string(out))
if err != nil {
t.Fatalf("rate limit integration failed: %v", err)
}
// Verify key assertions are present in output
if !strings.Contains(string(out), "Rate limit enforcement succeeded") {
t.Fatalf("unexpected script output: rate limit enforcement assertion not found")
}
if !strings.Contains(string(out), "ALL RATE LIMIT TESTS PASSED") {
t.Fatalf("unexpected script output: final success message not found")
}
}