File: test-req-dry-run.R

package info (click to toggle)
r-cran-httr2 1.1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,604 kB
  • sloc: sh: 21; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
test_that("req_dry_run() returns useful data", {
  resp <- request("http://example.com") %>%
    req_dry_run(quiet = TRUE, testing_headers = FALSE)
  expect_equal(resp$method, "GET")
  expect_equal(resp$path, "/")
  expect_match(resp$headers$`user-agent`, "libcurl")
})

test_that("body is shown", {
  req <- request("http://example.com")

  # can display UTF-8 characters
  req_utf8 <- req_body_raw(req, "CenĂ¡rio", type = "text/plain")
  expect_snapshot(req_dry_run(req_utf8))

  # json is prettified by default
  req_json <- req_body_raw(req, '{"x":1,"y":true}', type = "application/json")
  expect_snapshot(req_dry_run(req_json))
  expect_snapshot(req_dry_run(req_json, pretty_json = FALSE))

  # doesn't show binary data
  req_binary <- req_body_raw(req, "CenĂ¡rio")
  expect_snapshot(req_dry_run(req_binary))
})

test_that("authorization headers are redacted", {
  req <- request("http://example.com") %>% req_auth_basic("user", "password")
  expect_snapshot(req_dry_run(req))
})

test_that("doen't add space to urls (#567)", {
  req <- request("https://example.com/test:1:2")
  expect_output(req_dry_run(req), "test:1:2")
})