feat: implement raw sample capture querying and persistence, and add environment-based configuration for dev capture store.

This commit is contained in:
CJACK
2026-04-06 02:33:02 +08:00
parent 49012a227c
commit 039d7d3db1
7 changed files with 474 additions and 6 deletions

View File

@@ -14,8 +14,8 @@ import (
)
const (
defaultLimit = 5
defaultMaxBodyBytes = 2 * 1024 * 1024
defaultLimit = 20
defaultMaxBodyBytes = 5 * 1024 * 1024
maxLimit = 50
)

View File

@@ -6,6 +6,35 @@ import (
"testing"
)
func TestNewFromEnvDefaults(t *testing.T) {
t.Setenv("DS2API_DEV_PACKET_CAPTURE_LIMIT", "")
t.Setenv("DS2API_DEV_PACKET_CAPTURE_MAX_BODY_BYTES", "")
t.Setenv("VERCEL", "")
t.Setenv("NOW_REGION", "")
s := NewFromEnv()
if s.Limit() != 20 {
t.Fatalf("expected default limit 20, got %d", s.Limit())
}
if s.MaxBodyBytes() != 5*1024*1024 {
t.Fatalf("expected default max body bytes 5MB, got %d", s.MaxBodyBytes())
}
}
func TestNewFromEnvHonorsOverrides(t *testing.T) {
t.Setenv("DS2API_DEV_PACKET_CAPTURE_LIMIT", "7")
t.Setenv("DS2API_DEV_PACKET_CAPTURE_MAX_BODY_BYTES", "8192")
t.Setenv("VERCEL", "")
t.Setenv("NOW_REGION", "")
s := NewFromEnv()
if s.Limit() != 7 {
t.Fatalf("expected override limit 7, got %d", s.Limit())
}
if s.MaxBodyBytes() != 8192 {
t.Fatalf("expected override max body bytes 8192, got %d", s.MaxBodyBytes())
}
}
func TestStorePushKeepsNewestWithinLimit(t *testing.T) {
s := &Store{enabled: true, limit: 2, maxBodyBytes: 1024}
for i := 0; i < 3; i++ {