Update tests.
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>
{
text <- rawToChar(response$content)
doc <- XML::xmlParse(text, asText=TRUE)
- base <- paste(paste("/", strsplit(uri, "/")[[1]][-1:-3], sep="", collapse=""), "/", sep="")
+ base <- paste("/", strsplit(uri, "/")[[1]][4], "/", sep="")
result <- unlist(
XML::xpathApply(doc, "//D:response/D:href", function(node) {
sub(base, "", URLdecode(XML::xmlValue(node)), fixed=TRUE)
})
)
- result <- result[result != ""]
- result[-1]
+ result[result != ""]
},
getFileSizesFromResponse = function(response, uri)
{
if(is.null(private$webDavHostName))
{
- discoveryDocumentURL <- paste0("https://", private$rawHostName,
- "/discovery/v1/apis/arvados/v1/rest")
+ publicConfigURL <- paste0("https://", private$rawHostName,
+ "/arvados/v1/config")
- headers <- list(Authorization = paste("OAuth2", self$token))
-
- serverResponse <- self$http$exec("GET", discoveryDocumentURL, headers,
- retryTimes = self$numRetries)
+ serverResponse <- self$http$exec("GET", publicConfigURL, retryTimes = self$numRetries)
- discoveryDocument <- self$httpParser$parseJSONResponse(serverResponse)
- private$webDavHostName <- discoveryDocument$keepWebServiceUrl
+ configDocument <- self$httpParser$parseJSONResponse(serverResponse)
+ private$webDavHostName <- configDocument$Services$WebDAVDownload$ExternalURL
if(is.null(private$webDavHostName))
stop("Unable to find WebDAV server.")
collectionURL <- URLencode(paste0(self$getWebDavHostName(),
"c=", uuid))
- headers <- list("Authorization" = paste("OAuth2", self$token))
+ headers <- list("Authorization" = paste("Bearer", self$token))
response <- self$http$exec("PROPFIND", collectionURL, headers,
retryTimes = self$numRetries)
# SPDX-License-Identifier: Apache-2.0
getAPIDocument <- function(){
- url <- "https://4xphq.arvadosapi.com/discovery/v1/apis/arvados/v1/rest"
+ url <- "https://ce8i5.arvadosapi.com/discovery/v1/apis/arvados/v1/rest"
serverResponse <- httr::RETRY("GET", url = url)
httr::content(serverResponse, as = "parsed", type = "application/json")
dog <- ArvadosFile$new("dog")
responseIsNull <- is.null(dog$get("something"))
- expect_that(responseIsNull, is_true())
+ expect_true(responseIsNull)
})
test_that("getFirst always returns NULL", {
dog <- ArvadosFile$new("dog")
responseIsNull <- is.null(dog$getFirst())
- expect_that(responseIsNull, is_true())
+ expect_true(responseIsNull)
})
test_that(paste("getSizeInBytes returns zero if arvadosFile",
dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
dogExistsOnNewLocation <- !is.null(collection$get("dog"))
- expect_that(dogIsNullOnOldLocation, is_true())
- expect_that(dogExistsOnNewLocation, is_true())
+ expect_true(dogIsNullOnOldLocation)
+ expect_true(dogExistsOnNewLocation)
})
test_that(paste("copy raises exception if arvados file",
dogExistsOnOldLocation <- !is.null(collection$get("animal/dog"))
dogExistsOnNewLocation <- !is.null(collection$get("dog"))
- expect_that(dogExistsOnOldLocation, is_true())
- expect_that(dogExistsOnNewLocation, is_true())
+ expect_true(dogExistsOnOldLocation)
+ expect_true(dogExistsOnNewLocation)
})
test_that("duplicate performs deep cloning of Arvados file", {
dog <- collection$get("animal/dog")
dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
- expect_that(dogExistsInCollection, is_true())
+ expect_true(dogExistsInCollection)
expect_that(fakeREST$createCallCount, equals(1))
})
dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
- expect_that(dogExistsInCollection, is_true())
- expect_that(catExistsInCollection, is_true())
+ expect_true(dogExistsInCollection)
+ expect_true(catExistsInCollection)
expect_that(fakeREST$createCallCount, equals(2))
})
dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
- expect_that(dogExistsInCollection, is_false())
- expect_that(catExistsInCollection, is_false())
+ expect_false(dogExistsInCollection)
+ expect_false(catExistsInCollection)
expect_that(fakeREST$deleteCallCount, equals(2))
})
dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
dogExistsOnNewLocation <- !is.null(collection$get("dog"))
- expect_that(dogIsNullOnOldLocation, is_true())
- expect_that(dogExistsOnNewLocation, is_true())
+ expect_true(dogIsNullOnOldLocation)
+ expect_true(dogExistsOnNewLocation)
expect_that(fakeREST$moveCallCount, equals(1))
})
contentMatchExpected <- all(collection$getFileListing() ==
c("animal", "animal/fish", "ball"))
- expect_that(contentMatchExpected, is_true())
+ expect_true(contentMatchExpected)
#2 calls because Collection$new calls getFileListing once
expect_that(fakeREST$getCollectionContentCallCount, equals(2))
fish <- collection$get("animal/fish")
fishIsNotNull <- !is.null(fish)
- expect_that(fishIsNotNull, is_true())
+ expect_true(fishIsNotNull)
expect_that(fish$getName(), equals("fish"))
})
dogExistsOnOldLocation <- !is.null(collection$get("animal/dog"))
dogExistsOnNewLocation <- !is.null(collection$get("dog"))
- expect_that(dogExistsOnOldLocation, is_true())
- expect_that(dogExistsOnNewLocation, is_true())
+ expect_true(dogExistsOnOldLocation)
+ expect_true(dogExistsOnNewLocation)
expect_that(fakeREST$copyCallCount, equals(1))
})
boat$getCollection() == "myCollection"
expect_that(root$getName(), equals(""))
- expect_that(rootIsOfTypeSubcollection, is_true())
- expect_that(rootHasNoParent, is_true())
- expect_that(animalIsOfTypeSubcollection, is_true())
- expect_that(animalsParentIsRoot, is_true())
- expect_that(animalContainsDog, is_true())
- expect_that(dogIsOfTypeArvadosFile, is_true())
- expect_that(dogsParentIsAnimal, is_true())
- expect_that(boatIsOfTypeArvadosFile, is_true())
- expect_that(boatsParentIsRoot, is_true())
- expect_that(allElementsBelongToSameCollection, is_true())
+ expect_true(rootIsOfTypeSubcollection)
+ expect_true(rootHasNoParent)
+ expect_true(animalIsOfTypeSubcollection)
+ expect_true(animalsParentIsRoot)
+ expect_true(animalContainsDog)
+ expect_true(dogIsOfTypeArvadosFile)
+ expect_true(dogsParentIsAnimal)
+ expect_true(boatIsOfTypeArvadosFile)
+ expect_true(boatsParentIsRoot)
+ expect_true(allElementsBelongToSameCollection)
})
test_that("getElement returns element from tree if element exists on specified path", {
fish <- collectionTree$getElement("animal/fish")
fishIsNULL <- is.null(fish)
- expect_that(fishIsNULL, is_true())
+ expect_true(fishIsNULL)
})
test_that("getElement trims ./ from start of relativePath", {
result <- parser$parseJSONResponse(serverResponse)
barExists <- !is.null(result$bar)
- expect_that(barExists, is_true())
+ expect_true(barExists)
expect_that(unlist(result$bar$foo), equals(10))
})
webDAVResponseSample =
paste0("<?xml version=\"1.0\" encoding=\"UTF-8\"?><D:multistatus xmlns:",
- "D=\"DAV:\"><D:response><D:href>/c=aaaaa-bbbbb-ccccccccccccccc</D",
+ "D=\"DAV:\"><D:response><D:href>/c=aaaaa-bbbbb-ccccccccccccccc/</D",
":href><D:propstat><D:prop><D:resourcetype><D:collection xmlns:D=",
"\"DAV:\"/></D:resourcetype><D:getlastmodified>Fri, 11 Jan 2018 1",
"1:11:11 GMT</D:getlastmodified><D:displayname></D:displayname><D",
expectedResult <- "myFile.exe"
resultMatchExpected <- all.equal(result, expectedResult)
- expect_that(resultMatchExpected, is_true())
+ expect_true(resultMatchExpected)
})
test_that(paste("getFileSizesFromResponse returns file sizes",
result <- parser$getFileSizesFromResponse(serverResponse, url)
resultMatchExpected <- result == expectedResult
- expect_that(resultMatchExpected, is_true())
+ expect_true(resultMatchExpected)
})
http <- HttpRequest$new()
http$exec("GET", "url")
- expect_that(add_headersCalled, is_true())
- expect_that(retryCalled, is_true())
+ expect_true(add_headersCalled)
+ expect_true(retryCalled)
expect_that(expectedConfig$options, equals(list(ssl_verifypeer = 0L)))
})
http <- HttpRequest$new()
http$getConnection("location", list(), "r")
- expect_that(new_handleCalled, is_true())
- expect_that(handle_setheadersCalled, is_true())
- expect_that(handle_setoptCalled, is_true())
- expect_that(curlCalled, is_true())
+ expect_true(new_handleCalled)
+ expect_true(handle_setheadersCalled)
+ expect_true(handle_setoptCalled)
+ expect_true(curlCalled)
})
test_that("getWebDavHostName calls REST service properly", {
- expectedURL <- "https://host/discovery/v1/apis/arvados/v1/rest"
- serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
+ expectedURL <- "https://host/arvados/v1/config"
+ serverResponse <- list(Services = list(WebDAVDownload = list(ExternalURL = "https://myWebDavServer.com")))
httpRequest <- FakeHttpRequest$new(expectedURL, serverResponse)
REST <- RESTService$new("token", "host",
REST$getWebDavHostName()
- expect_that(httpRequest$URLIsProperlyConfigured, is_true())
- expect_that(httpRequest$requestHeaderContainsAuthorizationField, is_true())
+ expect_true(httpRequest$URLIsProperlyConfigured)
+ expect_false(httpRequest$requestHeaderContainsAuthorizationField)
expect_that(httpRequest$numberOfGETRequests, equals(1))
})
test_that("getWebDavHostName returns webDAV host name properly", {
- serverResponse <- list(keepWebServiceUrl = "https://myWebDavServer.com")
+ serverResponse <- list(Services = list(WebDAVDownload = list(ExternalURL = "https://myWebDavServer.com")))
httpRequest <- FakeHttpRequest$new(expectedURL = NULL, serverResponse)
REST <- RESTService$new("token", "host",
REST$create("file", uuid)
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
expect_that(fakeHttp$numberOfPUTRequests, equals(1))
})
REST$delete("file", uuid)
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
expect_that(fakeHttp$numberOfDELETERequests, equals(1))
})
REST$move("file", "newDestination/file", uuid)
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
- expect_that(fakeHttp$requestHeaderContainsDestinationField, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
+ expect_true(fakeHttp$requestHeaderContainsDestinationField)
expect_that(fakeHttp$numberOfMOVERequests, equals(1))
})
REST$copy("file", "newDestination/file", uuid)
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
- expect_that(fakeHttp$requestHeaderContainsDestinationField, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
+ expect_true(fakeHttp$requestHeaderContainsDestinationField)
expect_that(fakeHttp$numberOfCOPYRequests, equals(1))
})
returnedContentMatchExpected <- all.equal(returnResult,
c("animal", "animal/dog", "ball"))
- expect_that(returnedContentMatchExpected, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
+ expect_true(returnedContentMatchExpected)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
})
test_that("getCollectionContent raises exception if server returns empty response", {
returnedContentMatchExpected <- all.equal(returnResult,
c(6, 2, 931, 12003))
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
- expect_that(returnedContentMatchExpected, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
+ expect_true(returnedContentMatchExpected)
})
test_that("getResourceSize raises exception if server returns empty response", {
returnResult <- REST$read("file", uuid, "text", 1024, 512)
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
- expect_that(fakeHttp$requestHeaderContainsRangeField, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
+ expect_true(fakeHttp$requestHeaderContainsRangeField)
expect_that(returnResult, equals("file content"))
})
REST$write("file", uuid, fileContent, "text/html")
- expect_that(fakeHttp$URLIsProperlyConfigured, is_true())
- expect_that(fakeHttp$requestBodyIsProvided, is_true())
- expect_that(fakeHttp$requestHeaderContainsAuthorizationField, is_true())
- expect_that(fakeHttp$requestHeaderContainsContentTypeField, is_true())
+ expect_true(fakeHttp$URLIsProperlyConfigured)
+ expect_true(fakeHttp$requestBodyIsProvided)
+ expect_true(fakeHttp$requestHeaderContainsAuthorizationField)
+ expect_true(fakeHttp$requestHeaderContainsContentTypeField)
})
test_that("write raises exception if server response code is not between 200 and 300", {
resultsMatch <- length(expectedResult) == length(result) &&
all(expectedResult == result)
- expect_that(resultsMatch, is_true())
+ expect_true(resultsMatch)
})
test_that(paste("getFileListing returns sorted names of all direct children",
resultsMatch <- length(expectedResult) == length(result) &&
all(expectedResult == result)
- expect_that(resultsMatch, is_true())
+ expect_true(resultsMatch)
})
test_that("add adds content to inside collection tree", {
animalContainsFish <- animal$get("fish")$getName() == fish$getName()
animalContainsDog <- animal$get("dog")$getName() == dog$getName()
- expect_that(animalContainsFish, is_true())
- expect_that(animalContainsDog, is_true())
+ expect_true(animalContainsFish)
+ expect_true(animalContainsDog)
})
test_that("add raises exception if content name is empty string", {
returnValueAfterRemovalIsNull <- is.null(animal$get("fish"))
- expect_that(returnValueAfterRemovalIsNull, is_true())
+ expect_true(returnValueAfterRemovalIsNull)
})
test_that(paste("remove raises exception",
returnedFishIsSubcollection <- "Subcollection" %in% class(returnedFish)
returnedDogIsArvadosFile <- "ArvadosFile" %in% class(returnedDog)
- expect_that(returnedFishIsSubcollection, is_true())
+ expect_true(returnedFishIsSubcollection)
expect_that(returnedFish$getName(), equals("fish"))
- expect_that(returnedDogIsArvadosFile, is_true())
+ expect_true(returnedDogIsArvadosFile)
expect_that(returnedDog$getName(), equals("dog"))
})
returnedDogIsNull <- is.null(animal$get("dog"))
- expect_that(returnedDogIsNull, is_true())
+ expect_true(returnedDogIsNull)
})
test_that("getFirst returns first child in the subcollection", {
returnedElementIsNull <- is.null(animal$getFirst())
- expect_that(returnedElementIsNull, is_true())
+ expect_true(returnedElementIsNull)
})
test_that(paste("setCollection by default sets collection",
fishCollectionIsNull <- is.null(fish$getCollection())
expect_that(animal$getCollection(), equals("myCollection"))
- expect_that(fishCollectionIsNull, is_true())
+ expect_true(fishCollectionIsNull)
})
test_that(paste("move raises exception if subcollection",
fishIsNullOnOldLocation <- is.null(collection$get("animal/fish"))
fishExistsOnNewLocation <- !is.null(collection$get("fish"))
- expect_that(fishIsNullOnOldLocation, is_true())
- expect_that(fishExistsOnNewLocation, is_true())
+ expect_true(fishIsNullOnOldLocation)
+ expect_true(fishExistsOnNewLocation)
})
test_that(paste("getSizeInBytes returns zero if subcollection",
fishExistsOnOldLocation <- !is.null(collection$get("animal/fish"))
fishExistsOnNewLocation <- !is.null(collection$get("fish"))
- expect_that(fishExistsOnOldLocation, is_true())
- expect_that(fishExistsOnNewLocation, is_true())
+ expect_true(fishExistsOnOldLocation)
+ expect_true(fishExistsOnNewLocation)
})
test_that("duplicate performs deep cloning of Subcollection", {