Skip to content

Test Helper: Raw Bodies #76

@jonthegeek

Description

@jonthegeek

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions