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_that(dogExistsInCollection, is_true())
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("create raises exception if relative path is not valid", {
109 collectionContent <- c("animal",
113 fakeREST <- FakeRESTService$new(collectionContent)
115 api <- Arvados$new("myToken", "myHostName")
116 api$setRESTService(fakeREST)
117 collection <- Collection$new(api, "myUUID")
119 newPen <- ArvadosFile$new("pen")
121 expect_that(collection$create(newPen, "objects"),
122 throws_error("Subcollection objects doesn't exist.",
126 test_that(paste("create adds files specified by fileNames",
127 "to local tree structure and remote REST service"), {
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 files <- c("dog", "cat")
137 collection$create(files, "animal")
139 dog <- collection$get("animal/dog")
140 cat <- collection$get("animal/cat")
141 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
142 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
144 expect_that(dogExistsInCollection, is_true())
145 expect_that(catExistsInCollection, is_true())
146 expect_that(fakeREST$createCallCount, equals(2))
149 test_that("remove raises exception if passed argumet is not character vector", {
151 collectionContent <- c("animal", "animal/fish", "ball")
152 fakeREST <- FakeRESTService$new(collectionContent)
154 api <- Arvados$new("myToken", "myHostName")
155 api$setRESTService(fakeREST)
156 collection <- Collection$new(api, "myUUID")
158 expect_that(collection$remove(10),
159 throws_error("Expected character vector, got (numeric).",
163 test_that("remove raises exception if user tries to remove root folder", {
165 collectionContent <- c("animal", "animal/fish")
166 fakeREST <- FakeRESTService$new(collectionContent)
168 api <- Arvados$new("myToken", "myHostName")
169 api$setRESTService(fakeREST)
170 collection <- Collection$new(api, "myUUID")
172 expect_that(collection$remove(""),
173 throws_error("You can't delete root folder.", fixed = TRUE))
176 test_that(paste("remove removes files specified by paths",
177 "from local tree structure and from remote REST service"), {
179 collectionContent <- c("animal", "animal/fish", "animal/dog", "animal/cat", "ball")
180 fakeREST <- FakeRESTService$new(collectionContent)
182 api <- Arvados$new("myToken", "myHostName")
183 api$setRESTService(fakeREST)
184 collection <- Collection$new(api, "myUUID")
186 collection$remove(c("animal/dog", "animal/cat"))
188 dog <- collection$get("animal/dog")
189 cat <- collection$get("animal/dog")
190 dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
191 catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
193 expect_that(dogExistsInCollection, is_false())
194 expect_that(catExistsInCollection, is_false())
195 expect_that(fakeREST$deleteCallCount, equals(2))
198 test_that(paste("move moves content to a new location inside file tree",
199 "and on REST service"), {
201 collectionContent <- c("animal", "animal/dog", "ball")
202 fakeREST <- FakeRESTService$new(collectionContent)
204 api <- Arvados$new("myToken", "myHostName")
205 api$setRESTService(fakeREST)
206 collection <- Collection$new(api, "myUUID")
208 collection$move("animal/dog", "dog")
210 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
211 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
213 expect_that(dogIsNullOnOldLocation, is_true())
214 expect_that(dogExistsOnNewLocation, is_true())
215 expect_that(fakeREST$moveCallCount, equals(1))
218 test_that("move raises exception if new location is not valid", {
220 collectionContent <- c("animal", "animal/fish", "ball")
221 fakeREST <- FakeRESTService$new(collectionContent)
223 api <- Arvados$new("myToken", "myHostName")
224 api$setRESTService(fakeREST)
225 collection <- Collection$new(api, "myUUID")
227 expect_that(collection$move("fish", "object"),
228 throws_error("Content you want to move doesn't exist in the collection.",
232 test_that("getFileListing returns sorted collection content received from REST service", {
234 collectionContent <- c("animal", "animal/fish", "ball")
235 fakeREST <- FakeRESTService$new(collectionContent)
237 api <- Arvados$new("myToken", "myHostName")
238 api$setRESTService(fakeREST)
239 collection <- Collection$new(api, "myUUID")
241 contentMatchExpected <- all(collection$getFileListing() ==
242 c("animal", "animal/fish", "ball"))
244 expect_that(contentMatchExpected, is_true())
245 #2 calls because Collection$new calls getFileListing once
246 expect_that(fakeREST$getCollectionContentCallCount, equals(2))
250 test_that("get returns arvados file or subcollection from internal tree structure", {
252 collectionContent <- c("animal", "animal/fish", "ball")
253 fakeREST <- FakeRESTService$new(collectionContent)
255 api <- Arvados$new("myToken", "myHostName")
256 api$setRESTService(fakeREST)
257 collection <- Collection$new(api, "myUUID")
259 fish <- collection$get("animal/fish")
260 fishIsNotNull <- !is.null(fish)
262 expect_that(fishIsNotNull, is_true())
263 expect_that(fish$getName(), equals("fish"))