1 source("fakes/FakeRESTService.R")
5 test_that("getFileListing always returns file name", {
7 dog <- ArvadosFile$new("dog")
9 expect_that(dog$getFileListing(), equals("dog"))
12 test_that("get always returns NULL", {
14 dog <- ArvadosFile$new("dog")
16 responseIsNull <- is.null(dog$get("something"))
17 expect_that(responseIsNull, is_true())
20 test_that("getFirst always returns NULL", {
22 dog <- ArvadosFile$new("dog")
24 responseIsNull <- is.null(dog$getFirst())
25 expect_that(responseIsNull, is_true())
28 test_that(paste("getSizeInBytes returns zero if arvadosFile",
29 "is not part of a collection"), {
31 dog <- ArvadosFile$new("dog")
33 expect_that(dog$getSizeInBytes(), equals(0))
36 test_that(paste("getSizeInBytes delegates size calculation",
37 "to REST service class"), {
39 collectionContent <- c("animal", "animal/fish")
41 fakeREST <- FakeRESTService$new(collectionContent, returnSize)
43 api <- Arvados$new("myToken", "myHostName")
44 api$setRESTService(fakeREST)
45 collection <- Collection$new(api, "myUUID")
46 fish <- collection$get("animal/fish")
48 resourceSize <- fish$getSizeInBytes()
50 expect_that(resourceSize, equals(100))
53 test_that("getRelativePath returns path relative to the tree root", {
55 animal <- Subcollection$new("animal")
56 fish <- Subcollection$new("fish")
57 shark <- ArvadosFile$new("shark")
62 expect_that(shark$getRelativePath(), equals("animal/fish/shark"))
65 test_that("read raises exception if file doesn't belong to a collection", {
67 dog <- ArvadosFile$new("dog")
69 expect_that(dog$read(),
70 throws_error("ArvadosFile doesn't belong to any collection."))
73 test_that("read raises exception offset or length is negative number", {
76 collectionContent <- c("animal", "animal/fish")
77 fakeREST <- FakeRESTService$new(collectionContent)
79 api <- Arvados$new("myToken", "myHostName")
80 api$setRESTService(fakeREST)
81 collection <- Collection$new(api, "myUUID")
82 fish <- collection$get("animal/fish")
84 expect_that(fish$read(contentType = "text", offset = -1),
85 throws_error("Offset and length must be positive values."))
86 expect_that(fish$read(contentType = "text", length = -1),
87 throws_error("Offset and length must be positive values."))
88 expect_that(fish$read(contentType = "text", offset = -1, length = -1),
89 throws_error("Offset and length must be positive values."))
92 test_that("read delegates reading operation to REST service class", {
94 collectionContent <- c("animal", "animal/fish")
95 readContent <- "my file"
96 fakeREST <- FakeRESTService$new(collectionContent, readContent)
98 api <- Arvados$new("myToken", "myHostName")
99 api$setRESTService(fakeREST)
100 collection <- Collection$new(api, "myUUID")
101 fish <- collection$get("animal/fish")
103 fileContent <- fish$read("text")
105 expect_that(fileContent, equals("my file"))
106 expect_that(fakeREST$readCallCount, equals(1))
109 test_that(paste("connection delegates connection creation ro RESTService class",
110 "which returns curl connection opened in read mode when",
111 "'r' of 'rb' is passed as argument"), {
113 collectionContent <- c("animal", "animal/fish")
114 fakeREST <- FakeRESTService$new(collectionContent)
116 api <- Arvados$new("myToken", "myHostName")
117 api$setRESTService(fakeREST)
118 collection <- Collection$new(api, "myUUID")
119 fish <- collection$get("animal/fish")
121 connection <- fish$connection("r")
123 expect_that(fakeREST$getConnectionCallCount, equals(1))
126 test_that(paste("connection returns textConnection opened",
127 "in write mode when 'w' is passed as argument"), {
129 collectionContent <- c("animal", "animal/fish")
130 fakeREST <- FakeRESTService$new(collectionContent)
132 api <- Arvados$new("myToken", "myHostName")
133 api$setRESTService(fakeREST)
134 collection <- Collection$new(api, "myUUID")
135 fish <- collection$get("animal/fish")
137 connection <- fish$connection("w")
139 writeLines("file", connection)
140 writeLines("content", connection)
142 writeResult <- textConnectionValue(connection)
144 expect_that(writeResult[1], equals("file"))
145 expect_that(writeResult[2], equals("content"))
148 test_that("flush sends data stored in a connection to a REST server", {
151 collectionContent <- c("animal", "animal/fish")
152 fakeREST <- FakeRESTService$new(collectionContent)
154 api <- Arvados$new("myToken", "myHostName")
155 api$setRESTService(fakeREST)
156 collection <- Collection$new(api, "myUUID")
157 fish <- collection$get("animal/fish")
159 connection <- fish$connection("w")
161 writeLines("file content", connection)
165 expect_that(fakeREST$writeBuffer, equals("file content"))
168 test_that("write raises exception if file doesn't belong to a collection", {
170 dog <- ArvadosFile$new("dog")
172 expect_that(dog$write(),
173 throws_error("ArvadosFile doesn't belong to any collection."))
176 test_that("write delegates writing operation to REST service class", {
179 collectionContent <- c("animal", "animal/fish")
180 fakeREST <- FakeRESTService$new(collectionContent)
182 api <- Arvados$new("myToken", "myHostName")
183 api$setRESTService(fakeREST)
184 collection <- Collection$new(api, "myUUID")
185 fish <- collection$get("animal/fish")
187 fileContent <- fish$write("new file content")
189 expect_that(fakeREST$writeBuffer, equals("new file content"))
192 test_that(paste("move raises exception if arvados file",
193 "doesn't belong to any collection"), {
195 animal <- ArvadosFile$new("animal")
197 expect_that(animal$move("new/location"),
198 throws_error("ArvadosFile doesn't belong to any collection"))
201 test_that(paste("move raises exception if newLocationInCollection",
202 "parameter is invalid"), {
205 collectionContent <- c("animal",
210 fakeREST <- FakeRESTService$new(collectionContent)
212 api <- Arvados$new("myToken", "myHostName")
213 api$setRESTService(fakeREST)
215 collection <- Collection$new(api, "myUUID")
216 dog <- collection$get("animal/dog")
218 expect_that(dog$move("objects/dog"),
219 throws_error("Unable to get destination subcollection"))
222 test_that("move raises exception if new location contains content with the same name", {
225 collectionContent <- c("animal",
230 fakeREST <- FakeRESTService$new(collectionContent)
232 api <- Arvados$new("myToken", "myHostName")
233 api$setRESTService(fakeREST)
234 collection <- Collection$new(api, "myUUID")
235 dog <- collection$get("animal/dog")
237 expect_that(dog$move("dog"),
238 throws_error("Destination already contains content with same name."))
242 test_that("move moves arvados file inside collection tree", {
245 collectionContent <- c("animal",
250 fakeREST <- FakeRESTService$new(collectionContent)
252 api <- Arvados$new("myToken", "myHostName")
253 api$setRESTService(fakeREST)
254 collection <- Collection$new(api, "myUUID")
255 dog <- collection$get("animal/dog")
258 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
259 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
261 expect_that(dogIsNullOnOldLocation, is_true())
262 expect_that(dogExistsOnNewLocation, is_true())