13108: Rename parallel_submit_count to thread_count
[arvados.git] / sdk / cli / test / test_arv-collection-create.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 require 'minitest/autorun'
6 require 'digest/md5'
7 require 'active_support'
8 require 'active_support/core_ext'
9 require 'tempfile'
10
11 class TestCollectionCreate < Minitest::Test
12   def setup
13   end
14
15   def test_small_collection
16     uuid = Digest::MD5.hexdigest(foo_manifest) + '+' + foo_manifest.size.to_s
17     out, err = capture_subprocess_io do
18       assert_arv('--format', 'uuid', 'collection', 'create', '--collection', {
19                    uuid: uuid,
20                    manifest_text: foo_manifest
21                  }.to_json)
22     end
23     assert /^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/.match(out)
24     assert_equal '', err
25   end
26
27   def test_read_resource_object_from_file
28     tempfile = Tempfile.new('collection')
29     begin
30       tempfile.write({manifest_text: foo_manifest}.to_json)
31       tempfile.close
32       out, err = capture_subprocess_io do
33         assert_arv('--format', 'uuid',
34                    'collection', 'create', '--collection', tempfile.path)
35       end
36       assert /^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/.match(out)
37       assert_equal '', err
38     ensure
39       tempfile.unlink
40     end
41   end
42
43   protected
44   def assert_arv(*args)
45     expect = case args.first
46              when true, false
47                args.shift
48              else
49                true
50              end
51     assert_equal(expect,
52                  system(['./bin/arv', 'arv'], *args),
53                  "`arv #{args.join ' '}` " +
54                  "should exit #{if expect then 0 else 'non-zero' end}")
55   end
56
57   def foo_manifest
58     ". #{Digest::MD5.hexdigest('foo')}+3 0:3:foo\n"
59   end
60 end