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 test_file_to_stdout('/dev/stdout')
36 def test_file_to_stdout(specify_stdout_as='-')
37 out, err = capture_subprocess_io do
38 assert_arv_get @@foo_manifest_locator + '/foo', specify_stdout_as
41 assert_equal 'foo', out
46 out, err = capture_subprocess_io do
47 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/foo'
51 assert_equal 'foo', IO.read('tmp/foo')
54 def test_file_to_file_no_overwrite_file
55 File.open './tmp/foo', 'wb' do |f|
58 out, err = capture_subprocess_io do
59 assert_arv_get false, @@foo_manifest_locator + '/foo', 'tmp/foo'
61 assert_match /^ERROR:/, err
63 assert_equal 'baz', IO.read('tmp/foo')
66 def test_file_to_file_no_overwrite_file_in_dir
67 File.open './tmp/foo', 'wb' do |f|
70 out, err = capture_subprocess_io do
71 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/'
73 assert_match /^ERROR:/, err
75 assert_equal 'baz', IO.read('tmp/foo')
78 def test_file_to_file_force_overwrite
79 File.open './tmp/foo', 'wb' do |f|
82 assert_equal 'baz', IO.read('tmp/foo')
83 out, err = capture_subprocess_io do
84 assert_arv_get '-f', @@foo_manifest_locator + '/', 'tmp/'
88 assert_equal 'foo', IO.read('tmp/foo')
91 def test_file_to_file_skip_existing
92 File.open './tmp/foo', 'wb' do |f|
95 assert_equal 'baz', IO.read('tmp/foo')
96 out, err = capture_subprocess_io do
97 assert_arv_get '--skip-existing', @@foo_manifest_locator + '/', 'tmp/'
101 assert_equal 'baz', IO.read('tmp/foo')
106 out, err = capture_subprocess_io do
107 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/'
111 assert_equal 'foo', IO.read('tmp/foo')
115 out, err = capture_subprocess_io do
116 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/foo'
119 assert_match /^usage:/, err
122 def test_dir_to_empty_string
123 out, err = capture_subprocess_io do
124 assert_arv_get false, @@foo_manifest_locator + '/', ''
127 assert_match /^usage:/, err
130 def test_nonexistent_block
131 out, err = capture_subprocess_io do
132 assert_arv_get false, 'f1554a91e925d6213ce7c3103c5110c6'
135 assert_match /^ERROR:/, err
138 def test_nonexistent_manifest
139 out, err = capture_subprocess_io do
140 assert_arv_get false, 'f1554a91e925d6213ce7c3103c5110c6/', 'tmp/'
143 assert_match /^ERROR:/, err
146 def test_manifest_root_to_dir
148 out, err = capture_subprocess_io do
149 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp/'
153 assert_equal 'foo', IO.read('tmp/foo')
156 def test_manifest_root_to_dir_noslash
158 out, err = capture_subprocess_io do
159 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp'
163 assert_equal 'foo', IO.read('tmp/foo')
166 def test_display_md5sum
168 out, err = capture_subprocess_io do
169 assert_arv_get '-r', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
171 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
173 assert_equal 'foo', IO.read('tmp/foo')
176 def test_md5sum_nowrite
178 out, err = capture_subprocess_io do
179 assert_arv_get '-n', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
181 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
183 assert_equal false, File.exists?('tmp/foo')
186 def test_sha1_nowrite
188 out, err = capture_subprocess_io do
189 assert_arv_get '-n', '-r', '--hash', 'sha1', @@foo_manifest_locator+'/', 'tmp/'
191 assert_equal "#{Digest::SHA1.hexdigest('foo')} ./foo\n", err
193 assert_equal false, File.exists?('tmp/foo')
196 def test_block_to_file
198 out, err = capture_subprocess_io do
199 assert_arv_get @@foo_manifest_locator, 'tmp/foo'
203 assert_equal foo_manifest, IO.read('tmp/foo')
206 def test_create_directory_tree
207 `rm -rf ./tmp/arv-get-test/`
208 Dir.mkdir './tmp/arv-get-test'
209 out, err = capture_subprocess_io do
210 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
214 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
217 def test_create_partial_directory_tree
218 `rm -rf ./tmp/arv-get-test/`
219 Dir.mkdir './tmp/arv-get-test'
220 out, err = capture_subprocess_io do
221 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
226 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
230 def assert_arv_get(*args)
231 expect = case args.first
238 system(['./bin/arv-get', 'arv-get'], *args),
239 "`arv-get #{args.join ' '}` " +
240 "should exit #{if expect then 0 else 'non-zero' end}")
244 ". #{Digest::MD5.hexdigest('foo')}+3 0:3:foo\n"
249 File.unlink('tmp/foo')