Debian Codegraph @

tests/testthat/test-connection.R

raw
1 h <- new_handle()
2
3 test_that("Compression and destroying connection", {
4 # Compression is broken in 8.7.1, see https://github.com/curl/curl/issues/13493
5 skip_if(curl::curl_version()$version == '8.7.1')
6 con <- curl(httpbin("deflate"), handle = h)
7 expect_equal(jsonlite::fromJSON(readLines(con))$deflate, TRUE)
8 expect_false(isOpen(con))
9 close(con) #destroy
10
11 expect_equal(jsonlite::fromJSON(rawToChar(curl_fetch_memory(httpbin("deflate"), handle = h)$content))$deflate, TRUE)
12
13 con <- curl(httpbin("gzip"), handle = h)
14 expect_equal(jsonlite::fromJSON(readLines(con))$gzipped, TRUE)
15 expect_false(isOpen(con))
16 close(con) #destroy
17
18 expect_equal(jsonlite::fromJSON(rawToChar(curl_fetch_memory(httpbin("gzip"), handle = h)$content))$gzipped, TRUE)
19 })
20
21 test_that("Connection interface", {
22 # note: jsonlite automatically destroys auto-opened connection
23 con <- curl(httpbin("get?test=blabla"), handle = h)
24 expect_equal(jsonlite::fromJSON(con)$args$test, "blabla")
25
26 # test error
27 con <- curl(httpbin("status/418"))
28 expect_error(expect_warning(readLines(con), '418'), 'cannot open')
29 close(con) #destroy
30
31 # test not error
32 con <- curl(httpbin("status/418"), handle = h)
33 open(con, "rf")
34 expect_is(readLines(con), "character")
35 expect_equal(handle_data(h)$status_code, 418L)
36 close(con) #destroy
37 })
38
39 test_that("Can retrieve fds from a connection", {
40 con <- curl(httpbin("get?test=blabla"), handle = h)
41 fds <- multi_fdset(con)
42 expect_type(fds, "list")
43 close(con)
44 not <- "not a connection"
45 class(not) <- "curl"
46 expect_error(multi_fdset(not))
47 })