1 require 'minitest/autorun'
5 # Black box tests for 'arv get' command.
6 class TestArvGet < Minitest::Test
7 # UUID for an Arvados object that does not exist
8 NON_EXISTANT_OBJECT_UUID = "qr1hi-tpzed-p8yk1lihjsgwew0"
10 # Tests that a valid Arvados object can be retrieved in JSON format using:
11 # `arv get [uuid] --format json`.
12 def test_get_valid_object_json_format()
13 stored_value = __method__
14 uuid = create_arv_object_with_value(stored_value)
15 out, err = capture_subprocess_io do
16 arv_get(uuid, '--format', 'json')
19 assert(does_arv_object_as_json_use_value(out, stored_value))
22 # Tests that a valid Arvados object can be retrieved in YAML format using:
23 # `arv get [uuid] --format yaml`.
24 def test_get_valid_object_yaml_format()
25 stored_value = __method__
26 uuid = create_arv_object_with_value(stored_value)
27 out, err = capture_subprocess_io do
28 arv_get(uuid, '--format', 'yaml')
31 assert(does_arv_object_as_yaml_use_value(out, stored_value))
34 # Tests that a valid Arvados object can be retrieved in a supported format
35 # using: `arv get [uuid]`.
36 def test_get_valid_object_no_format()
37 stored_value = __method__
38 uuid = create_arv_object_with_value(stored_value)
39 out, err = capture_subprocess_io do
43 assert(does_arv_object_as_yaml_use_value(out, stored_value) ||
44 does_arv_object_as_json_use_value(out, stored_value))
47 # TODO: Add tests for selecting specific fields
48 def test_get_valid_object_with_specific_valid_fields()
52 # TODO: Add tests for selecting specific fields
53 def test_get_valid_object_with_both_specific_valid_and_invalid_fields()
57 # Tests that an valid Arvados object is not retrieved when specifying an
58 # invalid format: `arv get [uuid] --format invalid`.
59 def test_get_object_invalid_format()
60 stored_value = __method__
61 uuid = create_arv_object_with_value(stored_value)
62 out, err = capture_subprocess_io do
63 arv_get(uuid, '--format', 'invalid')
69 # Tests that an invalid (non-existant) Arvados object is not retrieved using:
70 # using: `arv get [non-existant-uuid] --format json`.
71 def test_get_invalid_object_json_format()
72 out, err = capture_subprocess_io do
73 arv_get(NON_EXISTANT_OBJECT_UUID, '--format', 'json')
79 # Tests that an invalid (non-existant) Arvados object is not retrieved using:
80 # using: `arv get [non-existant-uuid] --format yaml`.
81 def test_get_invalid_object_yaml_format()
82 out, err = capture_subprocess_io do
83 arv_get(NON_EXISTANT_OBJECT_UUID, '--format', 'yaml')
89 # Tests that an invalid (non-existant) Arvados object is not retrieved using:
90 # using: `arv get [non-existant-uuid]`.
91 def test_get_invalid_object_no_format()
92 out, err = capture_subprocess_io do
93 arv_get(NON_EXISTANT_OBJECT_UUID)
99 # Tests that an invalid (non-existant) Arvados object is not retrieved when
100 # specifying an invalid format:
101 # `arv get [non-existant-uuid] --format invalid`.
102 def test_get_object_invalid_format()
103 out, err = capture_subprocess_io do
104 arv_get(NON_EXISTANT_OBJECT_UUID, '--format', 'invalid')
110 # TODO: Test what happens when valid object but invalid fields
111 def test_get_valid_object_with_specific_invalid_fields()
116 # Runs 'arv get <varargs>' with given arguments.
118 system(['./bin/arv', 'arv get'], *args)
121 # Creates an Arvados object that stores a given value. Returns the uuid of the
123 def create_arv_object_with_value(value)
124 out, err = capture_subprocess_io do
125 # Write (without redirect)
126 system(['./bin/arv', "arv tag add #{value} --object testing"])
129 raise "Could not create Arvados object with given value"
134 # Checks whether the Arvados object, represented in JSON format, uses the
136 def does_arv_object_as_json_use_value(obj, value)
138 parsed = JSON.parse(obj)
139 return does_arv_object_as_ruby_object_use_value(parsed, value)
140 rescue JSON::ParserError => e
141 raise "Invalid JSON representation of Arvados object"
145 # Checks whether the Arvados object, represented in YAML format, uses the
147 def does_arv_object_as_yaml_use_value(obj, value)
149 parsed = YAML.load(obj)
150 return does_arv_object_as_ruby_object_use_value(parsed, value)
152 raise "Invalid YAML representation of Arvados object"
156 # Checks whether the Arvados object, represented as a Ruby object, uses the
158 def does_arv_object_as_ruby_object_use_value(obj, value)
159 assert(parsed.instance_of?(Hash))
160 stored_value = obj["name"]
161 return (value == stored_value)