Skip to content

Commit ecc94c0

Browse files
committed
Added bindings for validating a version directory.
Also updated the required version of the Gobbler API.
1 parent 45885e2 commit ecc94c0

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export(startGobbler)
2929
export(stopGobbler)
3030
export(unpackPath)
3131
export(uploadDirectory)
32+
export(validateVersion)
3233
export(versionPath)
3334
import(httr2)
3435
import(methods)

R/startGobbler.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#'
3737
#' @export
3838
#' @importFrom utils download.file
39-
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.4.3", overwrite = FALSE) {
39+
startGobbler <- function(staging=tempfile(), registry=tempfile(), port = NULL, wait = 1, version = "0.5.0", overwrite = FALSE) {
4040
if (!is.null(running$active)) {
4141
return(list(new=FALSE, staging=running$staging, registry=running$registry, port=running$port, url=assemble_url(running$port)))
4242
}

R/validateVersion.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#' Validate a versioned asset
2+
#'
3+
#' Check the validity of a version of an asset of a project from the registry.
4+
#' This compares the size, MD5 checksums and link information in the internal \code{..manifest} and \code{..links} files to the contents of the directory in the registry.
5+
#'
6+
#' @param project String containing the project to remove.
7+
#' @param asset String containing the asset to remove.
8+
#' @param version String containing the version of the asset to remove.
9+
#' @inheritParams createProject
10+
#'
11+
#' @return \code{NULL} is invisibly returned if the version is valid, otherwise an error is thrown.
12+
#'
13+
#' @author Aaron Lun
14+
#'
15+
#' @examples
16+
#' info <- startGobbler()
17+
#' removeProject("test", info$staging, url=info$url) # start with a clean slate.
18+
#' createProject("test", info$staging, url=info$url)
19+
#'
20+
#' # Mocking up a version if it doesn't already exist.
21+
#' src <- allocateUploadDirectory(info$staging)
22+
#' write(file=file.path(src, "foo"), "BAR")
23+
#' uploadDirectory("test", "simple", "v1", src, staging=info$staging, url=info$url)
24+
#'
25+
#' # Validation has no issue.
26+
#' validateVersion("test", "simple", "v1", staging=info$staging, url=info$url)
27+
#'
28+
#' # Let's add a new file directly to the directory and rerun the validation.
29+
#' write(file=file.path(info$registry, "test", "simple", "v1", "whee"), "stuff")
30+
#' try(validateVersion("test", "simple", "v1", staging=info$staging, url=info$url))
31+
#'
32+
#' @export
33+
validateVersion <- function(project, asset, version, staging, url) {
34+
dump_request(staging, url, "validate_version", list(project=project, asset=asset, version=version))
35+
invisible(NULL)
36+
}
37+

man/startGobbler.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/validateVersion.Rd

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# library(testthat); library(gobbler); source("test-validateVersion.R")
2+
3+
info <- startGobbler()
4+
removeProject("test-R-validate", staging=info$staging, url=info$url)
5+
createProject("test-R-validate", staging=info$staging, url=info$url)
6+
7+
test_that("validation functions work as expected", {
8+
src <- allocateUploadDirectory(info$staging)
9+
write(file=file.path(src, "foo"), "BAR")
10+
uploadDirectory("test-R-validate", "simple", "v1", src, staging=info$staging, url=info$url)
11+
expect_error(validateVersion("test-R-validate", "simple", "v1", staging=info$staging, url=info$url), NA)
12+
13+
# Let's add a new file directly to the directory.
14+
write(file=file.path(info$registry, "test-R-validate", "simple", "v1", "whee"), "stuff")
15+
expect_error(validateVersion("test-R-validate", "simple", "v1", staging=info$staging, url=info$url), "extra file \"whee\"")
16+
})

0 commit comments

Comments
 (0)