1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 require 'minitest/autorun'
8 class TestArvKeepGet < Minitest::Test
14 @@foo_manifest_locator ||= `echo -n foo | ./bin/arv-put --filename foo --no-progress -`.strip
15 @@baz_locator ||= `echo -n baz | ./bin/arv-put --as-raw --no-progress -`.strip
16 @@multilevel_manifest_locator ||= `echo -n baz | ./bin/arv-put --filename foo/bar/baz --no-progress -`.strip
20 out, err = capture_subprocess_io do
24 assert_match(/^usage:/, err)
28 out, err = capture_subprocess_io do
29 assert_arv_get '--version'
31 # python3 handles action='version' differently than python2
32 # https://dev.arvados.org/issues/15888#note-23
33 assert_empty(err, "STDERR not expected: '#{err}'")
34 assert_match(/[0-9]+\.[0-9]+\.[0-9]+/, out, "Version information incorrect: '#{out}'")
38 out, err = capture_subprocess_io do
43 assert_match(/^usage:/, out)
46 def test_file_to_dev_stdout
47 test_file_to_stdout('/dev/stdout')
50 def test_file_to_stdout(specify_stdout_as='-')
51 out, err = capture_subprocess_io do
52 assert_arv_get @@foo_manifest_locator + '/foo', specify_stdout_as
55 assert_equal 'foo', out
60 out, err = capture_subprocess_io do
61 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/foo'
65 assert_equal 'foo', IO.read('tmp/foo')
68 def test_file_to_file_no_overwrite_file
69 File.open './tmp/foo', 'wb' do |f|
72 out, err = capture_subprocess_io do
73 assert_arv_get false, @@foo_manifest_locator + '/foo', 'tmp/foo'
75 assert_match(/Local file tmp\/foo already exists/, err)
77 assert_equal 'baz', IO.read('tmp/foo')
80 def test_file_to_file_no_overwrite_file_in_dir
81 File.open './tmp/foo', 'wb' do |f|
84 out, err = capture_subprocess_io do
85 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/'
87 assert_match(/Local file tmp\/foo already exists/, err)
89 assert_equal 'baz', IO.read('tmp/foo')
92 def test_file_to_file_force_overwrite
93 File.open './tmp/foo', 'wb' do |f|
96 assert_equal 'baz', IO.read('tmp/foo')
97 out, err = capture_subprocess_io do
98 assert_arv_get '-f', @@foo_manifest_locator + '/', 'tmp/'
102 assert_equal 'foo', IO.read('tmp/foo')
105 def test_file_to_file_skip_existing
106 File.open './tmp/foo', 'wb' do |f|
109 assert_equal 'baz', IO.read('tmp/foo')
110 out, err = capture_subprocess_io do
111 assert_arv_get '--skip-existing', @@foo_manifest_locator + '/', 'tmp/'
115 assert_equal 'baz', IO.read('tmp/foo')
120 out, err = capture_subprocess_io do
121 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/'
125 assert_equal 'foo', IO.read('tmp/foo')
129 out, err = capture_subprocess_io do
130 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/foo'
133 assert_match(/^usage:/, err)
136 def test_dir_to_empty_string
137 out, err = capture_subprocess_io do
138 assert_arv_get false, @@foo_manifest_locator + '/', ''
141 assert_match(/^usage:/, err)
144 def test_nonexistent_block
145 out, err = capture_subprocess_io do
146 assert_arv_get false, 'e796ab2294f3e48ec709ffa8d6daf58c'
149 assert_match(/ERROR:/, err)
152 def test_nonexistent_manifest
153 out, err = capture_subprocess_io do
154 assert_arv_get false, 'acbd18db4cc2f85cedef654fccc4a4d8/', 'tmp/'
157 assert_match(/ERROR:/, err)
160 def test_manifest_root_to_dir
162 out, err = capture_subprocess_io do
163 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp/'
167 assert_equal 'foo', IO.read('tmp/foo')
170 def test_manifest_root_to_dir_noslash
172 out, err = capture_subprocess_io do
173 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp'
177 assert_equal 'foo', IO.read('tmp/foo')
180 def test_display_md5sum
182 out, err = capture_subprocess_io do
183 assert_arv_get '-r', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
185 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
187 assert_equal 'foo', IO.read('tmp/foo')
190 def test_md5sum_nowrite
192 out, err = capture_subprocess_io do
193 assert_arv_get '-n', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
195 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
197 assert_equal false, File.exist?('tmp/foo')
200 def test_sha1_nowrite
202 out, err = capture_subprocess_io do
203 assert_arv_get '-n', '-r', '--hash', 'sha1', @@foo_manifest_locator+'/', 'tmp/'
205 assert_equal "#{Digest::SHA1.hexdigest('foo')} ./foo\n", err
207 assert_equal false, File.exist?('tmp/foo')
210 def test_block_to_file
212 out, err = capture_subprocess_io do
213 assert_arv_get @@foo_manifest_locator, 'tmp/foo'
218 digest = Digest::MD5.hexdigest('foo')
219 !(IO.read('tmp/foo')).gsub!( /^(. #{digest}+3)(.*)( 0:3:foo)$/).nil?
222 def test_create_directory_tree
223 `rm -rf ./tmp/arv-get-test/`
224 Dir.mkdir './tmp/arv-get-test'
225 out, err = capture_subprocess_io do
226 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
230 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
233 def test_create_partial_directory_tree
234 `rm -rf ./tmp/arv-get-test/`
235 Dir.mkdir './tmp/arv-get-test'
236 out, err = capture_subprocess_io do
237 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
242 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
246 def assert_arv_get(*args)
247 expect = case args.first
254 system(['./bin/arv-get', 'arv-get'], *args),
255 "`arv-get #{args.join ' '}` " +
256 "should exit #{if expect then 0 else 'non-zero' end}")
261 File.unlink('tmp/foo')