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

Fix port issue #266

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: Record test suite 'HTTP' requests and replays them during
real 'HTTP' responses on disk in 'cassettes'. Subsequent 'HTTP' requests
matching any previous requests in the same 'cassette' use a cached
'HTTP' response.
Version: 1.2.2.91
Version: 1.2.2.93
Authors@R: c(person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID="0000-0003-1444-9135")),
Expand Down Expand Up @@ -48,7 +48,8 @@ Suggests:
crayon,
cli,
curl,
withr
withr,
webfakes
X-schema.org-applicationCategory: Web
X-schema.org-keywords: http, https, API, web-services, curl, mock, mocking, http-mocking, testing, testing-tools, tdd
X-schema.org-isPartOf: https://ropensci.org
Expand Down
3 changes: 2 additions & 1 deletion R/cassette_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ Cassette <- R6::R6Class(
x$request_headers
},
opts = self$cassette_opts,
disk = is_disk
disk = is_disk,
skip_port_stripping = TRUE
)

response <- VcrResponse$new(
Expand Down
8 changes: 5 additions & 3 deletions R/request_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Request <- R6::R6Class(
body = NULL,
#' @field headers (character) named list
headers = NULL,
#' @field skip_port_stripping (logical) whether to strip thhe port
#' @field skip_port_stripping (logical) whether to strip the port
skip_port_stripping = FALSE,
#' @field hash (character) a named list - internal use
hash = NULL,
Expand All @@ -62,9 +62,11 @@ Request <- R6::R6Class(
#' @param disk (boolean), is body a file on disk
#' @param fields (various) post fields
#' @param output (various) output details
#' @param skip_port_stripping (logical) whether to strip the port.
#' default: `FALSE`
#' @return A new `Request` object
initialize = function(method, uri, body, headers, opts, disk,
fields, output) {
fields, output, skip_port_stripping = FALSE) {

if (!missing(method)) self$method <- tolower(method)
if (!missing(body)) {
Expand All @@ -75,7 +77,7 @@ Request <- R6::R6Class(
}
if (!missing(headers)) self$headers <- headers
if (!missing(uri)) {
if (!self$skip_port_stripping) {
if (!skip_port_stripping) {
self$uri <- private$without_standard_port(uri)
} else {
self$uri <- uri
Expand Down
17 changes: 15 additions & 2 deletions man/Request.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 25 additions & 14 deletions revdep/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
# Platform

|field |value |
|:--------|:----------------------------|
|version |R version 4.1.0 (2021-05-18) |
|os |macOS Big Sur 10.16 |
|system |x86_64, darwin17.0 |
|ui |X11 |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |US/Pacific |
|date |2021-05-31 |
|field |value |
|:--------|:-----------------------------------|
|version |R version 4.3.2 (2023-10-31) |
|os |macOS Ventura 13.6.3 |
|system |aarch64, darwin20 |
|ui |X11 |
|language |(EN) |
|collate |en_US.UTF-8 |
|ctype |en_US.UTF-8 |
|tz |America/Los_Angeles |
|date |2024-01-09 |
|pandoc |3.1.11.1 @ /opt/homebrew/bin/pandoc |

# Dependencies

|package |old |new |Δ |
|:-------|:-----|:-----|:--|
|vcr |1.0.0 |1.0.2 |* |
|package |old |new |Δ |
|:---------|:-----|:--------|:--|
|vcr |1.2.2 |1.2.2.91 |* |
|askpass |NA |1.2.0 |* |
|curl |NA |5.2.0 |* |
|httr |NA |1.4.7 |* |
|openssl |NA |2.1.1 |* |
|Rcpp |NA |1.0.11 |* |
|rprojroot |NA |2.0.4 |* |
|sys |NA |3.4.2 |* |
|triebeard |NA |0.4.1 |* |
|whisker |NA |0.4.1 |* |
|yaml |NA |2.3.8 |* |

# Revdeps

2 changes: 1 addition & 1 deletion revdep/cran.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## revdepcheck results

We checked 52 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.
We checked 66 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package.

* We saw 0 new problems
* We failed to check 0 packages
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/helper-vcr.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ codes <- vapply(out, "[[", 1, "status_code")
if (!any(codes == 200)) stop("all httpbin servers down")
base_url <- urls[codes == 200][1]
cat(paste0("using base url for tests: ", base_url), sep = "\n")

# httpbin local
local_httpbin_app <- function() {
check_for_a_pkg("webfakes")
webfakes::local_app_process(
webfakes::httpbin_app(),
.local_envir = testthat::teardown_env()
)
}
33 changes: 33 additions & 0 deletions tests/testthat/test-localhost_port.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# orginally via https://github.com/ropensci/vcr/issues/264

tmpdir <- tempdir()
vcr_configure(dir = tmpdir)

test_that("testing against localhost port works", {
# httpbin <- webfakes::local_app_process(webfakes::httpbin_app())
httpbin <- local_httpbin_app()
url <- httpbin$url("/status/404")
port <- httpbin$get_port()

# real request w/o vcr
resp <- httr::GET(url)
expect_s3_class(resp, "response")

# real request w/ vcr
use_cassette("localhost_port", {
resp <- httr::GET(url)
# check that response object is correct
expect_s3_class(resp, "response")
})

# check that the port is actually in the cassette file
path <- file.path(tmpdir, "localhost_port.yml")
file <- yaml::yaml.load_file(path)
url <- file$http_interactions[[1]]$request$uri
expect_is(url, "character")
expect_match(url, "http://.+:[0-9]+/")
expect_match(url, as.character(port))
})

# reset configuration
vcr_configure_reset()