Skip to content

Commit da08bdc

Browse files
committed
Fix comment
1 parent e803233 commit da08bdc

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ package wrappers
22

33
import (
44
"errors"
5+
"github.com/stretchr/testify/assert"
56
"net/http"
67
"testing"
7-
"time"
8-
9-
"github.com/stretchr/testify/assert"
108
)
119

1210
type mockReadCloser struct{}
@@ -27,7 +25,7 @@ func TestRetryHTTPRequest_Success(t *testing.T) {
2725
}, nil
2826
}
2927

30-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
28+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
3129
assert.NoError(t, err)
3230
assert.NotNil(t, resp)
3331
assert.Equal(t, http.StatusOK, resp.StatusCode)
@@ -37,7 +35,7 @@ func TestRetryHTTPRequest_RetryOnBadGateway(t *testing.T) {
3735
attempts := 0
3836
fn := func() (*http.Response, error) {
3937
attempts++
40-
if attempts < 4 {
38+
if attempts < retryAttempts {
4139
return &http.Response{
4240
StatusCode: http.StatusBadGateway,
4341
Body: &mockReadCloser{},
@@ -49,19 +47,19 @@ func TestRetryHTTPRequest_RetryOnBadGateway(t *testing.T) {
4947
}, nil
5048
}
5149

52-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
50+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
5351
assert.NoError(t, err)
5452
assert.NotNil(t, resp)
5553
assert.Equal(t, http.StatusOK, resp.StatusCode)
56-
assert.Equal(t, 4, attempts)
54+
assert.Equal(t, retryAttempts, attempts)
5755
}
5856

5957
func TestRetryHTTPRequest_Fail(t *testing.T) {
6058
fn := func() (*http.Response, error) {
6159
return nil, errors.New("network error")
6260
}
6361

64-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
62+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
6563
assert.Error(t, err)
6664
assert.Nil(t, resp)
6765
}
@@ -74,7 +72,7 @@ func TestRetryHTTPRequest_EndWithBadGateway(t *testing.T) {
7472
}, nil
7573
}
7674

77-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
75+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
7876
assert.NoError(t, err)
7977
assert.NotNil(t, resp)
8078
assert.Equal(t, http.StatusBadGateway, resp.StatusCode)

internal/wrappers/projects-http.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"net/http"
8-
"time"
9-
107
"github.com/pkg/errors"
118
"github.com/spf13/viper"
9+
"net/http"
1210

1311
errorConstants "github.com/checkmarx/ast-cli/internal/constants/errors"
1412
commonParams "github.com/checkmarx/ast-cli/internal/params"
@@ -34,7 +32,7 @@ func (p *ProjectsHTTPWrapper) Create(model *Project) (*ProjectResponseModel, *Er
3432
fn := func() (*http.Response, error) {
3533
return SendHTTPRequest(http.MethodPost, p.path, bytes.NewBuffer(jsonBytes), true, clientTimeout)
3634
}
37-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
35+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
3836
if err != nil {
3937
return nil, nil, err
4038
}
@@ -56,7 +54,7 @@ func (p *ProjectsHTTPWrapper) Update(projectID string, model *Project) error {
5654
fn := func() (*http.Response, error) {
5755
return SendHTTPRequest(http.MethodPut, fmt.Sprintf("%s/%s", p.path, projectID), bytes.NewBuffer(jsonBytes), true, clientTimeout)
5856
}
59-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
57+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
6058
if err != nil {
6159
return err
6260
}
@@ -89,7 +87,7 @@ func (p *ProjectsHTTPWrapper) UpdateConfiguration(projectID string, configuratio
8987
fn := func() (*http.Response, error) {
9088
return SendHTTPRequestWithQueryParams(http.MethodPatch, "api/configuration/project", params, bytes.NewBuffer(jsonBytes), clientTimeout)
9189
}
92-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
90+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
9391
if err != nil {
9492
return nil, err
9593
}
@@ -113,7 +111,7 @@ func (p *ProjectsHTTPWrapper) Get(params map[string]string) (
113111
fn := func() (*http.Response, error) {
114112
return SendHTTPRequestWithQueryParams(http.MethodGet, p.path, params, nil, clientTimeout)
115113
}
116-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
114+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
117115
if err != nil {
118116
return nil, nil, err
119117
}
@@ -154,7 +152,7 @@ func (p *ProjectsHTTPWrapper) GetByID(projectID string) (
154152
fn := func() (*http.Response, error) {
155153
return SendHTTPRequest(http.MethodGet, p.path+"/"+projectID, http.NoBody, true, clientTimeout)
156154
}
157-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
155+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
158156
if err != nil {
159157
return nil, nil, err
160158
}
@@ -201,7 +199,7 @@ func (p *ProjectsHTTPWrapper) GetBranchesByID(projectID string, params map[strin
201199
fn := func() (*http.Response, error) {
202200
return SendHTTPRequestWithQueryParams(http.MethodGet, p.path+request, params, nil, clientTimeout)
203201
}
204-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
202+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
205203
if err != nil {
206204
return nil, nil, err
207205
}
@@ -239,7 +237,7 @@ func (p *ProjectsHTTPWrapper) Delete(projectID string) (*ErrorModel, error) {
239237
fn := func() (*http.Response, error) {
240238
return SendHTTPRequest(http.MethodDelete, p.path+"/"+projectID, http.NoBody, true, clientTimeout)
241239
}
242-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
240+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
243241
if err != nil {
244242
return nil, err
245243
}
@@ -260,7 +258,7 @@ func (p *ProjectsHTTPWrapper) Tags() (
260258
fn := func() (*http.Response, error) {
261259
return SendHTTPRequest(http.MethodGet, p.path+"/tags", http.NoBody, true, clientTimeout)
262260
}
263-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
261+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
264262
if err != nil {
265263
return nil, nil, err
266264
}

internal/wrappers/scans-http.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const (
1616
failedToParseGetAll = "Failed to parse list response"
1717
failedToParseTags = "Failed to parse tags response"
1818
failedToParseBranches = "Failed to parse branches response"
19+
retryAttempts = 4
20+
retryDelay = 500 * time.Millisecond
1921
)
2022

2123
type ScansHTTPWrapper struct {
@@ -40,7 +42,7 @@ func (s *ScansHTTPWrapper) Create(model *Scan) (*ScanResponseModel, *ErrorModel,
4042
fn := func() (*http.Response, error) {
4143
return SendHTTPRequest(http.MethodPost, s.path, bytes.NewBuffer(jsonBytes), true, clientTimeout)
4244
}
43-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
45+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
4446
if err != nil {
4547
return nil, nil, err
4648
}
@@ -58,7 +60,7 @@ func (s *ScansHTTPWrapper) Get(params map[string]string) (*ScansCollectionRespon
5860
fn := func() (*http.Response, error) {
5961
return SendHTTPRequestWithQueryParams(http.MethodGet, s.path, params, nil, clientTimeout)
6062
}
61-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
63+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
6264
if err != nil {
6365
return nil, nil, err
6466
}
@@ -98,7 +100,7 @@ func (s *ScansHTTPWrapper) GetByID(scanID string) (*ScanResponseModel, *ErrorMod
98100
fn := func() (*http.Response, error) {
99101
return SendHTTPRequest(http.MethodGet, s.path+"/"+scanID, http.NoBody, true, clientTimeout)
100102
}
101-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
103+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
102104
if err != nil {
103105
return nil, nil, err
104106
}
@@ -117,7 +119,7 @@ func (s *ScansHTTPWrapper) GetWorkflowByID(scanID string) ([]*ScanTaskResponseMo
117119
fn := func() (*http.Response, error) {
118120
return SendHTTPRequest(http.MethodGet, path, http.NoBody, true, clientTimeout)
119121
}
120-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
122+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
121123
if err != nil {
122124
return nil, nil, err
123125
}
@@ -162,7 +164,7 @@ func (s *ScansHTTPWrapper) Delete(scanID string) (*ErrorModel, error) {
162164
fn := func() (*http.Response, error) {
163165
return SendHTTPRequest(http.MethodDelete, s.path+"/"+scanID, http.NoBody, true, clientTimeout)
164166
}
165-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
167+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
166168
if err != nil {
167169
return nil, err
168170
}
@@ -186,7 +188,7 @@ func (s *ScansHTTPWrapper) Cancel(scanID string) (*ErrorModel, error) {
186188
fn := func() (*http.Response, error) {
187189
return SendHTTPRequest(http.MethodPatch, s.path+"/"+scanID, bytes.NewBuffer(b), true, clientTimeout)
188190
}
189-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
191+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
190192
if err != nil {
191193
return nil, err
192194
}
@@ -204,7 +206,7 @@ func (s *ScansHTTPWrapper) Tags() (map[string][]string, *ErrorModel, error) {
204206
fn := func() (*http.Response, error) {
205207
return SendHTTPRequest(http.MethodGet, s.path+"/tags", http.NoBody, true, clientTimeout)
206208
}
207-
resp, err := retryHTTPRequest(fn, 4, 500*time.Millisecond)
209+
resp, err := retryHTTPRequest(fn, retryAttempts, retryDelay)
208210
if err != nil {
209211
return nil, nil, err
210212
}

0 commit comments

Comments
 (0)