-
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.
Centralize some of the common test definitions.
- Added some tests for correct deregistration. - Added explicit tests for non-recursive listFiles. - Wrap tests in functions so that on.exit triggers for deregistration.
- Loading branch information
Showing
6 changed files
with
88 additions
and
51 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,17 @@ | ||
basic_config <- function() { | ||
# Starting up an example SewerRat service: | ||
info <- SewerRat::startSewerRat() | ||
|
||
# Mocking up a directory of stuff to query. | ||
mydir <- tempfile() | ||
dir.create(mydir) | ||
write(file=file.path(mydir, "metadata.json"), '{ "first": "Aaron", "last": "Lun" }') | ||
|
||
dir.create(file.path(mydir, "diet")) | ||
write(file=file.path(mydir, "diet", "metadata.json"), '{ "meal": "lunch", "ingredients": "water" }') | ||
|
||
# Registering it: | ||
SewerRat::register(mydir, "metadata.json", url=info$url) | ||
|
||
list(info=info, mydir=mydir) | ||
} |
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,24 @@ | ||
# library(testthat); library(SewerRat); source("setup.R"); source("test-listFiles.R") | ||
|
||
(function() { | ||
|
||
config <- basic_config() | ||
info <- config$info | ||
mydir <- config$mydir | ||
on.exit(deregister(mydir, url=info$url), add=TRUE, after=FALSE) | ||
|
||
test_that("listFiles works as expected", { | ||
all <- listFiles(mydir, info$url) | ||
expect_identical(sort(all), c("diet/metadata.json", "metadata.json")) | ||
|
||
all <- listFiles(mydir, info$url, recursive=FALSE) | ||
expect_identical(sort(all), c("diet/", "metadata.json")) | ||
|
||
all <- listFiles(paste0(mydir, "/diet"), info$url) | ||
expect_identical(sort(all), "metadata.json") | ||
|
||
all <- listFiles(mydir, info$url, forceRemote=TRUE) | ||
expect_identical(sort(all), c("diet/metadata.json", "metadata.json")) | ||
}) | ||
|
||
})() |
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
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 @@ | ||
# library(testthat); library(SewerRat); source("setup.R"); source("test-register.R") | ||
|
||
(function(){ | ||
|
||
config <- basic_config() | ||
info <- config$info | ||
mydir <- config$mydir | ||
on.exit(deregister(mydir, url=info$url), add=TRUE, after=FALSE) | ||
|
||
test_that("(de)registration works as expected", { | ||
res <- query("aaron", url=info$url) | ||
expect_identical(length(res), 1L) | ||
|
||
deregister(mydir, url=info$url) | ||
res <- query("aaron", url=info$url) | ||
expect_identical(length(res), 0L) | ||
}) | ||
|
||
})() |
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