Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Jan 10, 2025
1 parent 44fd81c commit 29ec725
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion R/class_store_repository_cas.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ tar_repository_cas_lookup <- function(store) {
return(lookup)
}
list_method <- .subset2(methods, "list")
if (all(list_method == "NULL")) {
if (!any(nzchar(list_method))) {
return(lookup_new())
}
keys_meta <- as.character(lookup)
Expand Down
8 changes: 6 additions & 2 deletions R/class_store_repository_cas_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,23 @@ store_repository_cas_methods_validate <- function(methods) {
tar_assert_scalar(methods$repository)
tar_assert_nzchar(methods$repository)
tar_assert_correct_fields(methods, store_repository_cas_methods_new)
for (field in c("upload", "download", "exists", "list")) {
for (field in c("upload", "download")) {
tar_assert_chr(methods[[field]])
tar_assert_scalar(methods[[field]])
tar_assert_nzchar(methods[[field]])
}
for (field in c("exists", "list")) {
tar_assert_chr(methods[[field]])
tar_assert_scalar(methods[[field]])
}
tar_assert_scalar(methods[["consistent"]])
tar_assert_lgl(methods[["consistent"]])
tar_assert_none_na(methods[["consistent"]])
}

store_repository_cas_field <- function(repository, pattern, prefix = "") {
text <- base64url::base64_urldecode(keyvalue_field(repository, pattern))
if (text != "NULL") {
if (nzchar(text)) {
text <- paste0(prefix, text)
}
text
Expand Down
3 changes: 3 additions & 0 deletions R/tar_repository_cas.R
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@ tar_repository_cas <- function(
}

tar_repository_cas_field <- function(key, value) {
if (is.null(value)) {
return(paste0(key, "="))
}
if (is.function(value)) {
value <- body(value)
}
Expand Down
13 changes: 6 additions & 7 deletions tests/testthat/test-tar_repository_cas.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tar_test("tar_repository_cas() generates an encoded string", {
expect_equal(out[1], "repository_cas")
expect_true(any(grepl("^upload=+.", out)))
expect_true(any(grepl("^download=+.", out)))
expect_true(any(grepl("^exists=+.", out)))
expect_true(any(grepl("^exists=*.", out)))
expect_true(any(grepl("^list=+.", out)))
expect_true(any(grepl("^consistent=+.", out)))
})
Expand All @@ -41,10 +41,7 @@ tar_test("tar_repository_cas() keeps 'exists' at the right times", {
consistent = TRUE
)
out <- unlist(strsplit(out, split = "&", fixed = TRUE))
exists <- base64url::base64_urldecode(
gsub("^exists=", "", out[grepl("^exists=+.", out)])
)
expect_equal(exists, "NULL")
expect_true(any(out == "exists="))
out <- tar_repository_cas(
upload = function(key, path) {
file.copy(path, file.path("cas", key))
Expand All @@ -64,7 +61,8 @@ tar_test("tar_repository_cas() keeps 'exists' at the right times", {
exists <- base64url::base64_urldecode(
gsub("^exists=", "", out[grepl("^exists=+.", out)])
)
expect_false(exists == "NULL")
expect_true(nzchar(exists))
expect_false(any(out == "exists="))
for (consistent in c(TRUE, FALSE)) {
out <- tar_repository_cas(
upload = function(key, path) {
Expand All @@ -82,7 +80,8 @@ tar_test("tar_repository_cas() keeps 'exists' at the right times", {
exists <- base64url::base64_urldecode(
gsub("^exists=", "", out[grepl("^exists=+.", out)])
)
expect_false(exists == "NULL")
expect_true(nzchar(exists))
expect_false(any(out == "exists="))
}
})

Expand Down

0 comments on commit 29ec725

Please sign in to comment.