1 source("fakes/FakeRESTService.R")
5 test_that("constructor raises error if file name is empty string", {
7 expect_that(ArvadosFile$new(""), throws_error("Invalid name."))
10 test_that("getFileListing always returns file name", {
12 dog <- ArvadosFile$new("dog")
14 expect_that(dog$getFileListing(), equals("dog"))
17 test_that("get always returns NULL", {
19 dog <- ArvadosFile$new("dog")
21 responseIsNull <- is.null(dog$get("something"))
22 expect_that(responseIsNull, is_true())
25 test_that("getFirst always returns NULL", {
27 dog <- ArvadosFile$new("dog")
29 responseIsNull <- is.null(dog$getFirst())
30 expect_that(responseIsNull, is_true())
33 test_that(paste("getSizeInBytes returns zero if arvadosFile",
34 "is not part of a collection"), {
36 dog <- ArvadosFile$new("dog")
38 expect_that(dog$getSizeInBytes(), equals(0))
41 test_that(paste("getSizeInBytes delegates size calculation",
42 "to REST service class"), {
44 collectionContent <- c("animal", "animal/fish")
46 fakeREST <- FakeRESTService$new(collectionContent, returnSize)
48 api <- Arvados$new("myToken", "myHostName")
49 api$setRESTService(fakeREST)
50 collection <- Collection$new(api, "myUUID")
51 fish <- collection$get("animal/fish")
53 resourceSize <- fish$getSizeInBytes()
55 expect_that(resourceSize, equals(100))
58 test_that("getRelativePath returns path relative to the tree root", {
60 animal <- Subcollection$new("animal")
61 fish <- Subcollection$new("fish")
62 shark <- ArvadosFile$new("shark")
67 expect_that(shark$getRelativePath(), equals("animal/fish/shark"))
70 test_that("read raises exception if file doesn't belong to a collection", {
72 dog <- ArvadosFile$new("dog")
74 expect_that(dog$read(),
75 throws_error("ArvadosFile doesn't belong to any collection."))
78 test_that("read raises exception offset or length is negative number", {
81 collectionContent <- c("animal", "animal/fish")
82 fakeREST <- FakeRESTService$new(collectionContent)
84 api <- Arvados$new("myToken", "myHostName")
85 api$setRESTService(fakeREST)
86 collection <- Collection$new(api, "myUUID")
87 fish <- collection$get("animal/fish")
89 expect_that(fish$read(contentType = "text", offset = -1),
90 throws_error("Offset and length must be positive values."))
91 expect_that(fish$read(contentType = "text", length = -1),
92 throws_error("Offset and length must be positive values."))
93 expect_that(fish$read(contentType = "text", offset = -1, length = -1),
94 throws_error("Offset and length must be positive values."))
97 test_that("read delegates reading operation to REST service class", {
99 collectionContent <- c("animal", "animal/fish")
100 readContent <- "my file"
101 fakeREST <- FakeRESTService$new(collectionContent, readContent)
103 api <- Arvados$new("myToken", "myHostName")
104 api$setRESTService(fakeREST)
105 collection <- Collection$new(api, "myUUID")
106 fish <- collection$get("animal/fish")
108 fileContent <- fish$read("text")
110 expect_that(fileContent, equals("my file"))
111 expect_that(fakeREST$readCallCount, equals(1))
114 test_that(paste("connection delegates connection creation ro RESTService class",
115 "which returns curl connection opened in read mode when",
116 "'r' of 'rb' is passed as argument"), {
118 collectionContent <- c("animal", "animal/fish")
119 fakeREST <- FakeRESTService$new(collectionContent)
121 api <- Arvados$new("myToken", "myHostName")
122 api$setRESTService(fakeREST)
123 collection <- Collection$new(api, "myUUID")
124 fish <- collection$get("animal/fish")
126 connection <- fish$connection("r")
128 expect_that(fakeREST$getConnectionCallCount, equals(1))
131 test_that(paste("connection returns textConnection opened",
132 "in write mode when 'w' is passed as argument"), {
134 collectionContent <- c("animal", "animal/fish")
135 fakeREST <- FakeRESTService$new(collectionContent)
137 api <- Arvados$new("myToken", "myHostName")
138 api$setRESTService(fakeREST)
139 collection <- Collection$new(api, "myUUID")
140 fish <- collection$get("animal/fish")
142 connection <- fish$connection("w")
144 writeLines("file", connection)
145 writeLines("content", connection)
147 writeResult <- textConnectionValue(connection)
149 expect_that(writeResult[1], equals("file"))
150 expect_that(writeResult[2], equals("content"))
153 test_that("flush sends data stored in a connection to a REST server", {
156 collectionContent <- c("animal", "animal/fish")
157 fakeREST <- FakeRESTService$new(collectionContent)
159 api <- Arvados$new("myToken", "myHostName")
160 api$setRESTService(fakeREST)
161 collection <- Collection$new(api, "myUUID")
162 fish <- collection$get("animal/fish")
164 connection <- fish$connection("w")
166 writeLines("file content", connection)
170 expect_that(fakeREST$writeBuffer, equals("file content"))
173 test_that("write raises exception if file doesn't belong to a collection", {
175 dog <- ArvadosFile$new("dog")
177 expect_that(dog$write(),
178 throws_error("ArvadosFile doesn't belong to any collection."))
181 test_that("write delegates writing operation to REST service class", {
184 collectionContent <- c("animal", "animal/fish")
185 fakeREST <- FakeRESTService$new(collectionContent)
187 api <- Arvados$new("myToken", "myHostName")
188 api$setRESTService(fakeREST)
189 collection <- Collection$new(api, "myUUID")
190 fish <- collection$get("animal/fish")
192 fileContent <- fish$write("new file content")
194 expect_that(fakeREST$writeBuffer, equals("new file content"))
197 test_that(paste("move raises exception if arvados file",
198 "doesn't belong to any collection"), {
200 animal <- ArvadosFile$new("animal")
202 expect_that(animal$move("new/location"),
203 throws_error("ArvadosFile doesn't belong to any collection"))
206 test_that(paste("move raises exception if newLocationInCollection",
207 "parameter is invalid"), {
210 collectionContent <- c("animal",
216 fakeREST <- FakeRESTService$new(collectionContent)
218 api <- Arvados$new("myToken", "myHostName")
219 api$setRESTService(fakeREST)
221 collection <- Collection$new(api, "myUUID")
222 dog <- collection$get("animal/dog")
224 expect_that(dog$move("objects/dog"),
225 throws_error("Unable to get destination subcollection"))
228 test_that("move raises exception if new location contains content with the same name", {
231 collectionContent <- c("animal",
237 fakeREST <- FakeRESTService$new(collectionContent)
239 api <- Arvados$new("myToken", "myHostName")
240 api$setRESTService(fakeREST)
241 collection <- Collection$new(api, "myUUID")
242 dog <- collection$get("animal/dog")
244 expect_that(dog$move("dog"),
245 throws_error("Destination already contains content with same name."))
249 test_that("move moves arvados file inside collection tree", {
252 collectionContent <- c("animal",
258 fakeREST <- FakeRESTService$new(collectionContent)
260 api <- Arvados$new("myToken", "myHostName")
261 api$setRESTService(fakeREST)
262 collection <- Collection$new(api, "myUUID")
263 dog <- collection$get("animal/dog")
266 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
267 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
269 expect_that(dogIsNullOnOldLocation, is_true())
270 expect_that(dogExistsOnNewLocation, is_true())