Merge branch '3036-collection-uuids' closes #3036
[arvados.git] / apps / workbench / test / unit / collection_test.rb
1 require 'test_helper'
2
3 class CollectionTest < ActiveSupport::TestCase
4   test 'recognize empty blob locator' do
5     ['d41d8cd98f00b204e9800998ecf8427e+0',
6      'd41d8cd98f00b204e9800998ecf8427e',
7      'd41d8cd98f00b204e9800998ecf8427e+0+Xyzzy'].each do |x|
8       assert_equal true, Collection.is_empty_blob_locator?(x)
9     end
10     ['d41d8cd98f00b204e9800998ecf8427e0',
11      'acbd18db4cc2f85cedef654fccc4a4d8+3',
12      'acbd18db4cc2f85cedef654fccc4a4d8+0'].each do |x|
13       assert_equal false, Collection.is_empty_blob_locator?(x)
14     end
15   end
16
17   def get_files_tree(coll_name)
18     use_token :admin
19     Collection.find(api_fixture('collections')[coll_name]['uuid']).files_tree
20   end
21
22   test "easy files_tree" do
23     files_in = lambda do |dirname|
24       (1..3).map { |n| [dirname, "file#{n}", 0] }
25     end
26     assert_equal([['.', 'dir1', nil], ['./dir1', 'subdir', nil]] +
27                  files_in['./dir1/subdir'] + files_in['./dir1'] +
28                  [['.', 'dir2', nil]] + files_in['./dir2'] + files_in['.'],
29                  get_files_tree('multilevel_collection_1'),
30                  "Collection file tree was malformed")
31   end
32
33   test "files_tree with files deep in subdirectories" do
34     # This test makes sure files_tree generates synthetic directory entries.
35     # The manifest doesn't list directories with no files.
36     assert_equal([['.', 'dir1', nil], ['./dir1', 'sub1', nil],
37                   ['./dir1/sub1', 'a', 0], ['./dir1/sub1', 'b', 0],
38                   ['.', 'dir2', nil], ['./dir2', 'sub2', nil],
39                   ['./dir2/sub2', 'c', 0], ['./dir2/sub2', 'd', 0]],
40                  get_files_tree('multilevel_collection_2'),
41                  "Collection file tree was malformed")
42   end
43 end