1 require 'minitest/autorun'
4 class TestArvPut < Minitest::Test
6 begin Dir.mkdir './tmp' rescue Errno::EEXIST end
7 begin Dir.mkdir './tmp/empty_dir' rescue Errno::EEXIST end
8 File.open './tmp/empty_file', 'wb' do
10 File.open './tmp/foo', 'wb' do |f|
16 out, err = capture_subprocess_io do
17 assert arv_put('-h'), 'arv-put -h exits zero'
21 assert_match /^usage:/, out
25 skip "Waiting unitl #4534 is implemented"
27 out, err = capture_subprocess_io do
34 assert arv_put('--raw', {in: r})
40 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
44 skip "Waiting unitl #4534 is implemented"
46 out, err = capture_subprocess_io do
47 assert arv_put('--raw', './tmp/foo')
51 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
54 def test_raw_empty_file
55 skip "Waiting unitl #4534 is implemented"
57 out, err = capture_subprocess_io do
58 assert arv_put('--raw', './tmp/empty_file')
62 assert_equal "d41d8cd98f00b204e9800998ecf8427e+0\n", out
65 def test_filename_arg_with_directory
66 out, err = capture_subprocess_io do
67 assert_equal(false, arv_put('--filename', 'foo', './tmp/empty_dir/.'),
68 'arv-put --filename refuses directory')
70 assert_match /^usage:.*error:/m, err
74 def test_filename_arg_with_multiple_files
75 out, err = capture_subprocess_io do
76 assert_equal(false, arv_put('--filename', 'foo',
79 'arv-put --filename refuses directory')
81 assert_match /^usage:.*error:/m, err
85 def test_filename_arg_with_empty_file
86 skip "Waiting unitl #4534 is implemented"
88 out, err = capture_subprocess_io do
89 assert arv_put('--filename', 'foo', './tmp/empty_file')
93 assert match_collection_uuid(out)
97 skip "Waiting unitl #4534 is implemented"
99 out, err = capture_subprocess_io do
100 assert arv_put('--as-stream', './tmp/foo')
104 assert_equal foo_manifest, out
108 skip "Waiting unitl #4534 is implemented"
110 out, err = capture_subprocess_io do
111 assert arv_put('--manifest', '--progress', './tmp/foo')
113 assert_match /%/, err
114 assert match_collection_uuid(out)
117 def test_batch_progress
118 skip "Waiting unitl #4534 is implemented"
120 out, err = capture_subprocess_io do
121 assert arv_put('--manifest', '--batch-progress', './tmp/foo')
123 assert_match /: 0 written 3 total/, err
124 assert_match /: 3 written 3 total/, err
125 assert match_collection_uuid(out)
128 def test_progress_and_batch_progress
129 out, err = capture_subprocess_io do
131 arv_put('--progress', '--batch-progress', './tmp/foo'),
132 'arv-put --progress --batch-progress is contradictory')
134 assert_match /^usage:.*error:/m, err
138 def test_read_from_implicit_stdin
139 skip "Waiting unitl #4534 is implemented"
141 test_read_from_stdin(specify_stdin_as='--manifest')
144 def test_read_from_dev_stdin
145 skip "Waiting unitl #4534 is implemented"
147 test_read_from_stdin(specify_stdin_as='/dev/stdin')
150 def test_read_from_stdin(specify_stdin_as='-')
151 skip "Waiting unitl #4534 is implemented"
153 out, err = capture_subprocess_io do
160 assert arv_put('--filename', 'foo', specify_stdin_as,
167 assert match_collection_uuid(out)
170 def test_read_from_implicit_stdin_implicit_manifest
171 skip "Waiting unitl #4534 is implemented"
173 test_read_from_stdin_implicit_manifest(specify_stdin_as=nil,
174 expect_filename='stdin')
177 def test_read_from_dev_stdin_implicit_manifest
178 skip "Waiting unitl #4534 is implemented"
180 test_read_from_stdin_implicit_manifest(specify_stdin_as='/dev/stdin')
183 def test_read_from_stdin_implicit_manifest(specify_stdin_as='-',
185 skip "Waiting unitl #4534 is implemented"
187 expect_filename = expect_filename || specify_stdin_as.split('/').last
188 out, err = capture_subprocess_io do
196 args.push specify_stdin_as if specify_stdin_as
197 assert arv_put(*args, { in: r })
203 assert match_collection_uuid(out)
208 system ['./bin/arv-put', 'arv-put'], *args
211 def foo_manifest(filename='foo')
212 ". #{Digest::MD5.hexdigest('foo')}+3 0:3:#{filename}\n"
215 def foo_manifest_locator(filename='foo')
216 Digest::MD5.hexdigest(foo_manifest(filename)) +
217 "+#{foo_manifest(filename).length}"
220 def match_collection_uuid(uuid)
221 /^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/.match(uuid)