Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HaveHTTPBody Does Not Work with Eventually #682

Closed
Kyle-Cooley opened this issue Jul 18, 2023 · 3 comments · Fixed by #686
Closed

HaveHTTPBody Does Not Work with Eventually #682

Kyle-Cooley opened this issue Jul 18, 2023 · 3 comments · Fixed by #686

Comments

@Kyle-Cooley
Copy link
Contributor

The following code does not work as expected when the first attempt does not succeed:

Eventually(func(ctx SpecContext) (*http.Response, error) {
  req, err := http.NewRequestWithContext(ctx, http.MethodPost, "http://localhost:8080/test", strings.NewReader(query))
  req.Header.Add("Content-Type", "application/json")
  if err != nil {
    return nil, err
  }
  return http.DefaultClient.Do(req)
}).
  WithContext(ctx).
  WithPolling(5 * time.Second).
  WithTimeout(30 * time.Second).
  Should(HaveHTTPBody(MatchJSON(expectedResult)))

This appears to be caused by the use of a cached variable that is never updated after being set:
https://github.com/onsi/gomega/blob/master/matchers/have_http_body_matcher.go#L76

@Kyle-Cooley
Copy link
Contributor Author

Kyle-Cooley commented Jul 18, 2023

Possible solution:
Store the pointer for the response and use that to determine if the cache should be used or not.

@onsi
Copy link
Owner

onsi commented Jul 22, 2023

hey @Kyle-Cooley - good catch; agreed on checking the pointer as you're proposing. Would you be up for submitting a PR?

@Kyle-Cooley
Copy link
Contributor Author

Hello @onsi , yes, I will make a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants