Skip to content

Commit

Permalink
remove trimws for workspace names with leading space, closes #86 (#87)
Browse files Browse the repository at this point in the history
* remove trimws for workspace names with leading space, closes #86

- no effect for trailing spaces

* isolate .avworkspaces_clean and test
  • Loading branch information
LiNk-NY authored Sep 7, 2023
1 parent 2ca65d9 commit 2cb3948
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
34 changes: 19 additions & 15 deletions R/avworkspace.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ NULL
}
})

.avworkspaces_clean <- function(.data) {
.data |>
select(
name = .data$workspace.name,
lastModified = .data$workspace.lastModified,
createdBy = .data$workspace.createdBy,
namespace = .data$workspace.namespace,
accessLevel = .data$accessLevel
) |>
mutate(
lastModified = as.Date(.data$lastModified)
) |>
arrange(
.data$name,
desc(.data$lastModified)
)
}

#' @rdname avworkspace
#'
#' @description `avworkspaces()` returns a tibble with available
Expand All @@ -45,21 +63,7 @@ avworkspaces <-
.avstop_for_status(response, "avworkspaces")

flatten(response) %>%
select(
name = .data$workspace.name,
lastModified = .data$workspace.lastModified,
createdBy = .data$workspace.createdBy,
namespace = .data$workspace.namespace,
accessLevel = .data$accessLevel
) %>%
mutate(
name = trimws(.data$name),
lastModified = as.Date(.data$lastModified)
) %>%
arrange(
.data$name,
desc(.data$lastModified)
)
.avworkspaces_clean()
}

#' @rdname avworkspace
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test_av.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,28 @@ test_that(".avbucket_path() trims arguments correctly", {
.avbucket_path("gs://foo", "bar", c("baz", "bing"))
)
})

test_that(".av_workspaces_clean() preserves leading and trailing spaces", {
## add intentional spaces in workspace.name
testws <- tibble::tibble(
workspace.name = " a test workspace ",
workspace.lastModified = "2023-06-26T21:17:26.343Z",
workspace.createdBy = "[email protected]",
workspace.namespace = "bioconductor-rpci-anvil",
accessLevel = "READER",
extraCol = TRUE
)
restbl <- testws
## for testing names
coi <- c("name", "lastModified", "createdBy", "namespace", "accessLevel")
names(restbl) <- coi
## for testing select operation
restbl <- restbl[, coi]
## for testing Date coercion
restbl[["lastModified"]] <- as.Date(restbl[["lastModified"]])

expect_identical(
.avworkspaces_clean(testws),
restbl
)
})

0 comments on commit 2cb3948

Please sign in to comment.