Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions tests/testthat/test-get_container.R
Original file line number Diff line number Diff line change
@@ -1,41 +0,0 @@
test_that("simple failing tests for missing env vars", {
skip_on_ci()
withr::with_envvar(c(AZ_CONTAINER = ""), get_container()) |>
expect_error("`AZ_CONTAINER` is not set", class = "rlang_error")

c(AZ_CONTAINER = "results", AZ_STORAGE_EP = "") |>
withr::with_envvar(get_container()) |>
expect_error("`AZ_STORAGE_EP` is not set", class = "rlang_error")
})

test_that("basic success", {
endpoint_uri <- Sys.getenv("AZ_STORAGE_EP")
# only run the test if this variable is set (ie locally, but not on GitHub)
if (nzchar(endpoint_uri)) {
token <- get_auth_token() # should return NULL if unsuccessful
expect_false(is.null(token))
expect_s3_class(token, "AzureToken")

# explore behaviour with blob_endpoint
ep <- AzureStor::blob_endpoint(endpoint_uri, token = token) |>
expect_no_error()
expect_s3_class(ep, "blob_endpoint")
cont <- expect_no_error(AzureStor::blob_container(ep, "supporting-data"))
expect_s3_class(cont, "blob_container")

expect_error(AzureStor::list_adls_files(cont))
expect_no_error(AzureStor::list_blobs(cont))

# compare behaviour with adls_endpoint instead (it's the same)
ep <- AzureStor::adls_endpoint(endpoint_uri, token = token)
expect_s3_class(ep, "adls_endpoint")
fs <- AzureStor::adls_filesystem(ep, "results") |>
expect_no_error()
expect_s3_class(fs, "adls_filesystem")
path <- "/archive/dev/synthetic"
# Expected this to succeed with adls_endpoint but it doesn't
expect_error(AzureStor::list_adls_files(fs, path))
# list_blobs works just like it does with the blob container
expect_no_error(AzureStor::list_blobs(fs, path))
}
})
75 changes: 0 additions & 75 deletions tests/testthat/test-list_files.R
Original file line number Diff line number Diff line change
@@ -1,78 +1,3 @@
test_that("function behaves as expected", {
skip_on_ci()
cont <- expect_no_error(get_container("supporting-data"))
res <- expect_no_error(AzureStor::list_blobs(cont))
expect_equal(nrow(res), 15L)
res2 <- dplyr::filter(res, !dplyr::if_any("isdir"))
expect_equal(nrow(res2), 14L)
file_ext <- NULL
file_ext <- file_ext %||% ".*"
res3 <- res2 |>
dplyr::filter(dplyr::if_any("name", \(x) gregg(x, "\\.{file_ext}$")))
expect_equal(nrow(res2), nrow(res3)) # because nothing filtered out yet
file_ext <- "json"
res4 <- res2 |>
dplyr::filter(dplyr::if_any("name", \(x) gregg(x, "\\.{file_ext}$")))
expect_equal(nrow(res4), 6L)
})

test_that("we can evolve list_files()", {
endpoint_uri <- Sys.getenv("AZ_STORAGE_EP")
# only run the test if this variable is set (ie locally, but not on GitHub)
if (nzchar(endpoint_uri)) {
cont <- expect_no_error(get_container("supporting-data"))

list_files <- \(container) AzureStor::list_blobs(container)
expect_equal(nrow(expect_no_error(list_files(cont))), 15L)

list_files <- function(container, recursive = TRUE) {
AzureStor::list_blobs(container, recursive = recursive) |>
dplyr::filter(!dplyr::if_any("isdir")) |>
dplyr::pull("name")
}
expect_length(expect_no_error(list_files(cont)), 14L)

list_files <- function(container, file_ext = ".*", recursive = TRUE) {
AzureStor::list_blobs(container, recursive = recursive) |>
dplyr::filter(
!dplyr::if_any("isdir") &
dplyr::if_any("name", \(x) gregg(x, "\\.{file_ext}$"))
) |>
dplyr::pull("name")
}
expect_length(expect_no_error(list_files(cont, "json", FALSE)), 6L)
expect_true(rlang::is_bare_character(list_files(cont, "json")))

list_files <- function(container, path = "", ext = ".*", recursive = TRUE) {
stopifnot("path not found" = AzureStor::blob_dir_exists(container, path))
tbl <- AzureStor::list_blobs(container, dir = path, recursive = recursive)
if (nrow(tbl) == 0) {
character(0)
} else {
tbl |>
dplyr::filter(
!dplyr::if_any("isdir") &
dplyr::if_any("name", \(x) gregg(x, "\\.{ext}$"))
) |>
dplyr::pull("name")
}
}
expect_length(list_files(cont), 14L)
expect_length(list_files(cont, ext = "json"), 6L)
# root folder can be specified as "" or "/", it doesn't matter
expect_length(list_files(cont, "/", "json"), 6L)
# no files with this extension present - but should not error
expect_length(expect_no_error(list_files(cont, ext = "xlsx")), 0L)

expect_no_error(list_files(cont, "QA")) # folder QA should exist
expect_no_error(list_files(cont, "/QA")) # /QA also works
expect_length(list_files(cont, "QA"), 0)
# folder does not exist
expect_error(list_files(cont, "BLAH"), "path not found")
}
})


test_that("edited path starts with '/' unless it's the root folder", {
fix_path <- \(path) sub("^/+$", "", sub("^([^/])(.*)", "/\\1\\2", path))
expect_equal(fix_path("/"), "")
Expand Down
Loading
Loading