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