1 require 'minitest/autorun'
5 def assert_failure *args
6 assert_equal false, *args
9 class TestArvTag < Minitest::Test
12 skip "Waiting until #4534 is implemented"
14 # arv-tag exits with failure if run with no args
15 out, err = capture_subprocess_io do
16 assert_equal false, arv_tag
19 assert_match /^usage:/i, err
22 # Test adding and removing a single tag on a single object.
23 def test_single_tag_single_obj
27 tag_uuid, err = capture_subprocess_io do
28 assert arv_tag '--short', 'add', 'test_tag1', '--object', 'uuid1'
32 out, err = capture_subprocess_io do
33 assert arv 'link', 'show', '--uuid', tag_uuid.rstrip
38 assert_tag link, 'test_tag1', 'uuid1'
41 out, err = capture_subprocess_io do
42 assert arv_tag 'remove', 'test_tag1', '--object', 'uuid1'
46 links = JSON.parse out
47 assert_equal 1, links.length
48 assert_tag links[0], 'test_tag1', 'uuid1'
50 # Verify that the link no longer exists.
51 out, err = capture_subprocess_io do
52 assert_equal false, arv('link', 'show', '--uuid', links[0]['uuid'])
55 assert_equal "Error: Path not found\n", err
58 # Test adding and removing a single tag with multiple objects.
59 def test_single_tag_multi_objects
62 out, err = capture_subprocess_io do
63 assert arv_tag('add', 'test_tag1',
70 out, err = capture_subprocess_io do
71 assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
75 json_out = JSON.parse out
76 links = json_out['items'].sort { |a,b| a['head_uuid'] <=> b['head_uuid'] }
77 assert_equal 3, links.length
78 assert_tag links[0], 'test_tag1', 'uuid1'
79 assert_tag links[1], 'test_tag1', 'uuid2'
80 assert_tag links[2], 'test_tag1', 'uuid3'
82 out, err = capture_subprocess_io do
83 assert arv_tag('remove', 'test_tag1',
90 out, err = capture_subprocess_io do
91 assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
100 system ['./bin/arv-tag', 'arv-tag'], *args
104 system ['./bin/arv', 'arv'], *args
107 def assert_tag(link, name, head_uuid)
108 assert_equal 'tag', link['link_class']
109 assert_equal name, link['name']
110 assert_equal head_uuid, link['head_uuid']