more accurate naming; for now don't actually change how wings works

This commit is contained in:
Dane Everitt 2021-03-03 20:53:40 -08:00
parent 8897be661b
commit 33f5cb7df4
2 changed files with 10 additions and 10 deletions

View File

@ -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 &&

View File

@ -15,7 +15,7 @@ func createTestClient(h http.HandlerFunc) (*client, *httptest.Server) {
httpClient: s.Client(),
baseUrl: s.URL,
retries: 1,
attempts: 1,
tokenId: "testid",
token: "testtoken",
}
@ -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)