refactor: variable names and modernize loop
This commit is contained in:
@@ -112,37 +112,37 @@ func newInMemoryRoundTripper(handler http.Handler) http.RoundTripper {
|
|||||||
return &inMemoryRoundTripper{handler: handler}
|
return &inMemoryRoundTripper{handler: handler}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rt *inMemoryRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
func (rt *inMemoryRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
|
||||||
if rt == nil || rt.handler == nil {
|
if rt == nil || rt.handler == nil {
|
||||||
return nil, fmt.Errorf("in-memory round tripper not initialized")
|
return nil, fmt.Errorf("in-memory round tripper not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
var bodyBytes []byte
|
var bodyBytes []byte
|
||||||
if req.Body != nil && req.Body != http.NoBody {
|
if request.Body != nil && request.Body != http.NoBody {
|
||||||
defer req.Body.Close()
|
defer request.Body.Close()
|
||||||
var err error
|
var err error
|
||||||
bodyBytes, err = io.ReadAll(req.Body)
|
bodyBytes, err = io.ReadAll(request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to read request body: %w", err)
|
return nil, fmt.Errorf("failed to read request body: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(bodyBytes) > 0 {
|
if len(bodyBytes) > 0 {
|
||||||
req.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
request.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
||||||
} else {
|
} else {
|
||||||
req.Body = http.NoBody
|
request.Body = http.NoBody
|
||||||
}
|
}
|
||||||
|
|
||||||
clonedReq := req.Clone(req.Context())
|
clonedRequest := request.Clone(request.Context())
|
||||||
if len(bodyBytes) > 0 {
|
if len(bodyBytes) > 0 {
|
||||||
clonedReq.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
clonedRequest.Body = io.NopCloser(bytes.NewReader(bodyBytes))
|
||||||
} else {
|
} else {
|
||||||
clonedReq.Body = http.NoBody
|
clonedRequest.Body = http.NoBody
|
||||||
}
|
}
|
||||||
clonedReq.RequestURI = clonedReq.URL.RequestURI()
|
clonedRequest.RequestURI = clonedRequest.URL.RequestURI()
|
||||||
|
|
||||||
recorder := httptest.NewRecorder()
|
recorder := httptest.NewRecorder()
|
||||||
rt.handler.ServeHTTP(recorder, clonedReq)
|
rt.handler.ServeHTTP(recorder, clonedRequest)
|
||||||
resp := recorder.Result()
|
resp := recorder.Result()
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
@@ -250,7 +250,7 @@ func tokenHash(token string) string {
|
|||||||
|
|
||||||
func retryOnRateLimit(t *testing.T, maxRetries int, operation func() int) int {
|
func retryOnRateLimit(t *testing.T, maxRetries int, operation func() int) int {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
for attempt := 0; attempt < maxRetries; attempt++ {
|
for attempt := range maxRetries {
|
||||||
statusCode := operation()
|
statusCode := operation()
|
||||||
if statusCode != http.StatusTooManyRequests {
|
if statusCode != http.StatusTooManyRequests {
|
||||||
return statusCode
|
return statusCode
|
||||||
|
|||||||
Reference in New Issue
Block a user