github.com/argoproj/argo-cd@v1.8.7/server/session/ratelimiter_test.go (about) 1 package session 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 util "github.com/argoproj/argo-cd/util/io" 9 "github.com/argoproj/argo-cd/util/session" 10 ) 11 12 func TestRateLimiter(t *testing.T) { 13 var closers []util.Closer 14 limiter := NewLoginRateLimiter(10) 15 for i := 0; i < 10; i++ { 16 closer, err := limiter() 17 assert.NoError(t, err) 18 closers = append(closers, closer) 19 } 20 // 11 request should fail 21 _, err := limiter() 22 assert.Equal(t, err, session.InvalidLoginErr) 23 24 if !assert.Equal(t, len(closers), 10) { 25 return 26 } 27 // complete one request 28 assert.NoError(t, closers[0].Close()) 29 _, err = limiter() 30 assert.NoError(t, err) 31 }