-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
178 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#' Setup Tests Infrastructure | ||
#' | ||
|
||
## Temporary Directory ---- | ||
|
||
create_tempdir <- function(path = file.path(tempdir(), "sandbox")) { | ||
|
||
old_wd <- getwd() | ||
|
||
withr::defer(fs::dir_delete(path), envir = parent.frame()) | ||
|
||
dir.create(path) | ||
|
||
setwd(path) | ||
|
||
withr::defer(setwd(old_wd), envir = parent.frame()) | ||
|
||
invisible(path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
## zenodo_id() ---- | ||
|
||
test_that("Test zenodo_id() for success", { | ||
|
||
x <- zenodo_id() | ||
|
||
expect_equal(x, "7390791") | ||
|
||
expect_equal(class(x), "character") | ||
expect_equal(length(x), 1L) | ||
}) | ||
|
||
|
||
|
||
## check_version() ---- | ||
|
||
test_that("Test check_version() for error", { | ||
|
||
expect_error(check_version(), | ||
"Argument 'version' is required", | ||
fixed = TRUE) | ||
|
||
expect_error(check_version(NA), | ||
"Argument 'version' must be character", | ||
fixed = TRUE) | ||
|
||
expect_error(check_version(6), | ||
"Argument 'version' must be character", | ||
fixed = TRUE) | ||
|
||
expect_error(check_version(character(0)), | ||
"Argument 'version' must be character of length 1", | ||
fixed = TRUE) | ||
|
||
expect_error(check_version(c("06", "07")), | ||
"Argument 'version' must be character of length 1", | ||
fixed = TRUE) | ||
}) | ||
|
||
test_that("Test check_version() for success", { | ||
|
||
x <- check_version(NULL) | ||
expect_null(x) | ||
|
||
x <- check_version("06") | ||
expect_null(x) | ||
|
||
expect_invisible(check_version("06")) | ||
}) | ||
|
||
|
||
## get_metadata() ---- | ||
|
||
test_that("Test get_metadata() for success", { | ||
|
||
x <- get_metadata() | ||
|
||
expect_equal(class(x), "list") | ||
expect_true("hits" %in% names(x)) | ||
expect_true(x$"hits"$"total" > 0L) | ||
}) | ||
|
||
|
||
|
||
## get_available_versions() ---- | ||
|
||
test_that("Test get_available_versions() for success", { | ||
|
||
x <- get_available_versions() | ||
|
||
expect_equal(class(x), "data.frame") | ||
expect_true(nrow(x) > 0L) | ||
expect_equal(ncol(x), 3L) | ||
|
||
expect_true("publication_date" %in% colnames(x)) | ||
expect_true("version" %in% colnames(x)) | ||
expect_true("access_right" %in% colnames(x)) | ||
}) | ||
|
||
|
||
|
||
## get_version_info() ---- | ||
|
||
test_that("Test get_version_info() for error", { | ||
|
||
expect_error(get_version_info(version = "999"), | ||
paste0("The required version is not available. Please run ", | ||
"'get_available_versions()' to list available versions."), | ||
fixed = TRUE) | ||
}) | ||
|
||
test_that("Test get_version_info() for success", { | ||
|
||
x <- get_version_info(version = NULL) | ||
|
||
expect_equal(class(x), "list") | ||
expect_true("version" %in% names(x)) | ||
expect_true("files" %in% names(x)) | ||
|
||
x <- get_version_info(version = "08") | ||
|
||
expect_equal(class(x), "list") | ||
expect_true("version" %in% names(x)) | ||
expect_true("files" %in% names(x)) | ||
|
||
expect_true(x$"version" == "08") | ||
expect_true(x$"publication_date" == "2024-02-09") | ||
}) | ||
|
||
|
||
|
||
## get_latest_version() ---- | ||
|
||
test_that("Test get_latest_version() for success", { | ||
|
||
x <- get_latest_version() | ||
|
||
expect_equal(class(x), "character") | ||
}) | ||
|
||
|
||
|
||
## save_version() ---- | ||
|
||
test_that("Test save_version() for success", { | ||
|
||
create_tempdir() | ||
|
||
expect_invisible(save_version("06")) | ||
expect_true(file.exists(".forcis")) | ||
expect_equal(readLines(".forcis"), "FORCIS_VERSION=06") | ||
|
||
x <- save_version("07") | ||
expect_null(x) | ||
expect_true(file.exists(".forcis")) | ||
expect_equal(readLines(".forcis"), "FORCIS_VERSION=07") | ||
}) | ||
|
||
|
||
|
||
## get_current_version() ---- | ||
|
||
test_that("Test get_current_version() for success", { | ||
|
||
create_tempdir() | ||
|
||
x <- get_current_version() | ||
expect_null(x) | ||
|
||
save_version("07") | ||
x <- get_current_version() | ||
expect_equal(class(x), "character") | ||
expect_equal(length(x), 1L) | ||
expect_equal(x, "07") | ||
}) | ||
|
||
|
||
|
||
## set_version() ---- |