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
25 assert_arv_get '--version'
27 assert_empty(out, "STDOUT not expected: '#{out}'")
28 assert_match(/[0-9]+\.[0-9]+\.[0-9]+/, err, "Version information incorrect: '#{err}'")
32 out, err = capture_subprocess_io do
37 assert_match /^usage:/, out
40 def test_file_to_dev_stdout
41 test_file_to_stdout('/dev/stdout')
44 def test_file_to_stdout(specify_stdout_as='-')
45 out, err = capture_subprocess_io do
46 assert_arv_get @@foo_manifest_locator + '/foo', specify_stdout_as
49 assert_equal 'foo', out
54 out, err = capture_subprocess_io do
55 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/foo'
59 assert_equal 'foo', IO.read('tmp/foo')
62 def test_file_to_file_no_overwrite_file
63 File.open './tmp/foo', 'wb' do |f|
66 out, err = capture_subprocess_io do
67 assert_arv_get false, @@foo_manifest_locator + '/foo', 'tmp/foo'
69 assert_match /Local file tmp\/foo already exists/, err
71 assert_equal 'baz', IO.read('tmp/foo')
74 def test_file_to_file_no_overwrite_file_in_dir
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 /Local file tmp\/foo already exists/, err
83 assert_equal 'baz', IO.read('tmp/foo')
86 def test_file_to_file_force_overwrite
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 File.open './tmp/foo', 'wb' do |f|
103 assert_equal 'baz', IO.read('tmp/foo')
104 out, err = capture_subprocess_io do
105 assert_arv_get '--skip-existing', @@foo_manifest_locator + '/', 'tmp/'
109 assert_equal 'baz', IO.read('tmp/foo')
114 out, err = capture_subprocess_io do
115 assert_arv_get @@foo_manifest_locator + '/foo', 'tmp/'
119 assert_equal 'foo', IO.read('tmp/foo')
123 out, err = capture_subprocess_io do
124 assert_arv_get false, @@foo_manifest_locator + '/', 'tmp/foo'
127 assert_match /^usage:/, err
130 def test_dir_to_empty_string
131 out, err = capture_subprocess_io do
132 assert_arv_get false, @@foo_manifest_locator + '/', ''
135 assert_match /^usage:/, err
138 def test_nonexistent_block
139 out, err = capture_subprocess_io do
140 assert_arv_get false, 'e796ab2294f3e48ec709ffa8d6daf58c'
143 assert_match /Error:/, err
146 def test_nonexistent_manifest
147 out, err = capture_subprocess_io do
148 assert_arv_get false, 'acbd18db4cc2f85cedef654fccc4a4d8/', 'tmp/'
151 assert_match /Error:/, err
154 def test_manifest_root_to_dir
156 out, err = capture_subprocess_io do
157 assert_arv_get '-r', @@foo_manifest_locator + '/', 'tmp/'
161 assert_equal 'foo', IO.read('tmp/foo')
164 def test_manifest_root_to_dir_noslash
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_display_md5sum
176 out, err = capture_subprocess_io do
177 assert_arv_get '-r', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
179 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
181 assert_equal 'foo', IO.read('tmp/foo')
184 def test_md5sum_nowrite
186 out, err = capture_subprocess_io do
187 assert_arv_get '-n', '--md5sum', @@foo_manifest_locator + '/', 'tmp/'
189 assert_equal "#{Digest::MD5.hexdigest('foo')} ./foo\n", err
191 assert_equal false, File.exist?('tmp/foo')
194 def test_sha1_nowrite
196 out, err = capture_subprocess_io do
197 assert_arv_get '-n', '-r', '--hash', 'sha1', @@foo_manifest_locator+'/', 'tmp/'
199 assert_equal "#{Digest::SHA1.hexdigest('foo')} ./foo\n", err
201 assert_equal false, File.exist?('tmp/foo')
204 def test_block_to_file
206 out, err = capture_subprocess_io do
207 assert_arv_get @@foo_manifest_locator, 'tmp/foo'
212 digest = Digest::MD5.hexdigest('foo')
213 !(IO.read('tmp/foo')).gsub!( /^(. #{digest}+3)(.*)( 0:3:foo)$/).nil?
216 def test_create_directory_tree
217 `rm -rf ./tmp/arv-get-test/`
218 Dir.mkdir './tmp/arv-get-test'
219 out, err = capture_subprocess_io do
220 assert_arv_get @@multilevel_manifest_locator + '/', 'tmp/arv-get-test/'
224 assert_equal 'baz', IO.read('tmp/arv-get-test/foo/bar/baz')
227 def test_create_partial_directory_tree
228 `rm -rf ./tmp/arv-get-test/`
229 Dir.mkdir './tmp/arv-get-test'
230 out, err = capture_subprocess_io do
231 assert_arv_get(@@multilevel_manifest_locator + '/foo/',
236 assert_equal 'baz', IO.read('tmp/arv-get-test/bar/baz')
240 def assert_arv_get(*args)
241 expect = case args.first
248 system(['./bin/arv-get', 'arv-get'], *args),
249 "`arv-get #{args.join ' '}` " +
250 "should exit #{if expect then 0 else 'non-zero' end}")
255 File.unlink('tmp/foo')