github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/plugin/rate/rate_limit_logger_test.go (about) 1 package rate 2 3 import ( 4 "net/http" 5 "testing" 6 7 "github.com/hellofresh/stats-go" 8 "github.com/stretchr/testify/assert" 9 "github.com/ulule/limiter/v3" 10 "github.com/ulule/limiter/v3/drivers/store/memory" 11 12 "github.com/hellofresh/janus/pkg/test" 13 ) 14 15 func TestSuccessfulRateLimitLog(t *testing.T) { 16 statsClient, _ := stats.NewClient("noop://") 17 limiterStore := memory.NewStore() 18 rate, _ := limiter.NewRateFromFormatted("100-M") 19 limiterInstance := limiter.New(limiterStore, rate) 20 21 mw := NewRateLimitLogger(limiterInstance, statsClient, false) 22 w, err := test.Record( 23 "GET", 24 "/", 25 map[string]string{ 26 "Content-Type": "application/json", 27 }, 28 mw(http.HandlerFunc(test.Ping)), 29 ) 30 assert.NoError(t, err) 31 32 assert.Equal(t, http.StatusOK, w.Code) 33 assert.Equal(t, "application/json", w.Header().Get("Content-Type")) 34 }