Merge branch 'master' of git.curoverse.com:arvados into 13076-r-autogen-api
[arvados.git] / sdk / R / tests / testthat / test-ArvadosFile.R
index 43c841bf8ce7906e2261a29e8e497173a57fcf5c..67ed0f6240938562ff5cb7894201205926c3c494 100644 (file)
@@ -2,6 +2,11 @@ source("fakes/FakeRESTService.R")
 
 context("ArvadosFile")
 
+test_that("constructor raises error if  file name is empty string", {
+
+    expect_that(ArvadosFile$new(""), throws_error("Invalid name."))
+}) 
+
 test_that("getFileListing always returns file name", {
 
     dog <- ArvadosFile$new("dog")
@@ -40,9 +45,8 @@ test_that(paste("getSizeInBytes delegates size calculation",
     returnSize <- 100
     fakeREST <- FakeRESTService$new(collectionContent, returnSize)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
 
     resourceSize <- fish$getSizeInBytes()
@@ -76,9 +80,8 @@ test_that("read raises exception offset or length is negative number", {
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
 
     expect_that(fish$read(contentType = "text", offset = -1),
@@ -95,9 +98,8 @@ test_that("read delegates reading operation to REST service class", {
     readContent <- "my file"
     fakeREST <- FakeRESTService$new(collectionContent, readContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
     
     fileContent <- fish$read("text")
@@ -113,9 +115,8 @@ test_that(paste("connection delegates connection creation ro RESTService class",
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
 
     connection <- fish$connection("r")
@@ -129,9 +130,8 @@ test_that(paste("connection returns textConnection opened",
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
 
     connection <- fish$connection("w")
@@ -151,9 +151,8 @@ test_that("flush sends data stored in a connection to a REST server", {
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
 
     connection <- fish$connection("w")
@@ -179,9 +178,8 @@ test_that("write delegates writing operation to REST service class", {
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     fish <- collection$get("animal/fish")
     
     fileContent <- fish$write("new file content")
@@ -207,12 +205,11 @@ test_that(paste("move raises exception if newLocationInCollection",
                            "animal/dog",
                            "animal/fish/shark",
                            "ball")
-    fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
+    fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     dog <- collection$get("animal/dog")
 
     expect_that(dog$move("objects/dog"),
@@ -227,11 +224,11 @@ test_that("move raises exception if new location contains content with the same
                            "animal/dog",
                            "animal/fish/shark",
                            "dog")
+
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     dog <- collection$get("animal/dog")
 
     expect_that(dog$move("dog"),
@@ -247,11 +244,11 @@ test_that("move moves arvados file inside collection tree", {
                            "animal/dog",
                            "animal/fish/shark",
                            "ball")
+
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
+    collection <- Collection$new("fakeUUID")
+    collection$setRESTService(fakeREST)
     dog <- collection$get("animal/dog")
 
     dog$move("dog")