Configure HttpClient, added context parameter to all methods (#37)
Context is needed to limit time of execution of a method. Previously, context was passed to structure and it was stored inside structure which is a bad practice. Now we need to pass context to function, which is a best practice
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
testTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
type TestRequestRequest struct {
|
||||
@@ -55,7 +61,8 @@ func TestRequest(t *testing.T) {
|
||||
c := NewMockClient(NewMockHttpHandler(test.statusCode, test.response, test.headers))
|
||||
|
||||
respStruct := &TestRequestResponse{}
|
||||
resp, err := c.Request(http.MethodPost, "/", test.params, respStruct, nil)
|
||||
ctx, _ := context.WithTimeout(context.Background(), testTimeout)
|
||||
resp, err := c.Request(ctx, http.MethodPost, "/", test.params, respStruct, nil)
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
|
||||
Reference in New Issue
Block a user