These functions can be used to temporarily mock responses from the Connect server, which is useful for writing tests that verify the behaviour of viewer-based or service account credentials.
Usage
with_mocked_connect_responses(
code,
mock = NULL,
token = NULL,
error = FALSE,
env = caller_env()
)
local_mocked_connect_responses(
mock = NULL,
token = NULL,
error = FALSE,
env = caller_env()
)Arguments
- code
Code to execute in the temporary environment.
- mock
A function, a list, or
NULL.NULLdisables mocking and returns httr2 to regular operation.A list of responses will be returned in sequence. After all responses have been used up, will return 503 server errors.
For maximum flexibility, you can supply a function that that takes a single argument,
req, and returns eitherNULL(if it doesn't want to handle the request) or a response (if it does).
- token
When not
NULL, return this token from the Connect server.- error
When
TRUE, return an error from the Connect server.- env
Environment to use for scoping changes.
Examples
with_mocked_connect_responses(
connect_viewer_token(),
token = "test"
)
#> <httr2_token>
#> * token_type : "Bearer"
#> * access_token : <REDACTED>
#> * issued_token_type: "urn:ietf:params:oauth:token-type:access_token"
with_mocked_connect_responses(
connect_service_account_token(),
token = "test"
)
#> <httr2_token>
#> * token_type : "Bearer"
#> * access_token : <REDACTED>
#> * issued_token_type: "urn:ietf:params:oauth:token-type:access_token"