@@ -251,6 +251,9 @@ func testNewRequestAndDoFailureCategory(t *testing.T, methodName string, client
251251 client .BaseURL .Path = "/api-v3/"
252252 client .rateLimits [category ].Reset .Time = time .Now ().Add (10 * time .Minute )
253253 resp , err = f ()
254+ if client .DisableRateLimitCheck {
255+ return
256+ }
254257 if bypass := resp .Request .Context ().Value (BypassRateLimitCheck ); bypass != nil {
255258 return
256259 }
@@ -1912,6 +1915,79 @@ func TestDo_rateLimit_abuseRateLimitError_maxDuration(t *testing.T) {
19121915 }
19131916}
19141917
1918+ // Make network call if client has disabled the rate limit check.
1919+ func TestDo_rateLimit_disableRateLimitCheck (t * testing.T ) {
1920+ t .Parallel ()
1921+ client , mux , _ := setup (t )
1922+ client .DisableRateLimitCheck = true
1923+
1924+ reset := time .Now ().UTC ().Add (60 * time .Second )
1925+ client .rateLimits [CoreCategory ] = Rate {Limit : 5000 , Remaining : 0 , Reset : Timestamp {reset }}
1926+ requestCount := 0
1927+ mux .HandleFunc ("/" , func (w http.ResponseWriter , _ * http.Request ) {
1928+ requestCount ++
1929+ w .Header ().Set (headerRateLimit , "5000" )
1930+ w .Header ().Set (headerRateRemaining , "5000" )
1931+ w .Header ().Set (headerRateUsed , "0" )
1932+ w .Header ().Set (headerRateReset , fmt .Sprint (reset .Add (time .Hour ).Unix ()))
1933+ w .Header ().Set (headerRateResource , "core" )
1934+ w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
1935+ w .WriteHeader (http .StatusOK )
1936+ fmt .Fprintln (w , `{}` )
1937+ })
1938+ req , _ := client .NewRequest ("GET" , "." , nil )
1939+ ctx := context .Background ()
1940+ resp , err := client .Do (ctx , req , nil )
1941+ if err != nil {
1942+ t .Errorf ("Do returned unexpected error: %v" , err )
1943+ }
1944+ if got , want := resp .StatusCode , http .StatusOK ; got != want {
1945+ t .Errorf ("Response status code = %v, want %v" , got , want )
1946+ }
1947+ if got , want := requestCount , 1 ; got != want {
1948+ t .Errorf ("Expected 1 request, got %d" , got )
1949+ }
1950+ if got , want := client .rateLimits [CoreCategory ].Remaining , 0 ; got != want {
1951+ t .Errorf ("Expected 0 requests remaining, got %d" , got )
1952+ }
1953+ }
1954+
1955+ // Make network call if client has bypassed the rate limit check.
1956+ func TestDo_rateLimit_bypassRateLimitCheck (t * testing.T ) {
1957+ t .Parallel ()
1958+ client , mux , _ := setup (t )
1959+
1960+ reset := time .Now ().UTC ().Add (60 * time .Second )
1961+ client .rateLimits [CoreCategory ] = Rate {Limit : 5000 , Remaining : 0 , Reset : Timestamp {reset }}
1962+ requestCount := 0
1963+ mux .HandleFunc ("/" , func (w http.ResponseWriter , _ * http.Request ) {
1964+ requestCount ++
1965+ w .Header ().Set (headerRateLimit , "5000" )
1966+ w .Header ().Set (headerRateRemaining , "5000" )
1967+ w .Header ().Set (headerRateUsed , "0" )
1968+ w .Header ().Set (headerRateReset , fmt .Sprint (reset .Add (time .Hour ).Unix ()))
1969+ w .Header ().Set (headerRateResource , "core" )
1970+ w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
1971+ w .WriteHeader (http .StatusOK )
1972+ fmt .Fprintln (w , `{}` )
1973+ })
1974+ req , _ := client .NewRequest ("GET" , "." , nil )
1975+ ctx := context .Background ()
1976+ resp , err := client .Do (context .WithValue (ctx , BypassRateLimitCheck , true ), req , nil )
1977+ if err != nil {
1978+ t .Errorf ("Do returned unexpected error: %v" , err )
1979+ }
1980+ if got , want := resp .StatusCode , http .StatusOK ; got != want {
1981+ t .Errorf ("Response status code = %v, want %v" , got , want )
1982+ }
1983+ if got , want := requestCount , 1 ; got != want {
1984+ t .Errorf ("Expected 1 request, got %d" , got )
1985+ }
1986+ if got , want := client .rateLimits [CoreCategory ].Remaining , 5000 ; got != want {
1987+ t .Errorf ("Expected 5000 requests remaining, got %d" , got )
1988+ }
1989+ }
1990+
19151991func TestDo_noContent (t * testing.T ) {
19161992 t .Parallel ()
19171993 client , mux , _ := setup (t )
0 commit comments