From f9c289a95bc7ec0f0bfac78ae943ca2a53ea7f4a Mon Sep 17 00:00:00 2001 From: Rupak Ganguly Date: Wed, 4 Apr 2012 19:36:30 -0400 Subject: [PATCH] Add tests for images. --- tests/hp/requests/compute/image_tests.rb | 75 ++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/hp/requests/compute/image_tests.rb diff --git a/tests/hp/requests/compute/image_tests.rb b/tests/hp/requests/compute/image_tests.rb new file mode 100644 index 000000000..a80fd97cb --- /dev/null +++ b/tests/hp/requests/compute/image_tests.rb @@ -0,0 +1,75 @@ +Shindo.tests('Fog::Compute[:hp] | image requests', ['hp']) do + + @image_format = { + 'id' => String, + 'links' => Array, + 'metadata' => Fog::Nullable::Hash, + 'name' => String, + 'progress' => Fog::Nullable::Integer, + 'status' => String, + 'created' => Fog::Nullable::String, + 'updated' => Fog::Nullable::String + } + + @list_images_format = { + 'id' => String, + 'name' => String + } + + tests('success') do + @server_name = "fogservertest" + @image_name = "fogimagetest" + @server = Fog::Compute[:hp].servers.create(:name => @server_name, :flavor_id => 100, :image_id => 1242) + @server.wait_for { ready? } + @image_id = nil + + tests("#create_image(#{@server.id}, #{@image_name})").formats({}) do + response = Fog::Compute[:hp].create_image(@server.id, @image_name) + # no data is returned for the call, so get id off the header + @image_id = response.headers["Location"].split("/")[5] + {} + end + + unless Fog.mocking? + Fog::Compute[:hp].images.get(@image_id).wait_for { ready? } + end + + tests("#get_image_details(#{@image_id})").formats(@image_format) do + pending if Fog.mocking? + Fog::Compute[:hp].get_image_details(@image_id).body['image'] + end + + tests('#list_images').formats({'images' => [@list_images_format]}) do + Fog::Compute[:hp].list_images.body + end + + tests('#list_images_detail').formats({'images' => [@image_format]}) do + Fog::Compute[:hp].list_images_detail.body + end + + unless Fog.mocking? + Fog::Compute[:hp].images.get(@image_id).wait_for { ready? } + end + + tests("#delete_image(#{@image_id})").succeeds do + pending if Fog.mocking? + Fog::Compute[:hp].delete_image(@image_id) + end + + @server.destroy + + end + + tests('failure') do + + tests('#delete_image(0)').raises(Excon::Errors::BadRequest) do + Fog::Compute[:hp].delete_image(0) + end + + tests('#get_image_details(0)').raises(Fog::Compute::HP::NotFound) do + Fog::Compute[:hp].get_image_details(0) + end + + end + +end