remove trailing white space from all files
[arvados.git] / sdk / R / tests / testthat / test-ArvadosFile.R
index 67ed0f6240938562ff5cb7894201205926c3c494..1f559e999c52be207317b1f9f6f17332ab287ac0 100644 (file)
@@ -1,3 +1,7 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
 source("fakes/FakeRESTService.R")
 
 context("ArvadosFile")
@@ -5,30 +9,30 @@ 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")
 
     expect_that(dog$getFileListing(), equals("dog"))
-}) 
+})
 
 test_that("get always returns NULL", {
 
     dog <- ArvadosFile$new("dog")
-    
+
     responseIsNull <- is.null(dog$get("something"))
     expect_that(responseIsNull, is_true())
-}) 
+})
 
 test_that("getFirst always returns NULL", {
 
     dog <- ArvadosFile$new("dog")
-    
+
     responseIsNull <- is.null(dog$getFirst())
     expect_that(responseIsNull, is_true())
-}) 
+})
 
 test_that(paste("getSizeInBytes returns zero if arvadosFile",
                 "is not part of a collection"), {
@@ -36,7 +40,7 @@ test_that(paste("getSizeInBytes returns zero if arvadosFile",
     dog <- ArvadosFile$new("dog")
 
     expect_that(dog$getSizeInBytes(), equals(0))
-}) 
+})
 
 test_that(paste("getSizeInBytes delegates size calculation",
                 "to REST service class"), {
@@ -45,14 +49,15 @@ test_that(paste("getSizeInBytes delegates size calculation",
     returnSize <- 100
     fakeREST <- FakeRESTService$new(collectionContent, returnSize)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
 
     resourceSize <- fish$getSizeInBytes()
 
     expect_that(resourceSize, equals(100))
-}) 
+})
 
 test_that("getRelativePath returns path relative to the tree root", {
 
@@ -64,7 +69,7 @@ test_that("getRelativePath returns path relative to the tree root", {
     fish$add(shark)
 
     expect_that(shark$getRelativePath(), equals("animal/fish/shark"))
-}) 
+})
 
 test_that("read raises exception if file doesn't belong to a collection", {
 
@@ -72,7 +77,7 @@ test_that("read raises exception if file doesn't belong to a collection", {
 
     expect_that(dog$read(),
                 throws_error("ArvadosFile doesn't belong to any collection."))
-}) 
+})
 
 test_that("read raises exception offset or length is negative number", {
 
@@ -80,8 +85,9 @@ test_that("read raises exception offset or length is negative number", {
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
 
     expect_that(fish$read(contentType = "text", offset = -1),
@@ -90,7 +96,7 @@ test_that("read raises exception offset or length is negative number", {
                 throws_error("Offset and length must be positive values."))
     expect_that(fish$read(contentType = "text", offset = -1, length = -1),
                 throws_error("Offset and length must be positive values."))
-}) 
+})
 
 test_that("read delegates reading operation to REST service class", {
 
@@ -98,31 +104,33 @@ test_that("read delegates reading operation to REST service class", {
     readContent <- "my file"
     fakeREST <- FakeRESTService$new(collectionContent, readContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
-    
+
     fileContent <- fish$read("text")
 
     expect_that(fileContent, equals("my file"))
     expect_that(fakeREST$readCallCount, equals(1))
-}) 
+})
 
 test_that(paste("connection delegates connection creation ro RESTService class",
-                "which returns curl connection opened in read mode when", 
+                "which returns curl connection opened in read mode when",
                 "'r' of 'rb' is passed as argument"), {
 
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
 
     connection <- fish$connection("r")
 
     expect_that(fakeREST$getConnectionCallCount, equals(1))
-}) 
+})
 
 test_that(paste("connection returns textConnection opened",
                 "in write mode when 'w' is passed as argument"), {
@@ -130,8 +138,9 @@ test_that(paste("connection returns textConnection opened",
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
 
     connection <- fish$connection("w")
@@ -143,7 +152,7 @@ test_that(paste("connection returns textConnection opened",
 
     expect_that(writeResult[1], equals("file"))
     expect_that(writeResult[2], equals("content"))
-}) 
+})
 
 test_that("flush sends data stored in a connection to a REST server", {
 
@@ -151,8 +160,9 @@ test_that("flush sends data stored in a connection to a REST server", {
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
 
     connection <- fish$connection("w")
@@ -162,7 +172,7 @@ test_that("flush sends data stored in a connection to a REST server", {
     fish$flush()
 
     expect_that(fakeREST$writeBuffer, equals("file content"))
-}) 
+})
 
 test_that("write raises exception if file doesn't belong to a collection", {
 
@@ -170,7 +180,7 @@ test_that("write raises exception if file doesn't belong to a collection", {
 
     expect_that(dog$write(),
                 throws_error("ArvadosFile doesn't belong to any collection."))
-}) 
+})
 
 test_that("write delegates writing operation to REST service class", {
 
@@ -178,14 +188,15 @@ test_that("write delegates writing operation to REST service class", {
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     fish <- collection$get("animal/fish")
-    
+
     fileContent <- fish$write("new file content")
 
     expect_that(fakeREST$writeBuffer, equals("new file content"))
-}) 
+})
 
 test_that(paste("move raises exception if arvados file",
                 "doesn't belong to any collection"), {
@@ -194,7 +205,7 @@ test_that(paste("move raises exception if arvados file",
 
     expect_that(animal$move("new/location"),
                 throws_error("ArvadosFile doesn't belong to any collection"))
-}) 
+})
 
 test_that(paste("move raises exception if newLocationInCollection",
                 "parameter is invalid"), {
@@ -208,13 +219,15 @@ test_that(paste("move raises exception if newLocationInCollection",
 
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+
+    collection <- Collection$new(api, "myUUID")
     dog <- collection$get("animal/dog")
 
     expect_that(dog$move("objects/dog"),
                 throws_error("Unable to get destination subcollection"))
-}) 
+})
 
 test_that("move raises exception if new location contains content with the same name", {
 
@@ -227,14 +240,15 @@ test_that("move raises exception if new location contains content with the same
 
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     dog <- collection$get("animal/dog")
 
     expect_that(dog$move("dog"),
                 throws_error("Destination already contains content with same name."))
 
-}) 
+})
 
 test_that("move moves arvados file inside collection tree", {
 
@@ -247,8 +261,9 @@ test_that("move moves arvados file inside collection tree", {
 
     fakeREST <- FakeRESTService$new(collectionContent)
 
-    collection <- Collection$new("fakeUUID")
-    collection$setRESTService(fakeREST)
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
     dog <- collection$get("animal/dog")
 
     dog$move("dog")
@@ -257,4 +272,4 @@ test_that("move moves arvados file inside collection tree", {
 
     expect_that(dogIsNullOnOldLocation, is_true())
     expect_that(dogExistsOnNewLocation, is_true())
-}) 
+})