Skip to content

HaveHTTPBody Does Not Work with Eventually #682

@Kyle-Cooley

Description

@Kyle-Cooley

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions