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 assert_empty(out, "STDOUT not expected: '#{out}'")
32 assert_match(/[0-9]+\.[0-9]+\.[0-9]+/, err, "Version information incorrect: '#{err}'")
36 out, err = capture_subprocess_io do
41 assert_match(/^usage:/, out)
44 def test_file_to_dev_stdout
45 test_file_to_stdout('/dev/stdout')
48 def test_file_to_stdout(specify_stdout_as='-')
49 out, err = capture_subprocess_io do
50 assert_arv_get @@foo_manifest_locator + '/foo', specify_stdout_as
53 assert_equal 'foo', out
58 out, err = capture_subprocess_io do
59 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/foo'
63 assert_equal 'foo', IO.read('tmp/foo')
66 def test_file_to_file_no_overwrite_file
67 File.open './tmp/foo', 'wb' do |f|
70 out, err = capture_subprocess_io do
71 assert_arv_get false, @@foo_manifest_locator + '/foo', 'tmp/foo'
73 assert_match(/Local file tmp\/foo already exists/, err)
75 assert_equal 'baz', IO.read('tmp/foo')
78 def test_file_to_file_no_overwrite_file_in_dir
79 File.open './tmp/foo', 'wb' do |f|
82 out, err = capture_subprocess_io do
83 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/'
85 assert_match(/Local file tmp\/foo already exists/, err)
87 assert_equal 'baz', IO.read('tmp/foo')
90 def test_file_to_file_force_overwrite
91 File.open './tmp/foo', 'wb' do |f|
94 assert_equal 'baz', IO.read('tmp/foo')
95 out, err = capture_subprocess_io do
96 assert_arv_get '-f', @@foo_manifest_locator + '/', 'tmp/'
100 assert_equal 'foo', IO.read('tmp/foo')
103 def test_file_to_file_skip_existing
104 File.open './tmp/foo', 'wb' do |f|
107 assert_equal 'baz', IO.read('tmp/foo')
108 out, err = capture_subprocess_io do
109 assert_arv_get '--skip-existing', @@foo_manifest_locator + '/', 'tmp/'
113 assert_equal 'baz', IO.read('tmp/foo')
118 out, err = capture_subprocess_io do
119 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/'
123 assert_equal 'foo', IO.read('tmp/foo')
127 out, err = capture_subprocess_io do
128 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/foo'
131 assert_match(/^usage:/, err)
134 def test_dir_to_empty_string
135 out, err = capture_subprocess_io do
136 assert_arv_get false, @@foo_manifest_locator + '/', ''
139 assert_match(/^usage:/, err)
142 def test_nonexistent_block
143 out, err = capture_subprocess_io do
144 assert_arv_get false, 'e796ab2294f3e48ec709ffa8d6daf58c'
147 assert_match(/ERROR:/, err)
150 def test_nonexistent_manifest
151 out, err = capture_subprocess_io do
152 assert_arv_get false, 'acbd18db4cc2f85cedef654fccc4a4d8/', 'tmp/'
155 assert_match(/ERROR:/, err)
158 def test_manifest_root_to_dir
160 out, err = capture_subprocess_io do
161 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp/'
165 assert_equal 'foo', IO.read('tmp/foo')
168 def test_manifest_root_to_dir_noslash
170 out, err = capture_subprocess_io do
171 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp'
175 assert_equal 'foo', IO.read('tmp/foo')
178 def test_display_md5sum
180 out, err = capture_subprocess_io do
181 assert_arv_get '-r', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
183 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
185 assert_equal 'foo', IO.read('tmp/foo')
188 def test_md5sum_nowrite
190 out, err = capture_subprocess_io do
191 assert_arv_get '-n', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
193 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
195 assert_equal false, File.exist?('tmp/foo')
198 def test_sha1_nowrite
200 out, err = capture_subprocess_io do
201 assert_arv_get '-n', '-r', '--hash', 'sha1', @@foo_manifest_locator+'/', 'tmp/'
203 assert_equal "#{Digest::SHA1.hexdigest('foo')} ./foo\n", err
205 assert_equal false, File.exist?('tmp/foo')
208 def test_block_to_file
210 out, err = capture_subprocess_io do
211 assert_arv_get @@foo_manifest_locator, 'tmp/foo'
216 digest = Digest::MD5.hexdigest('foo')
217 !(IO.read('tmp/foo')).gsub!( /^(. #{digest}+3)(.*)( 0:3:foo)$/).nil?
220 def test_create_directory_tree
221 `rm -rf ./tmp/arv-get-test/`
222 Dir.mkdir './tmp/arv-get-test'
223 out, err = capture_subprocess_io do
224 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
228 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
231 def test_create_partial_directory_tree
232 `rm -rf ./tmp/arv-get-test/`
233 Dir.mkdir './tmp/arv-get-test'
234 out, err = capture_subprocess_io do
235 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
240 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
244 def assert_arv_get(*args)
245 expect = case args.first
252 system(['./bin/arv-get', 'arv-get'], *args),
253 "`arv-get #{args.join ' '}` " +
254 "should exit #{if expect then 0 else 'non-zero' end}")
259 File.unlink('tmp/foo')