1 require 'minitest/autorun'
5 def assert_failure *args
6 assert_equal false, *args
9 class TestArvTag < Minitest::Test
12 # arv-tag exits with failure if run with no args
13 out, err = capture_subprocess_io do
14 assert_equal false, arv_tag
17 assert_match /^usage:/i, err
20 # Test adding and removing a single tag on a single object.
21 def test_single_tag_single_obj
23 tag_uuid, err = capture_subprocess_io do
24 assert arv_tag '--short', 'add', 'test_tag1', '--object', 'uuid1'
28 out, err = capture_subprocess_io do
29 assert arv 'link', 'show', '--uuid', tag_uuid.rstrip
34 assert_tag link, 'test_tag1', 'uuid1'
37 out, err = capture_subprocess_io do
38 assert arv_tag 'remove', 'test_tag1', '--object', 'uuid1'
42 links = JSON.parse out
43 assert_equal 1, links.length
44 assert_tag links[0], 'test_tag1', 'uuid1'
46 # Verify that the link no longer exists.
47 out, err = capture_subprocess_io do
48 assert_equal false, arv('link', 'show', '--uuid', links[0]['uuid'])
51 assert_equal "Error: Path not found\n", err
54 # Test adding and removing a single tag with multiple objects.
55 def test_single_tag_multi_objects
56 out, err = capture_subprocess_io do
57 assert arv_tag('add', 'test_tag1',
64 out, err = capture_subprocess_io do
65 assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
69 json_out = JSON.parse out
70 links = json_out['items'].sort { |a,b| a['head_uuid'] <=> b['head_uuid'] }
71 assert_equal 3, links.length
72 assert_tag links[0], 'test_tag1', 'uuid1'
73 assert_tag links[1], 'test_tag1', 'uuid2'
74 assert_tag links[2], 'test_tag1', 'uuid3'
76 out, err = capture_subprocess_io do
77 assert arv_tag('remove', 'test_tag1',
84 out, err = capture_subprocess_io do
85 assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
94 system ['./bin/arv-tag', 'arv-tag'], *args
98 system ['./bin/arv', 'arv'], *args
101 def assert_tag(link, name, head_uuid)
102 assert_equal 'tag', link['link_class']
103 assert_equal name, link['name']
104 assert_equal head_uuid, link['head_uuid']