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 skip "Waiting unitl #4534 is implemented"
62 File.open './tmp/foo', 'wb' do |f|
65 out, err = capture_subprocess_io do
66 assert_arv_get false, @@foo_manifest_locator + '/foo', 'tmp/foo'
68 assert_match /Error:/, err
70 assert_equal 'baz', IO.read('tmp/foo')
73 def test_file_to_file_no_overwrite_file_in_dir
74 skip "Waiting unitl #4534 is implemented"
75 File.open './tmp/foo', 'wb' do |f|
78 out, err = capture_subprocess_io do
79 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/'
81 assert_match /Error:/, err
83 assert_equal 'baz', IO.read('tmp/foo')
86 def test_file_to_file_force_overwrite
87 skip "Waiting unitl #4534 is implemented"
89 File.open './tmp/foo', 'wb' do |f|
92 assert_equal 'baz', IO.read('tmp/foo')
93 out, err = capture_subprocess_io do
94 assert_arv_get '-f', @@foo_manifest_locator + '/', 'tmp/'
98 assert_equal 'foo', IO.read('tmp/foo')
101 def test_file_to_file_skip_existing
102 skip "Waiting unitl #4534 is implemented"
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')
117 skip "Waiting unitl #4534 is implemented"
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 skip "Waiting unitl #4534 is implemented"
147 out, err = capture_subprocess_io do
148 assert_arv_get false, 'f1554a91e925d6213ce7c3103c5110c6'
151 assert_match /Error:/, err
154 def test_nonexistent_manifest
155 skip "Waiting unitl #4534 is implemented"
157 out, err = capture_subprocess_io do
158 assert_arv_get false, 'f1554a91e925d6213ce7c3103c5110c6/', 'tmp/'
161 assert_match /Error:/, err
164 def test_manifest_root_to_dir
165 skip "Waiting unitl #4534 is implemented"
168 out, err = capture_subprocess_io do
169 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp/'
173 assert_equal 'foo', IO.read('tmp/foo')
176 def test_manifest_root_to_dir_noslash
177 skip "Waiting unitl #4534 is implemented"
180 out, err = capture_subprocess_io do
181 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp'
185 assert_equal 'foo', IO.read('tmp/foo')
188 def test_display_md5sum
189 skip "Waiting unitl #4534 is implemented"
192 out, err = capture_subprocess_io do
193 assert_arv_get '-r', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
195 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
197 assert_equal 'foo', IO.read('tmp/foo')
200 def test_md5sum_nowrite
201 skip "Waiting unitl #4534 is implemented"
204 out, err = capture_subprocess_io do
205 assert_arv_get '-n', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
207 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
209 assert_equal false, File.exists?('tmp/foo')
212 def test_sha1_nowrite
213 skip "Waiting unitl #4534 is implemented"
216 out, err = capture_subprocess_io do
217 assert_arv_get '-n', '-r', '--hash', 'sha1', @@foo_manifest_locator+'/', 'tmp/'
219 assert_equal "#{Digest::SHA1.hexdigest('foo')} ./foo\n", err
221 assert_equal false, File.exists?('tmp/foo')
224 def test_block_to_file
225 skip "Waiting unitl #4534 is implemented"
228 out, err = capture_subprocess_io do
229 assert_arv_get @@foo_manifest_locator, 'tmp/foo'
234 digest = Digest::MD5.hexdigest('foo')
235 !(IO.read('tmp/foo')).gsub!( /^(. #{digest}+3)(.*)( 0:3:foo)$/).nil?
238 def test_create_directory_tree
239 skip "Waiting unitl #4534 is implemented"
241 `rm -rf ./tmp/arv-get-test/`
242 Dir.mkdir './tmp/arv-get-test'
243 out, err = capture_subprocess_io do
244 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
248 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
251 def test_create_partial_directory_tree
252 skip "Waiting unitl #4534 is implemented"
254 `rm -rf ./tmp/arv-get-test/`
255 Dir.mkdir './tmp/arv-get-test'
256 out, err = capture_subprocess_io do
257 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
262 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
266 def assert_arv_get(*args)
267 expect = case args.first
274 system(['./bin/arv-get', 'arv-get'], *args),
275 "`arv-get #{args.join ' '}` " +
276 "should exit #{if expect then 0 else 'non-zero' end}")
281 File.unlink('tmp/foo')