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_equal(true, arv_put('-h'),
18 'arv-put -h exits zero')
22 assert_match /^usage:/, out
26 out, err = capture_subprocess_io do
33 assert_equal true, arv_put('--raw', {in: r})
39 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
43 out, err = capture_subprocess_io do
44 assert_equal true, arv_put('--raw', './tmp/foo')
48 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
51 def test_raw_empty_file
52 out, err = capture_subprocess_io do
53 assert_equal true, arv_put('--raw', './tmp/empty_file')
57 assert_equal "d41d8cd98f00b204e9800998ecf8427e+0\n", out
60 def test_filename_arg_with_directory
61 out, err = capture_subprocess_io do
62 assert_equal(false, arv_put('--filename', 'foo', './tmp/empty_dir/.'),
63 'arv-put --filename refuses directory')
65 assert_match /^usage:.*error:/m, err
69 def test_filename_arg_with_multiple_files
70 out, err = capture_subprocess_io do
71 assert_equal(false, arv_put('--filename', 'foo',
74 'arv-put --filename refuses directory')
76 assert_match /^usage:.*error:/m, err
80 def test_filename_arg_with_empty_file
81 out, err = capture_subprocess_io do
82 assert_equal true, arv_put('--filename', 'foo', './tmp/empty_file')
86 assert_equal "aa4f15cbf013142a7d98b1e273f9c661+45\n", out
90 out, err = capture_subprocess_io do
91 assert_equal true, arv_put('--as-stream', './tmp/foo')
95 assert_equal foo_manifest, out
99 out, err = capture_subprocess_io do
100 assert_equal true, arv_put('--manifest', '--progress', './tmp/foo')
102 assert_match /%/, err
103 assert_equal foo_manifest_locator+"\n", out
106 def test_batch_progress
107 out, err = capture_subprocess_io do
108 assert_equal true, arv_put('--manifest', '--batch-progress', './tmp/foo')
110 assert_match /: 0 written 3 total/, err
111 assert_match /: 3 written 3 total/, err
112 assert_equal foo_manifest_locator+"\n", out
115 def test_progress_and_batch_progress
116 out, err = capture_subprocess_io do
118 arv_put('--progress', '--batch-progress', './tmp/foo'),
119 'arv-put --progress --batch-progress is contradictory')
121 assert_match /^usage:.*error:/m, err
125 def test_read_from_implicit_stdin
126 test_read_from_stdin(specify_stdin_as='--manifest')
129 def test_read_from_dev_stdin
130 test_read_from_stdin(specify_stdin_as='/dev/stdin')
133 def test_read_from_stdin(specify_stdin_as='-')
134 out, err = capture_subprocess_io do
141 assert_equal true, arv_put('--filename', 'foo', specify_stdin_as,
148 assert_equal foo_manifest_locator+"\n", out
151 def test_read_from_implicit_stdin_implicit_manifest
152 test_read_from_stdin_implicit_manifest(specify_stdin_as=nil,
153 expect_filename='stdin')
156 def test_read_from_dev_stdin_implicit_manifest
157 test_read_from_stdin_implicit_manifest(specify_stdin_as='/dev/stdin')
160 def test_read_from_stdin_implicit_manifest(specify_stdin_as='-',
162 expect_filename = expect_filename || specify_stdin_as.split('/').last
163 out, err = capture_subprocess_io do
171 args.push specify_stdin_as if specify_stdin_as
172 assert_equal true, arv_put(*args, { in: r })
178 assert_equal(foo_manifest_locator(expect_filename)+"\n",
184 system ['./bin/arv-put', 'arv-put'], *args
187 def foo_manifest(filename='foo')
188 ". #{Digest::MD5.hexdigest('foo')}+3 0:3:#{filename}\n"
191 def foo_manifest_locator(filename='foo')
192 Digest::MD5.hexdigest(foo_manifest(filename)) +
193 "+#{foo_manifest(filename).length}"