From 55cffa7ad05b7d4621d7c3c7db78f395aa92238c Mon Sep 17 00:00:00 2001 From: Sergio Rubio Date: Tue, 26 Feb 2013 17:16:55 +0100 Subject: [PATCH] [openstack|network] Added missing router related tests --- .../openstack/models/network/router_tests.rb | 38 ++++++++++ .../openstack/models/network/routers_tests.rb | 21 ++++++ .../requests/network/router_tests.rb | 75 +++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 tests/openstack/models/network/router_tests.rb create mode 100644 tests/openstack/models/network/routers_tests.rb create mode 100644 tests/openstack/requests/network/router_tests.rb diff --git a/tests/openstack/models/network/router_tests.rb b/tests/openstack/models/network/router_tests.rb new file mode 100644 index 000000000..faad48a76 --- /dev/null +++ b/tests/openstack/models/network/router_tests.rb @@ -0,0 +1,38 @@ +Shindo.tests("Fog::Network[:openstack] | router", ['openstack']) do + + tests('success') do + + tests('#create').succeeds do + @instance = Fog::Network[:openstack].routers.create( + :name => 'router_name', + :admin_state_up => true, + ) + !@instance.id.nil? + end + + tests('#update') do + test 'router name' do + @instance.name = 'new_name' + @instance.update.name == 'new_name' + end + # Needs code from issue #1598 + #test 'external_gateway_info' do + # net = Fog::Network[:openstack].networks.create( + # :name => 'net_name', + # :shared => false, + # :admin_state_up => true, + # :tenant_id => 'tenant_id', + # :router_external => true, + # ) + # @instance.external_gateway_info = net + # @instance.update + #end + end + + tests('#destroy').succeeds do + @instance.destroy == true + end + + end + +end diff --git a/tests/openstack/models/network/routers_tests.rb b/tests/openstack/models/network/routers_tests.rb new file mode 100644 index 000000000..9aca47d2c --- /dev/null +++ b/tests/openstack/models/network/routers_tests.rb @@ -0,0 +1,21 @@ +Shindo.tests("Fog::Network[:openstack] | routers", ['openstack']) do + @router = Fog::Network[:openstack].routers.create( + :name => 'router_name', + :admin_state_up => true, + ) + @routers = Fog::Network[:openstack].routers + + tests('success') do + + tests('#all').succeeds do + @routers.all + end + + tests('#get').succeeds do + @routers.get @router.id + end + + end + + @router.destroy +end diff --git a/tests/openstack/requests/network/router_tests.rb b/tests/openstack/requests/network/router_tests.rb new file mode 100644 index 000000000..a0df1a6e2 --- /dev/null +++ b/tests/openstack/requests/network/router_tests.rb @@ -0,0 +1,75 @@ +Shindo.tests('Fog::Network[:openstack] | router requests', ['openstack']) do + + @router_format = { + 'id' => String, + 'name' => String, + 'status' => String, + 'admin_state_up' => Fog::Boolean, + 'tenant_id' => String, + 'external_gateway_info' => Fog::Nullable::Hash, + } + + tests('success') do + tests('#create_router').formats({'router' => @router_format}) do + attributes = { + :admin_state_up => true, + :tenant_id => 'tenant_id' + } + Fog::Network[:openstack].create_router('router_name', attributes).body + end + + tests('#list_routers').formats({'routers' => [@router_format]}) do + Fog::Network[:openstack].list_routers.body + end + + tests('#get_router').formats({'router' => @router_format}) do + router_id = Fog::Network[:openstack].routers.all.first.id + Fog::Network[:openstack].get_router(router_id).body + end + + tests('#update_router').formats({'router' => @router_format}) do + router_id = Fog::Network[:openstack].routers.all.first.id + attributes = {} + { + :name => 'net_name', + :external_gateway_info => { :network_id => 'net_id' }, + :status => 'ACTIVE', + :admin_state_up => 'true' + } + Fog::Network[:openstack].update_router(router_id, attributes).body + end + + tests('#update_router_with_network').formats({'router' => @router_format}) do + router_id = Fog::Network[:openstack].routers.all.first.id + net = Fog::Network[:openstack].networks.first + attributes = {} + { + :name => 'net_name', + :external_gateway_info => net, + :status => 'ACTIVE', + :admin_state_up => 'true' + } + Fog::Network[:openstack].update_router(router_id, attributes).body + end + + tests('#delete_router').succeeds do + router_id = Fog::Network[:openstack].routers.all.last.id + Fog::Network[:openstack].delete_router(router_id) + end + end + + tests('failure') do + tests('#get_router').raises(Fog::Network::OpenStack::NotFound) do + Fog::Network[:openstack].get_router(0) + end + + tests('#update_router').raises(Fog::Network::OpenStack::NotFound) do + Fog::Network[:openstack].update_router(0, {}) + end + + tests('#delete_router').raises(Fog::Network::OpenStack::NotFound) do + Fog::Network[:openstack].delete_router(0) + end + end + +end