Skip to content

Commit

Permalink
test: additional test cases to rpc rate limiting interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
JadhavPoonam committed Jan 23, 2023
1 parent 7781edf commit 312f635
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion agent/rpc/middleware/interceptors_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package middleware

import (
"errors"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -278,7 +279,26 @@ func TestGetNetRPCRateLimitingInterceptor(t *testing.T) {

listener, _ := net.Listen("tcp", "127.0.0.1:0")

t.Run("Allow panics", func(t *testing.T) {
t.Run("allow operation", func(t *testing.T) {
limiter.On("Allow", mock.Anything).
Return(nil).
Once()

err := rateLimitInterceptor("Status.Leader", listener.Addr())
require.NoError(t, err)
})

t.Run("allow returns error", func(t *testing.T) {
limiter.On("Allow", mock.Anything).
Return(errors.New("uh oh")).
Once()

err := rateLimitInterceptor("Status.Leader", listener.Addr())
require.Error(t, err)
require.Equal(t, "uh oh", err.Error())
})

t.Run("allow panics", func(t *testing.T) {
limiter.On("Allow", mock.Anything).
Panic("uh oh").
Once()
Expand Down

0 comments on commit 312f635

Please sign in to comment.