From 06ba10e822648ed2c861179e71ba4a54c20cdb4f Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Mon, 25 Mar 2013 16:05:38 -0400 Subject: [PATCH] [hp|network] Add tests for request methods of subnets. --- tests/hp/requests/network/network_tests.rb | 2 +- tests/hp/requests/network/subnet_tests.rb | 71 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/hp/requests/network/subnet_tests.rb diff --git a/tests/hp/requests/network/network_tests.rb b/tests/hp/requests/network/network_tests.rb index d76b9d4b7..4ea158d9d 100644 --- a/tests/hp/requests/network/network_tests.rb +++ b/tests/hp/requests/network/network_tests.rb @@ -2,7 +2,7 @@ Shindo.tests("HP::Network | network requests", ['hp', 'network']) do @network_format = { 'id' => String, - 'name' => String, + 'name' => Fog::Nullable::String, 'tenant_id' => String, 'status' => String, 'subnets' => Array, diff --git a/tests/hp/requests/network/subnet_tests.rb b/tests/hp/requests/network/subnet_tests.rb new file mode 100644 index 000000000..15c6ccead --- /dev/null +++ b/tests/hp/requests/network/subnet_tests.rb @@ -0,0 +1,71 @@ +Shindo.tests("HP::Network | subnet requests", ['hp', 'subnet']) do + + @subnet_format = { + 'id' => String, + 'name' => Fog::Nullable::String, + 'network_id' => String, + 'cidr' => String, + 'ip_version' => Integer, + 'gateway_ip' => Fog::Nullable::String, + 'allocation_pools' => Fog::Nullable::Array, + 'dns_nameservers' => Fog::Nullable::Array, + 'host_routes' => Fog::Nullable::Array, + 'enable_dhcp' => Fog::Boolean, + 'tenant_id' => String, + } + + n_data = HP[:network].create_network({:name => 'fog_network'}).body['network'] + @network_id = n_data['id'] + + tests('success') do + + @subnet_id = nil + + tests('#create_subnet').formats(@subnet_format) do + attributes = {:name => 'mysubnet', :gateway_ip => '10.0.3.1', + :allocation_pools => [], :dns_nameservers => [], + :host_routes => [], :enable_dhcp => true} + data = HP[:network].create_subnet(@network_id, '10.0.3.0/24', 4, attributes).body['subnet'] + @subnet_id = data['id'] + data + end + + tests('#list_subnets').formats({'subnets' => [@subnet_format]}) do + HP[:network].list_subnets.body + end + + tests("#get_subnet(#{@subnet_id})").formats({'subnet' => @subnet_format}) do + HP[:network].get_subnet(@subnet_id).body + end + + tests("#update_subnet(#{@subnet_id})").formats({'subnet' => @subnet_format}) do + attributes = {:name => 'mysubnet_upd',:gateway_ip => '10.0.3.1', + :dns_nameservers => [], :host_routes => [], + :enable_dhcp => true} + HP[:network].update_subnet(@subnet_id, attributes).body + end + + tests("#delete_subnet(#{@subnet_id})").succeeds do + HP[:network].delete_subnet(@subnet_id) + end + + end + + tests('failure') do + tests('#get_subnet(0)').raises(Fog::HP::Network::NotFound) do + HP[:network].get_subnet(0) + end + + tests('#update_subnet(0)').raises(Fog::HP::Network::NotFound) do + HP[:network].update_subnet(0, {}) + end + + tests('#delete_subnet(0)').raises(Fog::HP::Network::NotFound) do + HP[:network].delete_subnet(0) + end + end + + # cleanup + HP[:network].delete_network(@network_id) + +end \ No newline at end of file