Skip to content

Commit

Permalink
fix: fix panic in HTTPGetAndAssert (#109)
Browse files Browse the repository at this point in the history
Issue #, if available:

*Description of changes:*
fix panic in fnet. When HTTP err != nil the test panics due to `err`
shadowing the `err` declared outside the for loop.
*Testing done:*
Yes. 


- [X] I've reviewed the guidance in CONTRIBUTING.md


#### License Acceptance

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license.

Signed-off-by: Vishwas Siravara <[email protected]>
  • Loading branch information
vsiravar authored Jan 6, 2024
1 parent a268e81 commit b572343
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fnet/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@ import (

// HTTPGetAndAssert sends an HTTP GET request to the specified URL, asserts the response status code against want, and closes the response body.
func HTTPGetAndAssert(url string, want int, maxRetry int, retryInterval time.Duration) {
var err error
var (
err error
resp *http.Response
)
client := http.Client{
Timeout: 5 * time.Second,
}

for i := 0; i < maxRetry; i++ {
// #nosec G107 // it does not matter if url is not a constant for testing.
resp, err := client.Get(url)
resp, err = client.Get(url)
if err != nil {
time.Sleep(retryInterval)
continue
Expand Down

0 comments on commit b572343

Please sign in to comment.