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