Merge branch '21535-multi-wf-delete'
[arvados.git] / sdk / R / tests / testthat / test-Collection.R
index c3c70910e4c63acea6d86f5df71cc9bab9f3e72f..3023a1b23fafcf01c28fda05e775cbe471927e04 100644 (file)
@@ -86,7 +86,7 @@ test_that(paste("add adds ArvadosFile or Subcollection",
     dog <- collection$get("animal/dog")
     dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
 
-    expect_that(dogExistsInCollection, is_true())
+    expect_true(dogExistsInCollection)
     expect_that(fakeREST$createCallCount, equals(1))
 })
 
@@ -100,49 +100,27 @@ test_that("create raises exception if passed argumet is not character vector", {
     collection <- Collection$new(api, "myUUID")
 
     expect_that(collection$create(10),
-                throws_error("Expected character vector, got (numeric).", 
+                throws_error("Expected character vector, got (numeric).",
                              fixed = TRUE))
 })
 
-test_that("create raises exception if relative path is not valid", {
-
-    collectionContent <- c("animal",
-                           "animal/fish",
-                           "ball")
-
-    fakeREST <- FakeRESTService$new(collectionContent)
-
-    api <- Arvados$new("myToken", "myHostName")
-    api$setRESTService(fakeREST)
-    collection <- Collection$new(api, "myUUID")
-
-    newPen <- ArvadosFile$new("pen")
-
-    expect_that(collection$create(newPen, "objects"),
-                throws_error("Subcollection objects doesn't exist.",
-                              fixed = TRUE))
-})
-
 test_that(paste("create adds files specified by fileNames",
                 "to local tree structure and remote REST service"), {
 
-    collectionContent <- c("animal", "animal/fish", "ball")
-    fakeREST <- FakeRESTService$new(collectionContent)
-
+    fakeREST <- FakeRESTService$new()
     api <- Arvados$new("myToken", "myHostName")
     api$setRESTService(fakeREST)
     collection <- Collection$new(api, "myUUID")
 
-    files <- c("dog", "cat")
-    collection$create(files, "animal")
+    collection$create(c("animal/dog", "animal/cat"))
 
     dog <- collection$get("animal/dog")
     cat <- collection$get("animal/cat")
     dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
     catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
 
-    expect_that(dogExistsInCollection, is_true())
-    expect_that(catExistsInCollection, is_true())
+    expect_true(dogExistsInCollection)
+    expect_true(catExistsInCollection)
     expect_that(fakeREST$createCallCount, equals(2))
 })
 
@@ -156,7 +134,7 @@ test_that("remove raises exception if passed argumet is not character vector", {
     collection <- Collection$new(api, "myUUID")
 
     expect_that(collection$remove(10),
-                throws_error("Expected character vector, got (numeric).", 
+                throws_error("Expected character vector, got (numeric).",
                              fixed = TRUE))
 })
 
@@ -190,8 +168,8 @@ test_that(paste("remove removes files specified by paths",
     dogExistsInCollection <- !is.null(dog) && dog$getName() == "dog"
     catExistsInCollection <- !is.null(cat) && cat$getName() == "cat"
 
-    expect_that(dogExistsInCollection, is_false())
-    expect_that(catExistsInCollection, is_false())
+    expect_false(dogExistsInCollection)
+    expect_false(catExistsInCollection)
     expect_that(fakeREST$deleteCallCount, equals(2))
 })
 
@@ -210,8 +188,8 @@ test_that(paste("move moves content to a new location inside file tree",
     dogIsNullOnOldLocation <- is.null(collection$get("animal/dog"))
     dogExistsOnNewLocation <- !is.null(collection$get("dog"))
 
-    expect_that(dogIsNullOnOldLocation, is_true())
-    expect_that(dogExistsOnNewLocation, is_true())
+    expect_true(dogIsNullOnOldLocation)
+    expect_true(dogExistsOnNewLocation)
     expect_that(fakeREST$moveCallCount, equals(1))
 })
 
@@ -238,10 +216,10 @@ test_that("getFileListing returns sorted collection content received from REST s
     api$setRESTService(fakeREST)
     collection <- Collection$new(api, "myUUID")
 
-    contentMatchExpected <- all(collection$getFileListing() == 
+    contentMatchExpected <- all(collection$getFileListing() ==
                                 c("animal", "animal/fish", "ball"))
 
-    expect_that(contentMatchExpected, is_true())
+    expect_true(contentMatchExpected)
     #2 calls because Collection$new calls getFileListing once
     expect_that(fakeREST$getCollectionContentCallCount, equals(2))
 
@@ -259,6 +237,67 @@ test_that("get returns arvados file or subcollection from internal tree structur
     fish <- collection$get("animal/fish")
     fishIsNotNull <- !is.null(fish)
 
-    expect_that(fishIsNotNull, is_true())
+    expect_true(fishIsNotNull)
+    expect_that(fish$getName(), equals("fish"))
+
+    ball <- collection$get("ball")
+    ballIsNotNull <- !is.null(ball)
+
+    expect_true(ballIsNotNull)
+    expect_that(ball$getName(), equals("ball"))
+})
+
+test_that(paste("copy copies content to a new location inside file tree",
+                "and on REST service"), {
+
+    collectionContent <- c("animal", "animal/dog", "ball")
+    fakeREST <- FakeRESTService$new(collectionContent)
+
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
+
+    collection$copy("animal/dog", "dog")
+
+    dogExistsOnOldLocation <- !is.null(collection$get("animal/dog"))
+    dogExistsOnNewLocation <- !is.null(collection$get("dog"))
+
+    expect_true(dogExistsOnOldLocation)
+    expect_true(dogExistsOnNewLocation)
+    expect_that(fakeREST$copyCallCount, equals(1))
+})
+
+test_that("copy raises exception if new location is not valid", {
+
+    collectionContent <- c("animal", "animal/fish", "ball")
+    fakeREST <- FakeRESTService$new(collectionContent)
+
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "myUUID")
+
+    expect_that(collection$copy("fish", "object"),
+                throws_error("Content you want to copy doesn't exist in the collection.",
+                             fixed = TRUE))
+})
+
+test_that("refresh invalidates current tree structure", {
+
+    collectionContent <- c("animal", "animal/fish", "ball")
+    fakeREST <- FakeRESTService$new(collectionContent)
+
+    api <- Arvados$new("myToken", "myHostName")
+    api$setRESTService(fakeREST)
+    collection <- Collection$new(api, "aaaaa-j7d0g-ccccccccccccccc")
+
+    # Before refresh
+    fish <- collection$get("animal/fish")
+    expect_that(fish$getName(), equals("fish"))
+    expect_that(fish$getCollection()$uuid, equals("aaaaa-j7d0g-ccccccccccccccc"))
+
+    collection$refresh()
+
+    # After refresh
     expect_that(fish$getName(), equals("fish"))
+    expect_true(is.null(fish$getCollection()))
 })