1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 source("fakes/FakeRESTService.R")
9 test_that(paste("constructor creates file tree from text content",
10 "retreived form REST service"), {
12 collectionContent <- c("animal", "animal/fish", "ball")
13 fakeREST <- FakeRESTService$new(collectionContent)
15 api <- Arvados$new("myToken", "myHostName")
16 api$setRESTService(fakeREST)
17 collection <- Collection$new(api, "myUUID")
19 root <- collection$get("")
21 expect_that(fakeREST$getCollectionContentCallCount, equals(1))
22 expect_that(root$getName(), equals(""))
25 test_that(paste("add raises exception if passed argumet is not",
26 "ArvadosFile or Subcollection"), {
28 collectionContent <- c("animal", "animal/fish", "ball")
29 fakeREST <- FakeRESTService$new(collectionContent)
31 api <- Arvados$new("myToken", "myHostName")
32 api$setRESTService(fakeREST)
33 collection <- Collection$new(api, "myUUID")
37 expect_that(collection$add(newNumber),
38 throws_error(paste("Expected AravodsFile or Subcollection",
39 "object, got (numeric)."), fixed = TRUE))
42 test_that("add raises exception if relative path is not valid", {
44 collectionContent <- c("animal", "animal/fish", "ball")
45 fakeREST <- FakeRESTService$new(collectionContent)
47 api <- Arvados$new("myToken", "myHostName")
48 api$setRESTService(fakeREST)
49 collection <- Collection$new(api, "myUUID")
51 newPen <- ArvadosFile$new("pen")
53 expect_that(collection$add(newPen, "objects"),
54 throws_error("Subcollection objects doesn't exist.",
58 test_that("add raises exception if content name is empty string", {
60 collectionContent <- c("animal", "animal/fish")
61 fakeREST <- FakeRESTService$new(collectionContent)
63 api <- Arvados$new("myToken", "myHostName")
64 api$setRESTService(fakeREST)
65 collection <- Collection$new(api, "myUUID")
67 rootFolder <- Subcollection$new("")
69 expect_that(collection$add(rootFolder),
70 throws_error("Content has invalid name.", fixed = TRUE))
73 test_that(paste("add adds ArvadosFile or Subcollection",
74 "to local tree structure and remote REST service"), {
76 collectionContent <- c("animal", "animal/fish", "ball")
77 fakeREST <- FakeRESTService$new(collectionContent)
79 api <- Arvados$new("myToken", "myHostName")
80 api$setRESTService(fakeREST)
81 collection <- Collection$new(api, "myUUID")
83 newDog <- ArvadosFile$new("dog")
84 collection$add(newDog, "animal")
86 dog <- collection$get("animal/dog")
87 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
89 expect_true(dogExistsInCollection)
90 expect_that(fakeREST$createCallCount, equals(1))
93 test_that("create raises exception if passed argumet is not character vector", {
95 collectionContent <- c("animal", "animal/fish", "ball")
96 fakeREST <- FakeRESTService$new(collectionContent)
98 api <- Arvados$new("myToken", "myHostName")
99 api$setRESTService(fakeREST)
100 collection <- Collection$new(api, "myUUID")
102 expect_that(collection$create(10),
103 throws_error("Expected character vector, got (numeric).",
107 test_that(paste("create adds files specified by fileNames",
108 "to local tree structure and remote REST service"), {
110 fakeREST <- FakeRESTService$new()
111 api <- Arvados$new("myToken", "myHostName")
112 api$setRESTService(fakeREST)
113 collection <- Collection$new(api, "myUUID")
115 collection$create(c("animal/dog", "animal/cat"))
117 dog <- collection$get("animal/dog")
118 cat <- collection$get("animal/cat")
119 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
120 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
122 expect_true(dogExistsInCollection)
123 expect_true(catExistsInCollection)
124 expect_that(fakeREST$createCallCount, equals(2))
127 test_that("remove raises exception if passed argumet is not character vector", {
129 collectionContent <- c("animal", "animal/fish", "ball")
130 fakeREST <- FakeRESTService$new(collectionContent)
132 api <- Arvados$new("myToken", "myHostName")
133 api$setRESTService(fakeREST)
134 collection <- Collection$new(api, "myUUID")
136 expect_that(collection$remove(10),
137 throws_error("Expected character vector, got (numeric).",
141 test_that("remove raises exception if user tries to remove root folder", {
143 collectionContent <- c("animal", "animal/fish")
144 fakeREST <- FakeRESTService$new(collectionContent)
146 api <- Arvados$new("myToken", "myHostName")
147 api$setRESTService(fakeREST)
148 collection <- Collection$new(api, "myUUID")
150 expect_that(collection$remove(""),
151 throws_error("You can't delete root folder.", fixed = TRUE))
154 test_that(paste("remove removes files specified by paths",
155 "from local tree structure and from remote REST service"), {
157 collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/cat", "ball")
158 fakeREST <- FakeRESTService$new(collectionContent)
160 api <- Arvados$new("myToken", "myHostName")
161 api$setRESTService(fakeREST)
162 collection <- Collection$new(api, "myUUID")
164 collection$remove(c("animal/dog", "animal/cat"))
166 dog <- collection$get("animal/dog")
167 cat <- collection$get("animal/dog")
168 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
169 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
171 expect_false(dogExistsInCollection)
172 expect_false(catExistsInCollection)
173 expect_that(fakeREST$deleteCallCount, equals(2))
176 test_that(paste("move moves content to a new location inside file tree",
177 "and on REST service"), {
179 collectionContent <- c("animal", "animal/dog", "ball")
180 fakeREST <- FakeRESTService$new(collectionContent)
182 api <- Arvados$new("myToken", "myHostName")
183 api$setRESTService(fakeREST)
184 collection <- Collection$new(api, "myUUID")
186 collection$move("animal/dog", "dog")
188 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
189 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
191 expect_true(dogIsNullOnOldLocation)
192 expect_true(dogExistsOnNewLocation)
193 expect_that(fakeREST$moveCallCount, equals(1))
196 test_that("move raises exception if new location is not valid", {
198 collectionContent <- c("animal", "animal/fish", "ball")
199 fakeREST <- FakeRESTService$new(collectionContent)
201 api <- Arvados$new("myToken", "myHostName")
202 api$setRESTService(fakeREST)
203 collection <- Collection$new(api, "myUUID")
205 expect_that(collection$move("fish", "object"),
206 throws_error("Content you want to move doesn't exist in the collection.",
210 test_that("getFileListing returns sorted collection content received from REST service", {
212 collectionContent <- c("animal", "animal/fish", "ball")
213 fakeREST <- FakeRESTService$new(collectionContent)
215 api <- Arvados$new("myToken", "myHostName")
216 api$setRESTService(fakeREST)
217 collection <- Collection$new(api, "myUUID")
219 contentMatchExpected <- all(collection$getFileListing() ==
220 c("animal", "animal/fish", "ball"))
222 expect_true(contentMatchExpected)
223 #2 calls because Collection$new calls getFileListing once
224 expect_that(fakeREST$getCollectionContentCallCount, equals(2))
228 test_that("get returns arvados file or subcollection from internal tree structure", {
230 collectionContent <- c("animal", "animal/fish", "ball")
231 fakeREST <- FakeRESTService$new(collectionContent)
233 api <- Arvados$new("myToken", "myHostName")
234 api$setRESTService(fakeREST)
235 collection <- Collection$new(api, "myUUID")
237 fish <- collection$get("animal/fish")
238 fishIsNotNull <- !is.null(fish)
240 expect_true(fishIsNotNull)
241 expect_that(fish$getName(), equals("fish"))
243 ball <- collection$get("ball")
244 ballIsNotNull <- !is.null(ball)
246 expect_true(ballIsNotNull)
247 expect_that(ball$getName(), equals("ball"))
250 test_that(paste("copy copies content to a new location inside file tree",
251 "and on REST service"), {
253 collectionContent <- c("animal", "animal/dog", "ball")
254 fakeREST <- FakeRESTService$new(collectionContent)
256 api <- Arvados$new("myToken", "myHostName")
257 api$setRESTService(fakeREST)
258 collection <- Collection$new(api, "myUUID")
260 collection$copy("animal/dog", "dog")
262 dogExistsOnOldLocation <- !is.null(collection$get("animal/dog"))
263 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
265 expect_true(dogExistsOnOldLocation)
266 expect_true(dogExistsOnNewLocation)
267 expect_that(fakeREST$copyCallCount, equals(1))
270 test_that("copy raises exception if new location is not valid", {
272 collectionContent <- c("animal", "animal/fish", "ball")
273 fakeREST <- FakeRESTService$new(collectionContent)
275 api <- Arvados$new("myToken", "myHostName")
276 api$setRESTService(fakeREST)
277 collection <- Collection$new(api, "myUUID")
279 expect_that(collection$copy("fish", "object"),
280 throws_error("Content you want to copy doesn't exist in the collection.",
284 test_that("refresh invalidates current tree structure", {
286 collectionContent <- c("animal", "animal/fish", "ball")
287 fakeREST <- FakeRESTService$new(collectionContent)
289 api <- Arvados$new("myToken", "myHostName")
290 api$setRESTService(fakeREST)
291 collection <- Collection$new(api, "aaaaa-j7d0g-ccccccccccccccc")
294 fish <- collection$get("animal/fish")
295 expect_that(fish$getName(), equals("fish"))
296 expect_that(fish$getCollection()$uuid, equals("aaaaa-j7d0g-ccccccccccccccc"))
301 expect_that(fish$getName(), equals("fish"))
302 expect_true(is.null(fish$getCollection()))