1 require 'minitest/autorun'
4 class TestArvGet < Minitest::Test
10 @@foo_manifest_locator ||= `echo -n foo | ./bin/arv-put --filename foo --no-progress -`.strip
11 @@baz_locator ||= `echo -n baz | ./bin/arv-put --as-raw --no-progress -`.strip
12 @@multilevel_manifest_locator ||= `echo ./foo/bar #{@@baz_locator} 0:3:baz | ./bin/arv-put --as-raw --no-progress -`.strip
16 out, err = capture_subprocess_io do
20 assert_match /^usage:/, err
24 out, err = capture_subprocess_io do
29 assert_match /^usage:/, out
32 def test_file_to_dev_stdout
33 skip "Waiting unitl #4534 is implemented"
35 test_file_to_stdout('/dev/stdout')
38 def test_file_to_stdout(specify_stdout_as='-')
39 skip "Waiting unitl #4534 is implemented"
41 out, err = capture_subprocess_io do
42 assert_arv_get @@foo_manifest_locator + '/foo', specify_stdout_as
45 assert_equal 'foo', out
49 skip "Waiting unitl #4534 is implemented"
52 out, err = capture_subprocess_io do
53 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/foo'
57 assert_equal 'foo', IO.read('tmp/foo')
60 def test_file_to_file_no_overwrite_file
61 File.open './tmp/foo', 'wb' do |f|
64 out, err = capture_subprocess_io do
65 assert_arv_get false, @@foo_manifest_locator + '/foo', 'tmp/foo'
67 assert_match /Error:/, err
69 assert_equal 'baz', IO.read('tmp/foo')
72 def test_file_to_file_no_overwrite_file_in_dir
73 File.open './tmp/foo', 'wb' do |f|
76 out, err = capture_subprocess_io do
77 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/'
79 assert_match /Error:/, err
81 assert_equal 'baz', IO.read('tmp/foo')
84 def test_file_to_file_force_overwrite
85 skip "Waiting unitl #4534 is implemented"
87 File.open './tmp/foo', 'wb' do |f|
90 assert_equal 'baz', IO.read('tmp/foo')
91 out, err = capture_subprocess_io do
92 assert_arv_get '-f', @@foo_manifest_locator + '/', 'tmp/'
96 assert_equal 'foo', IO.read('tmp/foo')
99 def test_file_to_file_skip_existing
100 skip "Waiting unitl #4534 is implemented"
102 File.open './tmp/foo', 'wb' do |f|
105 assert_equal 'baz', IO.read('tmp/foo')
106 out, err = capture_subprocess_io do
107 assert_arv_get '--skip-existing', @@foo_manifest_locator + '/', 'tmp/'
111 assert_equal 'baz', IO.read('tmp/foo')
115 skip "Waiting unitl #4534 is implemented"
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 skip "Waiting unitl #4534 is implemented"
145 out, err = capture_subprocess_io do
146 assert_arv_get false, 'f1554a91e925d6213ce7c3103c5110c6'
149 assert_match /Error:/, err
152 def test_nonexistent_manifest
153 skip "Waiting unitl #4534 is implemented"
155 out, err = capture_subprocess_io do
156 assert_arv_get false, 'f1554a91e925d6213ce7c3103c5110c6/', 'tmp/'
159 assert_match /Error:/, err
162 def test_manifest_root_to_dir
163 skip "Waiting unitl #4534 is implemented"
166 out, err = capture_subprocess_io do
167 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp/'
171 assert_equal 'foo', IO.read('tmp/foo')
174 def test_manifest_root_to_dir_noslash
175 skip "Waiting unitl #4534 is implemented"
178 out, err = capture_subprocess_io do
179 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp'
183 assert_equal 'foo', IO.read('tmp/foo')
186 def test_display_md5sum
187 skip "Waiting unitl #4534 is implemented"
190 out, err = capture_subprocess_io do
191 assert_arv_get '-r', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
193 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
195 assert_equal 'foo', IO.read('tmp/foo')
198 def test_md5sum_nowrite
199 skip "Waiting unitl #4534 is implemented"
202 out, err = capture_subprocess_io do
203 assert_arv_get '-n', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
205 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
207 assert_equal false, File.exists?('tmp/foo')
210 def test_sha1_nowrite
211 skip "Waiting unitl #4534 is implemented"
214 out, err = capture_subprocess_io do
215 assert_arv_get '-n', '-r', '--hash', 'sha1', @@foo_manifest_locator+'/', 'tmp/'
217 assert_equal "#{Digest::SHA1.hexdigest('foo')} ./foo\n", err
219 assert_equal false, File.exists?('tmp/foo')
222 def test_block_to_file
223 skip "Waiting unitl #4534 is implemented"
226 out, err = capture_subprocess_io do
227 assert_arv_get @@foo_manifest_locator, 'tmp/foo'
232 digest = Digest::MD5.hexdigest('foo')
233 !(IO.read('tmp/foo')).gsub!( /^(. #{digest}+3)(.*)( 0:3:foo)$/).nil?
236 def test_create_directory_tree
237 skip "Waiting unitl #4534 is implemented"
239 `rm -rf ./tmp/arv-get-test/`
240 Dir.mkdir './tmp/arv-get-test'
241 out, err = capture_subprocess_io do
242 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
246 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
249 def test_create_partial_directory_tree
250 skip "Waiting unitl #4534 is implemented"
252 `rm -rf ./tmp/arv-get-test/`
253 Dir.mkdir './tmp/arv-get-test'
254 out, err = capture_subprocess_io do
255 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
260 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
264 def assert_arv_get(*args)
265 expect = case args.first
272 system(['./bin/arv-get', 'arv-get'], *args),
273 "`arv-get #{args.join ' '}` " +
274 "should exit #{if expect then 0 else 'non-zero' end}")
279 File.unlink('tmp/foo')