X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/4f552c0187f8c31d94ff74485c57ef7f9888597e..a0fc519db4f3664366c356d21a8478495f2ae78b:/apps/workbench/test/unit/collection_test.rb diff --git a/apps/workbench/test/unit/collection_test.rb b/apps/workbench/test/unit/collection_test.rb index bbfc98350f..512ad47c34 100644 --- a/apps/workbench/test/unit/collection_test.rb +++ b/apps/workbench/test/unit/collection_test.rb @@ -13,4 +13,31 @@ class CollectionTest < ActiveSupport::TestCase assert_equal false, Collection.is_empty_blob_locator?(x) end end + + def get_files_tree(coll_name) + use_token :admin + Collection.find(api_fixture('collections')[coll_name]['uuid']).files_tree + end + + test "easy files_tree" do + files_in = lambda do |dirname| + (1..3).map { |n| [dirname, "file#{n}", 0] } + end + assert_equal([['.', 'dir1', nil], ['./dir1', 'subdir', nil]] + + files_in['./dir1/subdir'] + files_in['./dir1'] + + [['.', 'dir2', nil]] + files_in['./dir2'] + files_in['.'], + get_files_tree('multilevel_collection_1'), + "Collection file tree was malformed") + end + + test "files_tree with files deep in subdirectories" do + # This test makes sure files_tree generates synthetic directory entries. + # The manifest doesn't list directories with no files. + assert_equal([['.', 'dir1', nil], ['./dir1', 'sub1', nil], + ['./dir1/sub1', 'a', 0], ['./dir1/sub1', 'b', 0], + ['.', 'dir2', nil], ['./dir2', 'sub2', nil], + ['./dir2/sub2', 'c', 0], ['./dir2/sub2', 'd', 0]], + get_files_tree('multilevel_collection_2'), + "Collection file tree was malformed") + end end