Files
Agent-System-Backend/internal/server/ratelimit_e2e_test.go
T
weichen f1302ed5b3 Enable canonical versioned Go module consumption
Why: Allow consumers to download an immutable module revision without nested source checkouts or local path replacements.

Evidence: SELF package tests and the prior canonical-path rejection are recorded in the Dev dependency-workspace task card; remote consumption is replayed against the committed candidate.

Impact: Change the module identity and its Go imports while preserving API behavior. Existing historical submodule revisions remain buildable.

Refs: Versioned dependencies U1/U3; feature/dependency-workspace
2026-10-13 15:47:16 +00:00

41 lines
937 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package server
// 限流 e2e:limit=3 时第 4 个请求 429;其他租户不受影响。
import (
"net/http"
"net/http/httptest"
"testing"
"git-ssh.u1680832.nyat.app/weichen/Agent-System-Backend.git/internal/ratelimit"
)
func TestRateLimitMiddleware(t *testing.T) {
srv, _ := newTestServer(t)
srv.Limiter = ratelimit.NewMemory()
n := 3
srv.LimitLookup = func() int { return n }
h := srv.Handler()
get := func() int {
req := httptest.NewRequest("GET", "/api/projects", nil)
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
return rec.Code
}
for i := 1; i <= n; i++ {
if c := get(); c != http.StatusOK {
t.Fatalf("request %d: %d", i, c)
}
}
if c := get(); c != http.StatusTooManyRequests {
t.Fatalf("4th request: %d (want 429)", c)
}
// lookup<=0 时放行(默认不限)。
n = 0
srv.Limiter = ratelimit.NewMemory()
if c := get(); c != http.StatusOK {
t.Fatalf("unlimited: %d", c)
}
}