X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/38ceac30a22ac3c506ca69263ff9e2640e5bd71e..c856e47c2a25dc6979ea07f2c3942687687c833a:/sdk/R/tests/testthat/test-Subcollection.R diff --git a/sdk/R/tests/testthat/test-Subcollection.R b/sdk/R/tests/testthat/test-Subcollection.R index 45d0b02a17..e025586c58 100644 --- a/sdk/R/tests/testthat/test-Subcollection.R +++ b/sdk/R/tests/testthat/test-Subcollection.R @@ -1,8 +1,12 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: Apache-2.0 + source("fakes/FakeRESTService.R") context("Subcollection") -test_that("getRelativePath returns relative path properly", { +test_that("getRelativePath returns path relative to the tree root", { animal <- Subcollection$new("animal") @@ -13,7 +17,7 @@ test_that("getRelativePath returns relative path properly", { expect_that(fish$getRelativePath(), equals("animal/fish")) }) -test_that(paste("getFileListing by default returns path of all files", +test_that(paste("getFileListing by default returns sorted path of all files", "relative to the current subcollection"), { animal <- Subcollection$new("animal") @@ -26,7 +30,9 @@ test_that(paste("getFileListing by default returns path of all files", fish$add(blueFish) result <- animal$getFileListing() - expectedResult <- c("animal/fish/shark", "animal/fish/blueFish") + + #expect sorted array + expectedResult <- c("animal/fish/blueFish", "animal/fish/shark") resultsMatch <- length(expectedResult) == length(result) && all(expectedResult == result) @@ -34,7 +40,7 @@ test_that(paste("getFileListing by default returns path of all files", expect_that(resultsMatch, is_true()) }) -test_that(paste("getFileListing returns names of all direct children", +test_that(paste("getFileListing returns sorted names of all direct children", "if fullPath is set to FALSE"), { animal <- Subcollection$new("animal") @@ -47,7 +53,7 @@ test_that(paste("getFileListing returns names of all direct children", fish$add(shark) result <- animal$getFileListing(fullPath = FALSE) - expectedResult <- c("fish", "dog") + expectedResult <- c("dog", "fish") resultsMatch <- length(expectedResult) == length(result) && all(expectedResult == result) @@ -71,6 +77,15 @@ test_that("add adds content to inside collection tree", { expect_that(animalContainsDog, is_true()) }) +test_that("add raises exception if content name is empty string", { + + animal <- Subcollection$new("animal") + rootFolder <- Subcollection$new("") + + expect_that(animal$add(rootFolder), + throws_error("Content has invalid name.", fixed = TRUE)) +}) + test_that(paste("add raises exception if ArvadosFile/Subcollection", "with same name already exists in the subcollection"), { @@ -103,12 +118,10 @@ test_that(paste("add raises exception if passed argument is", test_that(paste("add post content to a REST service", "if subcollection belongs to a collection"), { - api <- Arvados$new("myToken", "myHostName") - api$setHttpClient(FakeHttpRequest$new()) - api$setHttpParser(FakeHttpParser$new()) - collectionContent <- c("animal", "animal/fish") fakeREST <- FakeRESTService$new(collectionContent) + + api <- Arvados$new("myToken", "myHostName") api$setRESTService(fakeREST) collection <- Collection$new(api, "myUUID") @@ -156,13 +169,10 @@ test_that("remove raises exception if passed argument is not character vector", test_that(paste("remove removes content from REST service", "if subcollection belongs to a collection"), { - api <- Arvados$new("myToken", "myHostName") - api$setHttpClient(FakeHttpRequest$new()) - api$setHttpParser(FakeHttpParser$new()) - collectionContent <- c("animal", "animal/fish", "animal/dog") - fakeREST <- FakeRESTService$new(collectionContent) + + api <- Arvados$new("myToken", "myHostName") api$setRESTService(fakeREST) collection <- Collection$new(api, "myUUID") animal <- collection$get("animal") @@ -263,42 +273,55 @@ test_that(paste("move raises exception if subcollection", throws_error("Subcollection doesn't belong to any collection")) }) -test_that(paste("move raises exception if newLocationInCollection", - "parameter is invalid"), { +test_that("move raises exception if new location contains content with the same name", { + + collectionContent <- c("animal", + "animal/fish", + "animal/dog", + "animal/fish/shark", + "fish") + fakeREST <- FakeRESTService$new(collectionContent) api <- Arvados$new("myToken", "myHostName") - api$setHttpClient(FakeHttpRequest$new()) - api$setHttpParser(FakeHttpParser$new()) + api$setRESTService(fakeREST) + collection <- Collection$new(api, "myUUID") + fish <- collection$get("animal/fish") + + expect_that(fish$move("fish"), + throws_error("Destination already contains content with same name.")) + +}) + +test_that(paste("move raises exception if newLocationInCollection", + "parameter is invalid"), { collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/fish/shark", "ball") - fakeREST <- FakeRESTService$new(collectionContent) + + api <- Arvados$new("myToken", "myHostName") api$setRESTService(fakeREST) collection <- Collection$new(api, "myUUID") - dog <- collection$get("animal/dog") + fish <- collection$get("animal/fish") - expect_that(dog$move("objects/dog"), + expect_that(fish$move("objects/dog"), throws_error("Unable to get destination subcollection")) }) test_that("move moves subcollection inside collection tree", { - api <- Arvados$new("myToken", "myHostName") - api$setHttpClient(FakeHttpRequest$new()) - api$setHttpParser(FakeHttpParser$new()) - collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/fish/shark", "ball") - fakeREST <- FakeRESTService$new(collectionContent) + + api <- Arvados$new("myToken", "myHostName") api$setRESTService(fakeREST) collection <- Collection$new(api, "myUUID") fish <- collection$get("animal/fish") @@ -322,14 +345,11 @@ test_that(paste("getSizeInBytes returns zero if subcollection", test_that(paste("getSizeInBytes delegates size calculation", "to REST service class"), { - api <- Arvados$new("myToken", "myHostName") - api$setHttpClient(FakeHttpRequest$new()) - api$setHttpParser(FakeHttpParser$new()) - collectionContent <- c("animal", "animal/fish") returnSize <- 100 - fakeREST <- FakeRESTService$new(collectionContent, returnSize) + + api <- Arvados$new("myToken", "myHostName") api$setRESTService(fakeREST) collection <- Collection$new(api, "myUUID") animal <- collection$get("animal") @@ -337,4 +357,4 @@ test_that(paste("getSizeInBytes delegates size calculation", resourceSize <- animal$getSizeInBytes() expect_that(resourceSize, equals(100)) -}) +})