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

Mock file path not altered #19

Closed
mpadge opened this issue May 24, 2022 · 1 comment
Closed

Mock file path not altered #19

mpadge opened this issue May 24, 2022 · 1 comment

Comments

@mpadge
Copy link

mpadge commented May 24, 2022

First off @nealrichardson, thanks so much for this awesome package! I've just started switching all my pkgs over to httr2 + httptest2, and this package make mock testing so easy. Awesome work!

Now to business: The following reprex demonstrates that, although gsub_response() should also modify the request via #8, the file path in httr::req_body_file() is not modified:

f <- tempfile ("data-", fileext = ".dat")
saveRDS (datasets::Orange, f)
u <- "https://my.upload.site"
req <- httr2::request (u) |>
    httr2::req_method ("PUT") |>
    httr2::req_headers ("Content-Type" = "application/octet-stream") |>
    httr2::req_body_file (path = f)

req$body$data
#> [1] "/tmp/RtmpW0CH4X/data-417e1b18af5c.dat"
#> attr(,"class")
#> [1] "httr2_path"

httptest2::gsub_response (
    req$body,
    paste0 ("[A-Za-z0-9]*", .Platform$file.sep, "data\\-"),
    paste0 ("tempdir", .Platform$file.sep, "data-"))
#> $data
#> [1] "/tmp/RtmpW0CH4X/data-417e1b18af5c.dat"
#> attr(,"class")
#> [1] "httr2_path"
#> 
#> $type
#> [1] "raw-file"
#> 
#> $content_type
#> [1] ""
#> 
#> $params
#> list()
#> 
#> $url
#> character(0)

Created on 2022-05-24 by the reprex package (v2.0.1)

The files output by httptest2 then have a part of the tempdir hash in their names, and so are not able to be reproduced, leading to test failures. In other words, a function issuing the req given above fails mock tests because the paths differ each time the test is run. I'd really appreciate any help you could offer. Thanks!

@mpadge
Copy link
Author

mpadge commented May 24, 2022

Whoops, my mistake - I'm also including my own internal hash in the body text, and that is changing between calls. Problem is with me, and not this package. Sorry 'bout that, and keep up the good work!

@mpadge mpadge closed this as completed May 24, 2022
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