1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: Apache-2.0
5 require 'minitest/autorun'
9 def assert_failure *args
10 assert_equal false, *args
13 class TestArvTag < Minitest::Test
16 skip "Waiting until #4534 is implemented"
18 # arv-tag exits with failure if run with no args
19 out, err = capture_subprocess_io do
20 assert_equal false, arv_tag
23 assert_match /^usage:/i, err
26 # Test adding and removing a single tag on a single object.
27 def test_single_tag_single_obj
31 tag_uuid, err = capture_subprocess_io do
32 assert arv_tag '--short', 'add', 'test_tag1', '--object', 'uuid1'
36 out, err = capture_subprocess_io do
37 assert arv 'link', 'show', '--uuid', tag_uuid.rstrip
42 assert_tag link, 'test_tag1', 'uuid1'
45 out, err = capture_subprocess_io do
46 assert arv_tag 'remove', 'test_tag1', '--object', 'uuid1'
50 links = JSON.parse out
51 assert_equal 1, links.length
52 assert_tag links[0], 'test_tag1', 'uuid1'
54 # Verify that the link no longer exists.
55 out, err = capture_subprocess_io do
56 assert_equal false, arv('link', 'show', '--uuid', links[0]['uuid'])
59 assert_equal "Error: Path not found\n", err
62 # Test adding and removing a single tag with multiple objects.
63 def test_single_tag_multi_objects
66 out, err = capture_subprocess_io do
67 assert arv_tag('add', 'test_tag1',
74 out, err = capture_subprocess_io do
75 assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
79 json_out = JSON.parse out
80 links = json_out['items'].sort { |a,b| a['head_uuid'] <=> b['head_uuid'] }
81 assert_equal 3, links.length
82 assert_tag links[0], 'test_tag1', 'uuid1'
83 assert_tag links[1], 'test_tag1', 'uuid2'
84 assert_tag links[2], 'test_tag1', 'uuid3'
86 out, err = capture_subprocess_io do
87 assert arv_tag('remove', 'test_tag1',
94 out, err = capture_subprocess_io do
95 assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
104 system ['./bin/arv-tag', 'arv-tag'], *args
108 system ['./bin/arv', 'arv'], *args
111 def assert_tag(link, name, head_uuid)
112 assert_equal 'tag', link['link_class']
113 assert_equal name, link['name']
114 assert_equal head_uuid, link['head_uuid']