httr2 icon indicating copy to clipboard operation
httr2 copied to clipboard

mocking iterative requests

Open asadow opened this issue 1 year ago • 0 comments

My function my_perform() uses httr2::req_perform_iterative() which has a max_reqs argument (default to 20). I'd like to test that my_perform() performs an infinite or very large number of iterative requests.

For now I am testing the argument:

test_that("my_perform() performs Inf requests by default", {
  expect_equal(formals(my_perform)$max_reqs, Inf)
})

Is this ideal or is it instead better to mock a large request? I created a fake response with data removed which allows for

with_mock_api({
  test_that("my_perform() returns API page_count responses", {
    responses<- my_req("my_endpoint") |> my_perform()
    expect_length(responses, 21)
  })
})

I also don't understand why the above requires 2 mock files, endpoint.R and endpoint-6fdf2d.R.

asadow avatar May 17 '24 18:05 asadow