From 977f6e3b8b6b7097e50f199d21fcc68aa74a30bb Mon Sep 17 00:00:00 2001 From: Paul Thornthwaite Date: Wed, 15 Aug 2012 12:01:56 +0100 Subject: [PATCH] [brightbox|compute] Updates to Test helper for select image * Extracted Image API lookup * Removed inline rescue --- tests/brightbox/requests/compute/helper.rb | 22 ++++++++++++++++++---- tests/compute/helper.rb | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/brightbox/requests/compute/helper.rb b/tests/brightbox/requests/compute/helper.rb index 63f5ce7bc..c23949eac 100644 --- a/tests/brightbox/requests/compute/helper.rb +++ b/tests/brightbox/requests/compute/helper.rb @@ -42,13 +42,20 @@ class Brightbox module TestSupport # Find a suitable image for testing with # For speed of server building we're using an empty image + # + # Unless the tester has credentials this will fail so we rescue + # any errors and return nil. + # + # This is used in the shared file +tests/compute/helper.rb+ so unfortunately + # makes all tests reliant on hardcoded values and each other + # + # @return [String,NilClass] the most suitable test image's identifier or nil def self.image_id return @image_id unless @image_id.nil? - images = Fog::Compute[:brightbox].list_images - raise "No available images!" if images.empty? - image = images.select {|img| img.size == 0 }.first - image = images.first if image.nil? + image = select_testing_image_from_api @image_id = image["id"] + rescue + @image_id = nil end # Prepare a test server, wait for it to be usable but raise if it fails @@ -62,6 +69,13 @@ class Brightbox server end + private + def self.select_testing_image_from_api + images = Fog::Compute[:brightbox].list_images + raise "No available images!" if images.empty? + images.select {|img| img.size == 0 }.first || images.first + end + end module Formats module Struct diff --git a/tests/compute/helper.rb b/tests/compute/helper.rb index ff812e36d..eec88af33 100644 --- a/tests/compute/helper.rb +++ b/tests/compute/helper.rb @@ -15,7 +15,7 @@ def compute_providers }, :brightbox => { :server_attributes => { - :image_id => (Brightbox::Compute::TestSupport.image_id rescue 'img-wwgbb') # Ubuntu Lucid 10.04 server (i686) + :image_id => Brightbox::Compute::TestSupport.image_id }, :mocked => false },