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("connect returns textConnection opened",
110 "in read mode when 'r' is passed as argument"), {
112 collectionContent <- c("animal", "animal/fish")
113 readContent <- "file content"
114 fakeREST <- FakeRESTService$new(collectionContent, readContent)
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(readLines(connection), equals("file content"))
126 test_that(paste("connect returns textConnection opened",
127 "in write mode when 'w' is passed as argument"), {
130 collectionContent <- c("animal", "animal/fish")
131 fakeREST <- FakeRESTService$new(collectionContent)
133 api <- Arvados$new("myToken", "myHostName")
134 api$setRESTService(fakeREST)
135 collection <- Collection$new(api, "myUUID")
136 fish <- collection$get("animal/fish")
138 connection <- fish$connection("w")
140 writeLines("file", connection)
141 writeLines("content", connection)
143 writeResult <- textConnectionValue(connection)
145 expect_that(writeResult[1], equals("file"))
146 expect_that(writeResult[2], equals("content"))
149 test_that("flush sends data stored in a connection to a REST server", {
152 collectionContent <- c("animal", "animal/fish")
153 fakeREST <- FakeRESTService$new(collectionContent)
155 api <- Arvados$new("myToken", "myHostName")
156 api$setRESTService(fakeREST)
157 collection <- Collection$new(api, "myUUID")
158 fish <- collection$get("animal/fish")
160 connection <- fish$connection("w")
162 writeLines("file content", connection)
166 expect_that(fakeREST$writeBuffer, equals("file content"))
169 test_that("write raises exception if file doesn't belong to a collection", {
171 dog <- ArvadosFile$new("dog")
173 expect_that(dog$write(),
174 throws_error("ArvadosFile doesn't belong to any collection."))
177 test_that("write delegates writing operation to REST service class", {
180 collectionContent <- c("animal", "animal/fish")
181 fakeREST <- FakeRESTService$new(collectionContent)
183 api <- Arvados$new("myToken", "myHostName")
184 api$setRESTService(fakeREST)
185 collection <- Collection$new(api, "myUUID")
186 fish <- collection$get("animal/fish")
188 fileContent <- fish$write("new file content")
190 expect_that(fakeREST$writeBuffer, equals("new file content"))
193 test_that(paste("move raises exception if arvados file",
194 "doesn't belong to any collection"), {
196 animal <- ArvadosFile$new("animal")
198 expect_that(animal$move("new/location"),
199 throws_error("ArvadosFile doesn't belong to any collection"))
202 test_that(paste("move raises exception if newLocationInCollection",
203 "parameter is invalid"), {
206 collectionContent <- c("animal",
211 fakeREST <- FakeRESTService$new(collectionContent)
213 api <- Arvados$new("myToken", "myHostName")
214 api$setRESTService(fakeREST)
216 collection <- Collection$new(api, "myUUID")
217 dog <- collection$get("animal/dog")
219 expect_that(dog$move("objects/dog"),
220 throws_error("Unable to get destination subcollection"))
223 test_that("move raises exception if new location contains content with the same name", {
226 collectionContent <- c("animal",
231 fakeREST <- FakeRESTService$new(collectionContent)
233 api <- Arvados$new("myToken", "myHostName")
234 api$setRESTService(fakeREST)
235 collection <- Collection$new(api, "myUUID")
236 dog <- collection$get("animal/dog")
238 expect_that(dog$move("dog"),
239 throws_error("Destination already contains content with same name."))
243 test_that("move moves arvados file inside collection tree", {
246 collectionContent <- c("animal",
251 fakeREST <- FakeRESTService$new(collectionContent)
253 api <- Arvados$new("myToken", "myHostName")
254 api$setRESTService(fakeREST)
255 collection <- Collection$new(api, "myUUID")
256 dog <- collection$get("animal/dog")
259 dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
260 dogExistsOnNewLocation <- !is.null(collection$get("dog"))
262 expect_that(dogIsNullOnOldLocation, is_true())
263 expect_that(dogExistsOnNewLocation, is_true())