From 33f5cb7df4af70cbae29a2c55eb062adb2027ea3 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 3 Mar 2021 20:53:40 -0800 Subject: [PATCH] more accurate naming; for now don't actually change how wings works --- remote/http.go | 8 ++++---- remote/http_test.go | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/remote/http.go b/remote/http.go index b75cd9e..82bc6d3 100644 --- a/remote/http.go +++ b/remote/http.go @@ -35,7 +35,7 @@ type client struct { baseUrl string tokenId string token string - retries int + attempts int } // New returns a new HTTP request client that is used for making authenticated @@ -46,7 +46,7 @@ func New(base string, opts ...ClientOption) Client { httpClient: &http.Client{ Timeout: time.Second * 15, }, - retries: 3, + attempts: 1, } for _, opt := range opts { opt(&c) @@ -96,10 +96,10 @@ func (c *client) requestOnce(ctx context.Context, method, path string, body io.R return &Response{res}, err } -// request executes a http request and retries when errors occur. +// request executes a http request and attempts when errors occur. // It appends the path to the endpoint of the client and adds the authentication token to the request. func (c *client) request(ctx context.Context, method, path string, body io.Reader, opts ...func(r *http.Request)) (res *Response, err error) { - for i := 0; i < c.retries; i++ { + for i := 0; i < c.attempts; i++ { res, err = c.requestOnce(ctx, method, path, body, opts...) if err == nil && res.StatusCode < http.StatusInternalServerError && diff --git a/remote/http_test.go b/remote/http_test.go index 7ba8685..67d59af 100644 --- a/remote/http_test.go +++ b/remote/http_test.go @@ -15,9 +15,9 @@ func createTestClient(h http.HandlerFunc) (*client, *httptest.Server) { httpClient: s.Client(), baseUrl: s.URL, - retries: 1, - tokenId: "testid", - token: "testtoken", + attempts: 1, + tokenId: "testid", + token: "testtoken", } return c, s } @@ -37,7 +37,7 @@ func TestRequest(t *testing.T) { } func TestRequestRetry(t *testing.T) { - // Test if the client retries failed requests + // Test if the client attempts failed requests i := 0 c, _ := createTestClient(func(rw http.ResponseWriter, r *http.Request) { if i < 1 { @@ -47,7 +47,7 @@ func TestRequestRetry(t *testing.T) { } i++ }) - c.retries = 2 + c.attempts = 2 r, err := c.request(context.Background(), "", "", nil) assert.NoError(t, err) assert.NotNil(t, r) @@ -60,7 +60,7 @@ func TestRequestRetry(t *testing.T) { rw.WriteHeader(http.StatusInternalServerError) i++ }) - c.retries = 2 + c.attempts = 2 r, err = c.request(context.Background(), "get", "", nil) assert.NoError(t, err) assert.NotNil(t, r)