1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 context("CollectionTree")
7 test_that("constructor creates file tree from character array properly", {
9 collection <- "myCollection"
10 characterArray <- c("animal",
14 collectionTree <- CollectionTree$new(characterArray, collection)
16 root <- collectionTree$getTree()
17 animal <- collectionTree$getElement("animal")
18 dog <- collectionTree$getElement("animal/dog")
19 boat <- collectionTree$getElement("boat")
21 rootHasNoParent <- is.null(root$getParent())
22 rootIsOfTypeSubcollection <- "Subcollection" %in% class(root)
23 animalIsOfTypeSubcollection <- "Subcollection" %in% class(animal)
24 dogIsOfTypeArvadosFile <- "ArvadosFile" %in% class(dog)
25 boatIsOfTypeArvadosFile <- "ArvadosFile" %in% class(boat)
26 animalsParentIsRoot <- animal$getParent()$getName() == root$getName()
27 animalContainsDog <- animal$getFirst()$getName() == dog$getName()
28 dogsParentIsAnimal <- dog$getParent()$getName() == animal$getName()
29 boatsParentIsRoot <- boat$getParent()$getName() == root$getName()
31 allElementsBelongToSameCollection <- root$getCollection() == "myCollection" &&
32 animal$getCollection() == "myCollection" &&
33 dog$getCollection() == "myCollection" &&
34 boat$getCollection() == "myCollection"
36 expect_that(root$getName(), equals(""))
37 expect_that(rootIsOfTypeSubcollection, is_true())
38 expect_that(rootHasNoParent, is_true())
39 expect_that(animalIsOfTypeSubcollection, is_true())
40 expect_that(animalsParentIsRoot, is_true())
41 expect_that(animalContainsDog, is_true())
42 expect_that(dogIsOfTypeArvadosFile, is_true())
43 expect_that(dogsParentIsAnimal, is_true())
44 expect_that(boatIsOfTypeArvadosFile, is_true())
45 expect_that(boatsParentIsRoot, is_true())
46 expect_that(allElementsBelongToSameCollection, is_true())
49 test_that("getElement returns element from tree if element exists on specified path", {
51 collection <- "myCollection"
52 characterArray <- c("animal",
56 collectionTree <- CollectionTree$new(characterArray, collection)
58 dog <- collectionTree$getElement("animal/dog")
60 expect_that(dog$getName(), equals("dog"))
63 test_that("getElement returns NULL from tree if element doesn't exists on specified path", {
65 collection <- "myCollection"
66 characterArray <- c("animal",
70 collectionTree <- CollectionTree$new(characterArray, collection)
72 fish <- collectionTree$getElement("animal/fish")
73 fishIsNULL <- is.null(fish)
75 expect_that(fishIsNULL, is_true())
78 test_that("getElement trims ./ from start of relativePath", {
80 collection <- "myCollection"
81 characterArray <- c("animal",
85 collectionTree <- CollectionTree$new(characterArray, collection)
87 dog <- collectionTree$getElement("animal/dog")
88 dogWithDotSlash <- collectionTree$getElement("./animal/dog")
90 expect_that(dogWithDotSlash$getName(), equals(dog$getName()))
93 test_that("getElement trims / from end of relativePath", {
95 collection <- "myCollection"
96 characterArray <- c("animal",
100 collectionTree <- CollectionTree$new(characterArray, collection)
102 animal <- collectionTree$getElement("animal")
103 animalWithSlash <- collectionTree$getElement("animal/")
105 expect_that(animalWithSlash$getName(), equals(animal$getName()))