1 require 'minitest/autorun'
4 class TestArvKeepPut < 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 out, err = capture_subprocess_io do
32 assert arv_put('--raw', {in: r})
38 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
42 out, err = capture_subprocess_io do
43 assert arv_put('--no-cache', '--raw', './tmp/foo')
47 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
50 def test_raw_empty_file
51 out, err = capture_subprocess_io do
52 assert arv_put('--raw', './tmp/empty_file')
56 assert_equal "d41d8cd98f00b204e9800998ecf8427e+0\n", out
59 def test_filename_arg_with_directory
60 out, err = capture_subprocess_io do
61 assert_equal(false, arv_put('--filename', 'foo', './tmp/empty_dir/.'),
62 'arv-put --filename refuses directory')
64 assert_match /^usage:.*error:/m, err
68 def test_filename_arg_with_multiple_files
69 out, err = capture_subprocess_io do
70 assert_equal(false, arv_put('--filename', 'foo',
73 'arv-put --filename refuses directory')
75 assert_match /^usage:.*error:/m, err
79 def test_filename_arg_with_empty_file
80 out, err = capture_subprocess_io do
81 assert arv_put('--filename', 'foo', './tmp/empty_file')
85 assert match_collection_uuid(out)
89 out, err = capture_subprocess_io do
90 assert arv_put('--no-cache', '--as-stream', './tmp/foo')
94 assert_equal foo_manifest, out
98 out, err = capture_subprocess_io do
99 assert arv_put('--no-cache', '--manifest', '--progress', './tmp/foo')
101 assert_match /%/, err
102 assert match_collection_uuid(out)
105 def test_batch_progress
106 out, err = capture_subprocess_io do
107 assert arv_put('--no-cache', '--manifest', '--batch-progress', './tmp/foo')
109 assert_match /: 0 written 3 total/, err
110 assert_match /: 3 written 3 total/, err
111 assert match_collection_uuid(out)
114 def test_progress_and_batch_progress
115 out, err = capture_subprocess_io do
117 arv_put('--progress', '--batch-progress', './tmp/foo'),
118 'arv-put --progress --batch-progress is contradictory')
120 assert_match /^usage:.*error:/m, err
124 def test_read_from_implicit_stdin
125 test_read_from_stdin(specify_stdin_as='--manifest')
128 def test_read_from_dev_stdin
129 test_read_from_stdin(specify_stdin_as='/dev/stdin')
132 def test_read_from_stdin(specify_stdin_as='-')
133 out, err = capture_subprocess_io do
140 assert arv_put('--filename', 'foo', specify_stdin_as,
147 assert match_collection_uuid(out)
150 def test_read_from_implicit_stdin_implicit_manifest
151 test_read_from_stdin_implicit_manifest(specify_stdin_as=nil,
152 expect_filename='stdin')
155 def test_read_from_dev_stdin_implicit_manifest
156 test_read_from_stdin_implicit_manifest(specify_stdin_as='/dev/stdin')
159 def test_read_from_stdin_implicit_manifest(specify_stdin_as='-',
161 expect_filename = expect_filename || specify_stdin_as.split('/').last
162 out, err = capture_subprocess_io do
170 args.push specify_stdin_as if specify_stdin_as
171 assert arv_put(*args, { in: r })
177 assert match_collection_uuid(out)
182 system ['./bin/arv-put', 'arv-put'], *args
185 def foo_manifest(filename='foo')
186 ". #{Digest::MD5.hexdigest('foo')}+3 0:3:#{filename}\n"
189 def foo_manifest_locator(filename='foo')
190 Digest::MD5.hexdigest(foo_manifest(filename)) +
191 "+#{foo_manifest(filename).length}"
194 def match_collection_uuid(uuid)
195 /^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/.match(uuid)