package api import ( "context" "testing" "atlas9.dev/c/core/throttle" ) func TestAccountThrottle_AllowsNormalLogin(t *testing.T) { at := NewAccountThrottle(throttle.NewMemoryBucket()) ctx := context.Background() if !at.Check(ctx, "user@example.com") { t.Error("normal login should be allowed") } } func TestAccountThrottle_BlocksAfterEmailExhausted(t *testing.T) { at := NewAccountThrottle(throttle.NewMemoryBucket()) at.EmailRefillRate = 0 // disable refill for test ctx := context.Background() for i := 0; i < at.EmailCapacity; i++ { if !at.Check(ctx, "user@example.com") { t.Errorf("attempt %d should be allowed", i+1) } } if at.Check(ctx, "user@example.com") { t.Error("should be denied after email capacity exhausted") } }