fix: HitQuota should be returned instead of Allowed when limit is equal to 1. (#1581)

This commit is contained in:
qi
2022-03-04 16:14:45 +08:00
committed by GitHub
parent 0c35f39a7d
commit 96c128c58a
2 changed files with 12 additions and 2 deletions

View File

@@ -65,3 +65,13 @@ func testPeriodLimit(t *testing.T, opts ...PeriodOption) {
assert.Equal(t, 1, hitQuota)
assert.Equal(t, total-quota, overQuota)
}
func TestQuotaFull(t *testing.T) {
s, err := miniredis.Run()
assert.Nil(t, err)
l := NewPeriodLimit(1, 1, redis.New(s.Addr()), "periodlimit")
val, err := l.Take("first")
assert.Nil(t, err)
assert.Equal(t, HitQuota, val)
}