[ARVADOS] updated: 16f43bd3117ab352d3d64882898716ade5b0163c
git at public.curoverse.com
git at public.curoverse.com
Tue Jan 14 17:23:56 EST 2014
Summary of changes:
sdk/cli/bin/arv-tag | 20 +++---
sdk/cli/test/test_arv-put.rb | 29 ++++----
sdk/cli/test/test_arv-tag.rb | 157 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 180 insertions(+), 26 deletions(-)
create mode 100644 sdk/cli/test/test_arv-tag.rb
via 16f43bd3117ab352d3d64882898716ade5b0163c (commit)
from ac86cc3a04d65c1f330e237aa70df468faffd207 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 16f43bd3117ab352d3d64882898716ade5b0163c
Author: Tim Pierce <twp at curoverse.com>
Date: Tue Jan 14 17:23:34 2014 -0500
Adding arv-tag unit tests.
Also:
Fix return value for deleting multiple links.
Clean up arv-put unit test code.
diff --git a/sdk/cli/bin/arv-tag b/sdk/cli/bin/arv-tag
index ca12cb1..9ce3f3d 100755
--- a/sdk/cli/bin/arv-tag
+++ b/sdk/cli/bin/arv-tag
@@ -81,11 +81,7 @@ def tag_remove(tag, obj_uuids=nil)
$stderr.puts "no tags found to remove"
end
- return {
- 'kind' => 'arvados#linkList',
- 'items_available' => results.length,
- 'items' => results,
- }
+ return results
end
if RUBY_VERSION < '1.9.3' then
@@ -191,6 +187,11 @@ $arvados = $client.discovered_api('arvados', $arvados_api_version)
results = []
cmd = ARGV.shift
+
+if ARGV.empty?
+ usage
+end
+
case cmd
when 'add'
ARGV.each do |tag|
@@ -201,9 +202,9 @@ when 'add'
when 'remove'
ARGV.each do |tag|
if $options[:all] then
- results.push(tag_remove(tag))
+ results.concat tag_remove(tag)
else
- results.push(tag_remove(tag, $options[:object]))
+ results.concat tag_remove(tag, $options[:object])
end
end
else
@@ -218,10 +219,7 @@ elsif global_opts[:json] then
puts Oj.dump(results)
else
results.each do |r|
- next if r == nil
- if r["items"] and r["kind"].match /list$/i
- r['items'].each do |i| puts i['uuid'] end
- elsif r['uuid'].nil?
+ if r['uuid'].nil?
abort("Response did not include a uuid:\n" +
Oj.dump(r, :indent => 1) +
"\n")
diff --git a/sdk/cli/test/test_arv-put.rb b/sdk/cli/test/test_arv-put.rb
index 53f05de..27809aa 100644
--- a/sdk/cli/test/test_arv-put.rb
+++ b/sdk/cli/test/test_arv-put.rb
@@ -14,11 +14,10 @@ class TestArvPut < Minitest::Test
def test_help
out, err = capture_subprocess_io do
- assert_equal(true, arv_put('-h'),
- 'arv-put -h exits zero')
+ assert arv_put('-h'), 'arv-put -h exits zero'
end
$stderr.write err
- assert_equal '', err
+ assert_empty err
assert_match /^usage:/, out
end
@@ -30,7 +29,7 @@ class TestArvPut < Minitest::Test
w << 'foo'
end
w.close
- assert_equal true, arv_put('--raw', {in: r})
+ assert arv_put('--raw', {in: r})
r.close
Process.waitpid wpid
end
@@ -41,7 +40,7 @@ class TestArvPut < Minitest::Test
def test_raw_file
out, err = capture_subprocess_io do
- assert_equal true, arv_put('--raw', './tmp/foo')
+ assert arv_put('--raw', './tmp/foo')
end
$stderr.write err
assert_match '', err
@@ -50,7 +49,7 @@ class TestArvPut < Minitest::Test
def test_raw_empty_file
out, err = capture_subprocess_io do
- assert_equal true, arv_put('--raw', './tmp/empty_file')
+ assert arv_put('--raw', './tmp/empty_file')
end
$stderr.write err
assert_match '', err
@@ -63,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
@@ -74,12 +73,12 @@ 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
@@ -88,7 +87,7 @@ class TestArvPut < Minitest::Test
def test_as_stream
out, err = capture_subprocess_io do
- assert_equal true, arv_put('--as-stream', './tmp/foo')
+ assert arv_put('--as-stream', './tmp/foo')
end
$stderr.write err
assert_match '', err
@@ -97,7 +96,7 @@ class TestArvPut < Minitest::Test
def test_progress
out, err = capture_subprocess_io do
- assert_equal true, arv_put('--manifest', '--progress', './tmp/foo')
+ assert arv_put('--manifest', '--progress', './tmp/foo')
end
assert_match /%/, err
assert_equal foo_manifest_locator+"\n", out
@@ -105,7 +104,7 @@ class TestArvPut < Minitest::Test
def test_batch_progress
out, err = capture_subprocess_io do
- assert_equal true, arv_put('--manifest', '--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
@@ -119,7 +118,7 @@ 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
@@ -138,7 +137,7 @@ 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
@@ -169,7 +168,7 @@ class TestArvPut < Minitest::Test
w.close
args = []
args.push specify_stdin_as if specify_stdin_as
- assert_equal true, arv_put(*args, { in: r })
+ assert arv_put(*args, { in: r })
r.close
Process.waitpid wpid
end
diff --git a/sdk/cli/test/test_arv-tag.rb b/sdk/cli/test/test_arv-tag.rb
new file mode 100644
index 0000000..247ac40
--- /dev/null
+++ b/sdk/cli/test/test_arv-tag.rb
@@ -0,0 +1,157 @@
+require 'minitest/autorun'
+require 'digest/md5'
+require 'json'
+
+def assert_failure *args
+ assert_equal false, *args
+end
+
+class TestArvTag < Minitest::Test
+
+ def test_no_args
+ # arv-tag exits with failure if run with no args
+ out, err = capture_subprocess_io do
+ assert_equal false, arv_tag
+ end
+ assert_empty out
+ assert_match /^usage:/i, err
+ end
+
+ # Test adding and removing a single tag on a single object.
+ def test_single_tag_single_obj
+ tag_uuid, err = capture_subprocess_io do
+ assert arv_tag 'add', 'test_tag1', '--object', 'uuid1'
+ end
+ assert_empty err
+
+ out, err = capture_subprocess_io do
+ assert arv '-h', 'link', 'show', '--uuid', tag_uuid.rstrip
+ end
+
+ assert_empty err
+ tag = JSON.parse out
+ assert_equal 'test_tag1', tag['name']
+ assert_equal 'tag', tag['link_class']
+ assert_equal 'uuid1', tag['head_uuid']
+
+ out, err = capture_subprocess_io do
+ assert arv_tag '-h', 'remove', 'test_tag1', '--object', 'uuid1'
+ end
+
+ assert_empty err
+ tag = JSON.parse out
+ assert_equal 'test_tag1', tag[0]['name']
+ assert_equal 'tag', tag[0]['link_class']
+ assert_equal 'uuid1', tag[0]['head_uuid']
+
+ out, err = capture_subprocess_io do
+ assert_equal false, arv('-h', 'link', 'show', '--uuid', tag[0]['uuid'])
+ end
+
+ assert_equal "Error: Path not found\n", err
+ end
+
+ # Test adding and removing a single tag with multiple objects.
+ def test_single_tag_multi_objects
+ out, err = capture_subprocess_io do
+ assert arv_tag('add', 'test_tag1',
+ '--object', 'uuid1',
+ '--object', 'uuid2',
+ '--object', 'uuid3')
+ end
+ assert_empty err
+
+ out, err = capture_subprocess_io do
+ assert arv '-h', 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
+ end
+
+ assert_empty err
+ json_out = JSON.parse out
+ links = json_out['items'].sort { |a,b| a['head_uuid'] <=> b['head_uuid'] }
+ assert_equal 'test_tag1', links[0]['name']
+ assert_equal 'tag', links[0]['link_class']
+ assert_equal 'uuid1', links[0]['head_uuid']
+ assert_equal 'test_tag1', links[1]['name']
+ assert_equal 'tag', links[1]['link_class']
+ assert_equal 'uuid2', links[1]['head_uuid']
+ assert_equal 'test_tag1', links[2]['name']
+ assert_equal 'tag', links[2]['link_class']
+ assert_equal 'uuid3', links[2]['head_uuid']
+
+ out, err = capture_subprocess_io do
+ assert arv_tag('remove', 'test_tag1',
+ '--object', 'uuid1',
+ '--object', 'uuid2',
+ '--object', 'uuid3')
+ end
+ assert_empty err
+
+ out, err = capture_subprocess_io do
+ assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
+ end
+
+ assert_empty err
+ assert_empty out
+ end
+
+ # Test adding and removing multiple tags with multiple objects.
+ def test_multi_tag_multi_objects
+ out, err = capture_subprocess_io do
+ assert arv_tag('add', 'test_tag1', 'test_tag2', 'test_tag3',
+ '--object', 'uuid1',
+ '--object', 'uuid2',
+ '--object', 'uuid3')
+ end
+
+ out, err = capture_subprocess_io do
+ assert arv '-h', 'link', 'list', '--where', '{"link_class":"tag"}'
+ end
+
+ assert_empty err
+ json_out = JSON.parse out
+ links = json_out['items'].sort { |a,b|
+ a['name'] <=> b['name'] or
+ a['head_uuid'] <=> b['head_uuid']
+ }
+
+ assert_equal 'test_tag1', links[0]['name']
+ assert_equal 'tag', links[0]['link_class']
+ assert_equal 'uuid1', links[0]['head_uuid']
+ assert_equal 'test_tag1', links[1]['name']
+ assert_equal 'tag', links[1]['link_class']
+ assert_equal 'uuid2', links[1]['head_uuid']
+ assert_equal 'test_tag1', links[2]['name']
+ assert_equal 'tag', links[2]['link_class']
+ assert_equal 'uuid3', links[2]['head_uuid']
+
+ assert_equal 'test_tag2', links[3]['name']
+ assert_equal 'tag', links[3]['link_class']
+ assert_equal 'uuid1', links[3]['head_uuid']
+ assert_equal 'test_tag2', links[4]['name']
+ assert_equal 'tag', links[4]['link_class']
+ assert_equal 'uuid2', links[4]['head_uuid']
+ assert_equal 'test_tag2', links[5]['name']
+ assert_equal 'tag', links[5]['link_class']
+ assert_equal 'uuid3', links[5]['head_uuid']
+
+ assert_equal 'test_tag3', links[6]['name']
+ assert_equal 'tag', links[6]['link_class']
+ assert_equal 'uuid1', links[6]['head_uuid']
+ assert_equal 'test_tag3', links[7]['name']
+ assert_equal 'tag', links[7]['link_class']
+ assert_equal 'uuid2', links[7]['head_uuid']
+ assert_equal 'test_tag3', links[8]['name']
+ assert_equal 'tag', links[8]['link_class']
+ assert_equal 'uuid3', links[8]['head_uuid']
+
+ end
+
+ protected
+ def arv_tag(*args)
+ system ['./bin/arv-tag', 'arv-tag'], *args
+ end
+
+ def arv(*args)
+ system ['./bin/arv', 'arv'], *args
+ end
+end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list