1 require 'minitest/autorun'
4 class TestArvKeepGet < 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 /Local file tmp\/foo already exists/, 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 /Local file tmp\/foo already exists/, 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, 'e796ab2294f3e48ec709ffa8d6daf58c'
135 assert_match /Error:/, err
138 def test_nonexistent_manifest
139 out, err = capture_subprocess_io do
140 assert_arv_get false, 'acbd18db4cc2f85cedef654fccc4a4d8/', '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'
204 digest = Digest::MD5.hexdigest('foo')
205 !(IO.read('tmp/foo')).gsub!( /^(. #{digest}+3)(.*)( 0:3:foo)$/).nil?
208 def test_create_directory_tree
209 `rm -rf ./tmp/arv-get-test/`
210 Dir.mkdir './tmp/arv-get-test'
211 out, err = capture_subprocess_io do
212 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
216 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
219 def test_create_partial_directory_tree
220 `rm -rf ./tmp/arv-get-test/`
221 Dir.mkdir './tmp/arv-get-test'
222 out, err = capture_subprocess_io do
223 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
228 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
232 def assert_arv_get(*args)
233 expect = case args.first
240 system(['./bin/arv-get', 'arv-get'], *args),
241 "`arv-get #{args.join ' '}` " +
242 "should exit #{if expect then 0 else 'non-zero' end}")
247 File.unlink('tmp/foo')