1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#!/usr/bin/ruby
# Test the secret methods the bindings support
$: << File.dirname(__FILE__)
require 'libvirt'
require 'test_utils.rb'
set_test_object("secret")
conn = Libvirt::open(URI)
# TESTGROUP: secret.uuid
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "uuid", 1)
expect_success(newsecret, "no args", "uuid") {|x| x == $SECRET_UUID}
newsecret.undefine
end
# TESTGROUP: secret.usagetype
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "usagetype", 1)
expect_success(newsecret, "no args", "usagetype") {|x| x == Libvirt::Secret::USAGE_TYPE_VOLUME}
newsecret.undefine
end
# TESTGROUP: secret.usageid
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "usageid", 1)
expect_success(newsecret, "no args", "usageid")
newsecret.undefine
end
# TESTGROUP: secret.xml_desc
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "xml_desc", 1, 2)
expect_invalid_arg_type(newsecret, "xml_desc", "foo")
expect_success(newsecret, "no args", "xml_desc")
newsecret.undefine
end
# TESTGROUP: secret.set_value
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "set_value", 1, 2, 3)
expect_too_few_args(newsecret, "set_value")
expect_invalid_arg_type(newsecret, "set_value", 1)
expect_invalid_arg_type(newsecret, "set_value", "foo", "bar")
expect_success(newsecret, "value arg", "set_value", "foo")
newsecret.undefine
end
# TESTGROUP: secret.value=
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "value=", 1, 2)
expect_too_few_args(newsecret, "value=")
expect_invalid_arg_type(newsecret, "value=", {})
expect_invalid_arg_type(newsecret, "value=", nil)
expect_invalid_arg_type(newsecret, "value=", 1)
expect_invalid_arg_type(newsecret, "value=", [1, 1])
expect_invalid_arg_type(newsecret, "value=", [nil, 1])
expect_invalid_arg_type(newsecret, "value=", [[], 1])
expect_invalid_arg_type(newsecret, "value=", [{}, 1])
expect_invalid_arg_type(newsecret, "value=", ['foo', nil])
expect_invalid_arg_type(newsecret, "value=", ['foo', 'foo'])
expect_invalid_arg_type(newsecret, "value=", ['foo', []])
expect_invalid_arg_type(newsecret, "value=", ['foo', {}])
expect_success(newsecret, "value arg", "value=", "foo")
newsecret.undefine
end
# TESTGROUP: secret.get_value
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
newsecret.set_value("foo")
expect_too_many_args(newsecret, "get_value", 1, 2)
expect_invalid_arg_type(newsecret, "get_value", 'foo')
expect_success(newsecret, "no args", "get_value") {|x| x == 'foo'}
newsecret.undefine
end
# TESTGROUP: secret.undefine
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
expect_too_many_args(newsecret, "undefine", 1)
expect_success(newsecret, "no args", "undefine")
end
# TESTGROUP: secret.free
if !test_default_uri?
newsecret = conn.define_secret_xml($new_secret_xml)
newsecret.undefine
expect_too_many_args(newsecret, "free", 1)
expect_success(newsecret, "no args", "free")
end
# END TESTS
conn.close
finish_tests
|