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

Test Helper: Raw Bodies #76

Open
jonthegeek opened this issue Jan 21, 2025 · 0 comments
Open

Test Helper: Raw Bodies #76

jonthegeek opened this issue Jan 21, 2025 · 0 comments

Comments

@jonthegeek
Copy link
Owner

I think it makes sense to add test helpers to beekeeper, since this is the dev-facing package.

It can be difficult to set up mock responses that don't contain private information, particularly for something like a raw body. Implement a helper to make this easier. It will probably be different per filetype, but this is something related to a fix for a CSV that someone wants to edit by hand:

resp <- original_httr2_resp
edited_csv_path <- "edited_file.csv"
save_path <- tempfile(fileext = ".csv.gz")
write_con <- gzfile(save_path, "wb")

readLines(edited_csv_path) |> 
  write.csv(write_con)
close(write_con)

read_con <- gzfile(save_path, "rb")
resp$body <- readBin(
  read_con,
  "raw",
  n = file.info(save_path)$size
)
close(read_con)
unlink(save_path)
dput(resp) # To copy/paste into the httptest2 file, or maybe use it and edit directly?

I'll need to experiment to see what makes sense as a helper. Images with {magick} might also be a thing, but I suspect gzipped CSVs will be the most common use case for this sort of editing.

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

No branches or pull requests

1 participant