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
41 lines
937 B
Go
41 lines
937 B
Go
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)
|
||
}
|
||
}
|