20684: Modernize pycurl dependency discussion
[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     ok = nil
18     out, err = capture_subprocess_io do
19       ok = arv('--format', 'uuid', 'collection', 'create', '--collection', {
20                      uuid: uuid,
21                      manifest_text: foo_manifest
22                    }.to_json)
23     end
24     assert_equal('', err)
25     assert_equal(true, ok)
26     assert_match(/^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/, out)
27   end
28
29   def test_collection_replace_files
30     ok = nil
31     uuid, err = capture_subprocess_io do
32       ok = arv('--format', 'uuid', 'collection', 'create', '--collection', '{}')
33     end
34     assert_equal('', err)
35     assert_equal(true, ok)
36     assert_match(/^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/, uuid)
37     uuid = uuid.strip
38
39     out, err = capture_subprocess_io do
40       ok = arv('--format', 'uuid',
41                    'collection', 'update',
42                    '--uuid', uuid,
43                    '--collection', '{}',
44                    '--replace-files', {
45                      "/gpl.pdf": "b519d9cb706a29fc7ea24dbea2f05851+93/GNU_General_Public_License,_version_3.pdf",
46                    }.to_json)
47     end
48     assert_equal('', err)
49     assert_equal(true, ok)
50     assert_equal(uuid, out.strip)
51
52     ok = nil
53     out, err = capture_subprocess_io do
54       ok = arv('--format', 'json', 'collection', 'get', '--uuid', uuid)
55     end
56     assert_equal('', err)
57     assert_equal(true, ok)
58     assert_match(/\. 6a4ff0499484c6c79c95cd8c566bd25f\+249025.* 0:249025:gpl.pdf\\n/, out)
59   end
60
61   def test_read_resource_object_from_file
62     tempfile = Tempfile.new('collection')
63     begin
64       tempfile.write({manifest_text: foo_manifest}.to_json)
65       tempfile.close
66       ok = nil
67       out, err = capture_subprocess_io do
68         ok = arv('--format', 'uuid',
69                      'collection', 'create', '--collection', tempfile.path)
70       end
71       assert_equal('', err)
72       assert_equal(true, ok)
73       assert_match(/^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/, out)
74     ensure
75       tempfile.unlink
76     end
77   end
78
79   protected
80   def arv(*args)
81     system(['./bin/arv', 'arv'], *args)
82   end
83
84   def foo_manifest
85     ". #{Digest::MD5.hexdigest('foo')}+3 0:3:foo\n"
86   end
87 end