8784: Fix test for latest firefox.
[arvados.git] / sdk / cli / test / test_arv-tag.rb
1 require 'minitest/autorun'
2 require 'digest/md5'
3 require 'json'
4
5 def assert_failure *args
6   assert_equal false, *args
7 end
8
9 class TestArvTag < Minitest::Test
10
11   def test_no_args
12     skip "Waiting until #4534 is implemented"
13
14     # arv-tag exits with failure if run with no args
15     out, err = capture_subprocess_io do
16       assert_equal false, arv_tag
17     end
18     assert_empty out
19     assert_match /^usage:/i, err
20   end
21
22   # Test adding and removing a single tag on a single object.
23   def test_single_tag_single_obj
24     skip "TBD"
25
26     # Add a single tag.
27     tag_uuid, err = capture_subprocess_io do
28       assert arv_tag '--short', 'add', 'test_tag1', '--object', 'uuid1'
29     end
30     assert_empty err
31
32     out, err = capture_subprocess_io do
33       assert arv 'link', 'show', '--uuid', tag_uuid.rstrip
34     end
35
36     assert_empty err
37     link = JSON.parse out
38     assert_tag link, 'test_tag1', 'uuid1'
39
40     # Remove the tag.
41     out, err = capture_subprocess_io do
42       assert arv_tag 'remove', 'test_tag1', '--object', 'uuid1'
43     end
44
45     assert_empty err
46     links = JSON.parse out
47     assert_equal 1, links.length
48     assert_tag links[0], 'test_tag1', 'uuid1'
49
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'])
53     end
54
55     assert_equal "Error: Path not found\n", err
56   end
57
58   # Test adding and removing a single tag with multiple objects.
59   def test_single_tag_multi_objects
60     skip "TBD"
61
62     out, err = capture_subprocess_io do
63       assert arv_tag('add', 'test_tag1',
64                      '--object', 'uuid1',
65                      '--object', 'uuid2',
66                      '--object', 'uuid3')
67     end
68     assert_empty err
69
70     out, err = capture_subprocess_io do
71       assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
72     end
73
74     assert_empty err
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'
81
82     out, err = capture_subprocess_io do
83       assert arv_tag('remove', 'test_tag1',
84                      '--object', 'uuid1',
85                      '--object', 'uuid2',
86                      '--object', 'uuid3')
87     end
88     assert_empty err
89
90     out, err = capture_subprocess_io do
91       assert arv 'link', 'list', '--where', '{"link_class":"tag","name":"test_tag1"}'
92     end
93
94     assert_empty err
95     assert_empty out
96   end
97
98   protected
99   def arv_tag(*args)
100     system ['./bin/arv-tag', 'arv-tag'], *args
101   end
102
103   def arv(*args)
104     system ['./bin/arv', 'arv'], *args
105   end
106
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']
111   end
112 end