Skip to content

Commit

Permalink
Use entire api object in API tests.
Browse files Browse the repository at this point in the history
The API tests used to setup individual endpoints to run the tests. That
is a bit verbose and duplicates a bunch of code from the `api.R` file.

This will be made much worse when we introduce `url` parameters to all
the endpoints, since all the tests will need to make a API call to fetch
the repository first, which will lead to more boilerplate.

Using the api object solves this issue.
  • Loading branch information
plietar committed Jan 15, 2025
1 parent 6287f46 commit 4c0ab5b
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 163 deletions.
33 changes: 15 additions & 18 deletions tests/testthat/helper-orderly-runner.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
orderly_runner_endpoint <- function(
method, path,
root = NULL,
repositories = NULL,
validate = TRUE,
skip_queue_creation = FALSE
) {
if (skip_queue_creation) {
queue <- NULL
} else {
queue <- Queue$new(root)
create_api <- function(root = NULL,
repositories = NULL,
log_level = "off",
...,
.local_envir = parent.frame()) {
if (is.null(repositories)) {
repositories <- withr::local_tempdir()
}
porcelain::porcelain_package_endpoint(
"orderly.runner", method, path,
state = list(root = root,
repositories_base_path = repositories,
queue = queue),
validate = validate
)

api(root, repositories, validate = TRUE, log_level = log_level, ...)
}


expect_success <- function(res) {
expect_equal(res$status, 200)
invisible(jsonlite::fromJSON(res$body)$data)
}


Expand Down
Loading

0 comments on commit 4c0ab5b

Please sign in to comment.