X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/da85cb6ee25ca7d9efd0cf39005047a02806e98e..d836cb04ab7e577b3f7896d6b49e78b97ed832f8:/sdk/cli/test/test_arv-put.rb?ds=inline diff --git a/sdk/cli/test/test_arv-put.rb b/sdk/cli/test/test_arv-put.rb index 7c8fc1790c..27809aaded 100644 --- a/sdk/cli/test/test_arv-put.rb +++ b/sdk/cli/test/test_arv-put.rb @@ -3,11 +3,8 @@ require 'digest/md5' class TestArvPut < Minitest::Test def setup - begin - Dir.mkdir './tmp' - Dir.mkdir './tmp/empty_dir' - rescue Errno::EEXIST - end + begin Dir.mkdir './tmp' rescue Errno::EEXIST end + begin Dir.mkdir './tmp/empty_dir' rescue Errno::EEXIST end File.open './tmp/empty_file', 'wb' do end File.open './tmp/foo', 'wb' do |f| @@ -15,22 +12,48 @@ class TestArvPut < Minitest::Test end end - def test_no_args + def test_help out, err = capture_subprocess_io do - assert_equal(false, arv_put, - 'arv-put without args exits non-zero') + assert arv_put('-h'), 'arv-put -h exits zero' end - assert_equal '', out - assert_match /^usage:/, err + $stderr.write err + assert_empty err + assert_match /^usage:/, out end - def test_help + def test_raw_stdin out, err = capture_subprocess_io do - assert_equal(true, arv_put('-h'), - 'arv-put -h exits zero') + r,w = IO.pipe + wpid = fork do + r.close + w << 'foo' + end + w.close + assert arv_put('--raw', {in: r}) + r.close + Process.waitpid wpid end - assert_equal '', err - assert_match /^usage:/, out + $stderr.write err + assert_match '', err + assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out + end + + def test_raw_file + out, err = capture_subprocess_io do + assert arv_put('--raw', './tmp/foo') + end + $stderr.write err + assert_match '', err + assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out + end + + def test_raw_empty_file + out, err = capture_subprocess_io do + assert arv_put('--raw', './tmp/empty_file') + end + $stderr.write err + assert_match '', err + assert_equal "d41d8cd98f00b204e9800998ecf8427e+0\n", out end def test_filename_arg_with_directory @@ -39,7 +62,7 @@ class TestArvPut < Minitest::Test 'arv-put --filename refuses directory') end assert_match /^usage:.*error:/m, err - assert_equal '', out + assert_empty out end def test_filename_arg_with_multiple_files @@ -50,33 +73,42 @@ class TestArvPut < Minitest::Test 'arv-put --filename refuses directory') end assert_match /^usage:.*error:/m, err - assert_equal '', out + assert_empty out end def test_filename_arg_with_empty_file out, err = capture_subprocess_io do - assert_equal true, arv_put('--filename', 'foo', './tmp/empty_file') + assert arv_put('--filename', 'foo', './tmp/empty_file') end $stderr.write err assert_match '', err assert_equal "aa4f15cbf013142a7d98b1e273f9c661+45\n", out end + def test_as_stream + out, err = capture_subprocess_io do + assert arv_put('--as-stream', './tmp/foo') + end + $stderr.write err + assert_match '', err + assert_equal foo_manifest, out + end + def test_progress out, err = capture_subprocess_io do - assert_equal true, arv_put('--progress', './tmp/foo') + assert arv_put('--manifest', '--progress', './tmp/foo') end assert_match /%/, err - expect_foo_manifest(out) + assert_equal foo_manifest_locator+"\n", out end def test_batch_progress out, err = capture_subprocess_io do - assert_equal true, arv_put('--batch-progress', './tmp/foo') + assert arv_put('--manifest', '--batch-progress', './tmp/foo') end assert_match /: 0 written 3 total/, err assert_match /: 3 written 3 total/, err - expect_foo_manifest(out) + assert_equal foo_manifest_locator+"\n", out end def test_progress_and_batch_progress @@ -86,7 +118,11 @@ class TestArvPut < Minitest::Test 'arv-put --progress --batch-progress is contradictory') end assert_match /^usage:.*error:/m, err - assert_equal '', out + assert_empty out + end + + def test_read_from_implicit_stdin + test_read_from_stdin(specify_stdin_as='--manifest') end def test_read_from_dev_stdin @@ -101,14 +137,45 @@ class TestArvPut < Minitest::Test w << 'foo' end w.close - assert_equal true, arv_put('--filename', 'foo', specify_stdin_as, + assert arv_put('--filename', 'foo', specify_stdin_as, { in: r }) r.close Process.waitpid wpid end $stderr.write err assert_match '', err - expect_foo_manifest(out) + assert_equal foo_manifest_locator+"\n", out + end + + def test_read_from_implicit_stdin_implicit_manifest + test_read_from_stdin_implicit_manifest(specify_stdin_as=nil, + expect_filename='stdin') + end + + def test_read_from_dev_stdin_implicit_manifest + test_read_from_stdin_implicit_manifest(specify_stdin_as='/dev/stdin') + end + + def test_read_from_stdin_implicit_manifest(specify_stdin_as='-', + expect_filename=nil) + expect_filename = expect_filename || specify_stdin_as.split('/').last + out, err = capture_subprocess_io do + r,w = IO.pipe + wpid = fork do + r.close + w << 'foo' + end + w.close + args = [] + args.push specify_stdin_as if specify_stdin_as + assert arv_put(*args, { in: r }) + r.close + Process.waitpid wpid + end + $stderr.write err + assert_match '', err + assert_equal(foo_manifest_locator(expect_filename)+"\n", + out) end protected @@ -116,10 +183,12 @@ class TestArvPut < Minitest::Test system ['./bin/arv-put', 'arv-put'], *args end - def expect_foo_manifest(out) - expect_manifest = ". #{Digest::MD5.hexdigest('foo')}+3 0:3:foo\n" - assert_equal(Digest::MD5.hexdigest(expect_manifest) + - "+#{expect_manifest.length}\n", - out) + def foo_manifest(filename='foo') + ". #{Digest::MD5.hexdigest('foo')}+3 0:3:#{filename}\n" + end + + def foo_manifest_locator(filename='foo') + Digest::MD5.hexdigest(foo_manifest(filename)) + + "+#{foo_manifest(filename).length}" end end