Merge branch 'master' into 7478-anm-spot-instances
[arvados.git] / sdk / R / tests / testthat / test-ArvadosFile.R
index 4897056a1a8c11019df0212f8b5673c707a37670..fb14888aab91b982d88dbdddca0be9589f757fb8 100644 (file)
@@ -1,7 +1,16 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: Apache-2.0
+
 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")
@@ -106,12 +115,12 @@ test_that("read delegates reading operation to REST service class", {
     expect_that(fakeREST$readCallCount, equals(1))
 }) 
 
-test_that(paste("connect returns textConnection opened",
-                "in read mode when 'r' is passed as argument"), {
+test_that(paste("connection delegates connection creation ro RESTService class",
+                "which returns curl connection opened in read mode when", 
+                "'r' of 'rb' is passed as argument"), {
 
     collectionContent <- c("animal", "animal/fish")
-    readContent <- "file content"
-    fakeREST <- FakeRESTService$new(collectionContent, readContent)
+    fakeREST <- FakeRESTService$new(collectionContent)
 
     api <- Arvados$new("myToken", "myHostName")
     api$setRESTService(fakeREST)
@@ -120,13 +129,12 @@ test_that(paste("connect returns textConnection opened",
 
     connection <- fish$connection("r")
 
-    expect_that(readLines(connection), equals("file content"))
+    expect_that(fakeREST$getConnectionCallCount, equals(1))
 }) 
 
-test_that(paste("connect returns textConnection opened",
+test_that(paste("connection returns textConnection opened",
                 "in write mode when 'w' is passed as argument"), {
 
-
     collectionContent <- c("animal", "animal/fish")
     fakeREST <- FakeRESTService$new(collectionContent)
 
@@ -208,6 +216,7 @@ test_that(paste("move raises exception if newLocationInCollection",
                            "animal/dog",
                            "animal/fish/shark",
                            "ball")
+
     fakeREST <- FakeRESTService$new(collectionContent)
 
     api <- Arvados$new("myToken", "myHostName")
@@ -228,6 +237,7 @@ 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")
@@ -248,6 +258,7 @@ test_that("move moves arvados file inside collection tree", {
                            "animal/dog",
                            "animal/fish/shark",
                            "ball")
+
     fakeREST <- FakeRESTService$new(collectionContent)
 
     api <- Arvados$new("myToken", "myHostName")
@@ -261,4 +272,4 @@ test_that("move moves arvados file inside collection tree", {
 
     expect_that(dogIsNullOnOldLocation, is_true())
     expect_that(dogExistsOnNewLocation, is_true())
-}) 
+})