mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-14 13:15:07 +08:00
feat: implement raw sample capture querying and persistence, and add environment-based configuration for dev capture store.
This commit is contained in:
@@ -14,8 +14,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
defaultLimit = 5
|
||||
defaultMaxBodyBytes = 2 * 1024 * 1024
|
||||
defaultLimit = 20
|
||||
defaultMaxBodyBytes = 5 * 1024 * 1024
|
||||
maxLimit = 50
|
||||
)
|
||||
|
||||
|
||||
@@ -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++ {
|
||||
|
||||
Reference in New Issue
Block a user