1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 require 'minitest/autorun'
8 class TestArvKeepPut < Minitest::Test
10 begin Dir.mkdir './tmp' rescue Errno::EEXIST end
11 begin Dir.mkdir './tmp/empty_dir' rescue Errno::EEXIST end
12 File.open './tmp/empty_file', 'wb' do
14 File.open './tmp/foo', 'wb' do |f|
20 out, err = capture_subprocess_io do
21 assert arv_put('-h'), 'arv-put -h exits zero'
25 assert_match /^usage:/, out
29 out, err = capture_subprocess_io do
36 assert arv_put('--raw', {in: r})
42 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
46 out, err = capture_subprocess_io do
47 assert arv_put('--no-cache', '--raw', './tmp/foo')
51 assert_equal "acbd18db4cc2f85cedef654fccc4a4d8+3\n", out
54 def test_raw_empty_file
55 out, err = capture_subprocess_io do
56 assert arv_put('--raw', './tmp/empty_file')
60 assert_equal "d41d8cd98f00b204e9800998ecf8427e+0\n", out
63 def test_filename_arg_with_directory
64 out, err = capture_subprocess_io do
65 assert_equal(false, arv_put('--filename', 'foo', './tmp/empty_dir/.'),
66 'arv-put --filename refuses directory')
68 assert_match /^usage:.*error:/m, err
72 def test_filename_arg_with_multiple_files
73 out, err = capture_subprocess_io do
74 assert_equal(false, arv_put('--filename', 'foo',
77 'arv-put --filename refuses directory')
79 assert_match /^usage:.*error:/m, err
83 def test_filename_arg_with_empty_file
84 out, err = capture_subprocess_io do
85 assert arv_put('--filename', 'foo', './tmp/empty_file')
89 assert match_collection_uuid(out)
93 out, err = capture_subprocess_io do
94 assert arv_put('--no-cache', '--as-stream', './tmp/foo')
98 assert_equal foo_manifest, out
102 out, err = capture_subprocess_io do
103 assert arv_put('--no-cache', '--manifest', '--progress', './tmp/foo')
105 assert_match /%/, err
106 assert match_collection_uuid(out)
109 def test_batch_progress
110 out, err = capture_subprocess_io do
111 assert arv_put('--no-cache', '--manifest', '--batch-progress', './tmp/foo')
113 assert_match /: 0 written 3 total/, err
114 assert_match /: 3 written 3 total/, err
115 assert match_collection_uuid(out)
118 def test_progress_and_batch_progress
119 out, err = capture_subprocess_io do
121 arv_put('--progress', '--batch-progress', './tmp/foo'),
122 'arv-put --progress --batch-progress is contradictory')
124 assert_match /^usage:.*error:/m, err
128 def test_read_from_implicit_stdin
129 test_read_from_stdin(specify_stdin_as='--manifest')
132 def test_read_from_dev_stdin
133 test_read_from_stdin(specify_stdin_as='/dev/stdin')
136 def test_read_from_stdin(specify_stdin_as='-')
137 out, err = capture_subprocess_io do
144 assert arv_put('--filename', 'foo', specify_stdin_as,
151 assert match_collection_uuid(out)
154 def test_read_from_implicit_stdin_implicit_manifest
155 test_read_from_stdin_implicit_manifest(specify_stdin_as=nil,
156 expect_filename='stdin')
159 def test_read_from_dev_stdin_implicit_manifest
160 test_read_from_stdin_implicit_manifest(specify_stdin_as='/dev/stdin')
163 def test_read_from_stdin_implicit_manifest(specify_stdin_as='-',
165 expect_filename = expect_filename || specify_stdin_as.split('/').last
166 out, err = capture_subprocess_io do
174 args.push specify_stdin_as if specify_stdin_as
175 assert arv_put(*args, { in: r })
181 assert match_collection_uuid(out)
186 system ['./bin/arv-put', 'arv-put'], *args
189 def foo_manifest(filename='foo')
190 ". #{Digest::MD5.hexdigest('foo')}+3 0:3:#{filename}\n"
193 def foo_manifest_locator(filename='foo')
194 Digest::MD5.hexdigest(foo_manifest(filename)) +
195 "+#{foo_manifest(filename).length}"
198 def match_collection_uuid(uuid)
199 /^([0-9a-z]{5}-4zz18-[0-9a-z]{15})?$/.match(uuid)