github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/libkb/ratelimit_test.go (about) 1 // Copyright 2015 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package libkb 5 6 import ( 7 "testing" 8 "time" 9 ) 10 11 func TestRateLimit(t *testing.T) { 12 tc := SetupTest(t, "rateLimit", 0) 13 defer tc.Cleanup() 14 limits := NewRateLimits(tc.G) 15 if !limits.GetPermission(TestEventRateLimit, 1*time.Minute) { 16 t.Fatal("expected to get permission") 17 } 18 if !limits.GetPermission(TestEventRateLimit, 0) { 19 t.Fatal("expected to get permission again with a zero interval") 20 } 21 if limits.GetPermission(TestEventRateLimit, 1*time.Minute) { 22 t.Fatal("expected not to get permission with a long interval") 23 } 24 }