This allows us to run tests with the destdriver like: RUBY_LIBVIRT_TEST_URI=test:///default \ RUBYLIB=lib/:ext/libvirt/ \ ruby tests/test_open.rb --- I've only converted three modules so far since they were simple but these already help to run tests during package build. tests/test_nodedevice.rb | 2 +- tests/test_open.rb | 36 ++++++++++++++++++------------------ tests/test_stream.rb | 2 +- tests/test_utils.rb | 2 ++ 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/tests/test_nodedevice.rb b/tests/test_nodedevice.rb index 7da1a5f..50a1304 100644 --- a/tests/test_nodedevice.rb +++ b/tests/test_nodedevice.rb @@ -9,7 +9,7 @@ require 'test_utils.rb' set_test_object("nodedevice") -conn = Libvirt::open("qemu:///system") +conn = Libvirt::open(URI) # TESTGROUP: nodedevice.name testnode = conn.lookup_nodedevice_by_name(conn.list_nodedevices[0]) diff --git a/tests/test_open.rb b/tests/test_open.rb index 17baa93..c67eaab 100644 --- a/tests/test_open.rb +++ b/tests/test_open.rb @@ -21,49 +21,49 @@ expect_success(Libvirt, "nil arg", "version", nil) {|x| x.class == Array and x.l expect_success(Libvirt, "Test arg", "version", "Test") {|x| x.class == Array and x.length == 2} # TESTGROUP: Libvirt::open -expect_too_many_args(Libvirt, "open", "qemu:///system", 1) +expect_too_many_args(Libvirt, "open", URI, 1) expect_connect_error("open", "foo:///system") conn = expect_success(Libvirt, "no args", "open") {|x| x.class == Libvirt::Connect } conn.close -conn = expect_success(Libvirt, "qemu:///system", "open", "qemu:///system") {|x| x.class == Libvirt::Connect } +conn = expect_success(Libvirt, URI, "open", URI) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "nil arg", "open", nil) {|x| x.class == Libvirt::Connect } conn.close # TESTGROUP: Libvirt::open_read_only -expect_too_many_args(Libvirt, "open_read_only", "qemu:///system", 1) +expect_too_many_args(Libvirt, "open_read_only", URI, 1) expect_connect_error("open_read_only", "foo:///system") conn = expect_success(Libvirt, "no args", "open_read_only") {|x| x.class == Libvirt::Connect } conn.close -conn = expect_success(Libvirt, "qemu:///system", "open_read_only", "qemu:///system") {|x| x.class == Libvirt::Connect } +conn = expect_success(Libvirt, URI, "open_read_only", URI) {|x| x.class == Libvirt::Connect } conn.close conn = expect_success(Libvirt, "nil arg", "open_read_only", nil) {|x| x.class == Libvirt::Connect } conn.close # TESTGROUP: Libvirt::open_auth -expect_too_many_args(Libvirt, "open_auth", "qemu:///system", [], "hello there", 1, 2) +expect_too_many_args(Libvirt, "open_auth", URI, [], "hello there", 1, 2) expect_connect_error("open_auth", "foo:///system") expect_invalid_arg_type(Libvirt, "open_auth", 1) -expect_invalid_arg_type(Libvirt, "open_auth", "qemu:///system", [], "hello", "foo") +expect_invalid_arg_type(Libvirt, "open_auth", URI, [], "hello", "foo") conn = expect_success(Libvirt, "no args", "open_auth") {|x| x.class == Libvirt::Connect } conn.close -conn = expect_success(Libvirt, "uri arg", "open_auth", "qemu:///system") {|x| x.class == Libvirt::Connect } +conn = expect_success(Libvirt, "uri arg", "open_auth", URI) {|x| x.class == Libvirt::Connect } conn.close -conn = expect_success(Libvirt, "uri and empty cred args", "open_auth", "qemu:///system", []) {|x| x.class == Libvirt::Connect } +conn = expect_success(Libvirt, "uri and empty cred args", "open_auth", URI, []) {|x| x.class == Libvirt::Connect } conn.close -conn = expect_success(Libvirt, "uri and full cred args", "open_auth", "qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) {|x| x.class == Libvirt::Connect } +conn = expect_success(Libvirt, "uri and full cred args", "open_auth", URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE]) {|x| x.class == Libvirt::Connect } conn.close -conn = expect_success(Libvirt, "uri, full cred, and user args", "open_auth", "qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") {|x| x.class == Libvirt::Connect } +conn = expect_success(Libvirt, "uri, full cred, and user args", "open_auth", URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") {|x| x.class == Libvirt::Connect } conn.close # equivalent to expect_invalid_arg_type begin - conn = Libvirt::open_auth("qemu:///system", {}) do |cred| + conn = Libvirt::open_auth(URI, {}) do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" @@ -73,7 +73,7 @@ end # equivalent to expect_invalid_arg_type begin - conn = Libvirt::open_auth("qemu:///system", 1) do |cred| + conn = Libvirt::open_auth(URI, 1) do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" @@ -83,7 +83,7 @@ end # equivalent to expect_invalid_arg_type begin - conn = Libvirt::open_auth("qemu:///system", 'foo') do |cred| + conn = Libvirt::open_auth(URI, 'foo') do |cred| end rescue TypeError => e puts_ok "#{$test_object}.open_auth invalid arg type threw #{TypeError.to_s}" @@ -93,7 +93,7 @@ end # equivalent to "expect_success" begin - conn = Libvirt::open_auth("qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") do |cred| + conn = Libvirt::open_auth(URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello") do |cred| if not cred["userdata"].nil? puts "userdata is #{cred["userdata"]}" end @@ -122,7 +122,7 @@ end # equivalent to "expect_success" begin - conn = Libvirt::open_auth("qemu:///system") do |cred| + conn = Libvirt::open_auth(URI) do |cred| end puts_ok "Libvirt.open_auth uri, succeeded" @@ -135,7 +135,7 @@ end # equivalent to "expect_success" begin - conn = Libvirt::open_auth("qemu:///system", [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello", Libvirt::CONNECT_RO) do |cred| + conn = Libvirt::open_auth(URI, [Libvirt::CRED_AUTHNAME, Libvirt::CRED_PASSPHRASE], "hello", Libvirt::CONNECT_RO) do |cred| if not cred["userdata"].nil? puts "userdata is #{cred["userdata"]}" end @@ -163,7 +163,7 @@ rescue => e end # TESTGROUP: Libvirt::event_invoke_handle_callback -conn = Libvirt::open("qemu:///system") +conn = Libvirt::open(URI) expect_too_many_args(Libvirt, "event_invoke_handle_callback", 1, 2, 3, 4, 5) expect_too_few_args(Libvirt, "event_invoke_handle_callback") @@ -188,7 +188,7 @@ expect_invalid_arg_type(Libvirt, "event_invoke_handle_callback", 1, 1, 1, { "lib conn.close # TESTGROUP: Libvirt::event_invoke_timeout_callback -conn = Libvirt::open("qemu:///system") +conn = Libvirt::open(URI) expect_too_many_args(Libvirt, "event_invoke_timeout_callback", 1, 2, 3) expect_too_few_args(Libvirt, "event_invoke_timeout_callback") diff --git a/tests/test_stream.rb b/tests/test_stream.rb index 07ec222..e272104 100644 --- a/tests/test_stream.rb +++ b/tests/test_stream.rb @@ -9,7 +9,7 @@ require 'test_utils.rb' set_test_object("stream") -conn = Libvirt::open("qemu:///system") +conn = Libvirt::open(URI) # TESTGROUP: stream.send st = conn.stream diff --git a/tests/test_utils.rb b/tests/test_utils.rb index 1bac1cc..519de27 100644 --- a/tests/test_utils.rb +++ b/tests/test_utils.rb @@ -2,6 +2,8 @@ $FAIL = 0 $SUCCESS = 0 $SKIPPED = 0 +URI = ENV['RUBY_LIBVIRT_TEST_URI'] || "qemu:///system" + $GUEST_BASE = '/var/lib/libvirt/images/ruby-libvirt-tester' $GUEST_DISK = $GUEST_BASE + '.qcow2' $GUEST_SAVE = $GUEST_BASE + '.save' -- 1.8.5.2 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list