On 01/06/2012 03:39 PM, mtaylor@redhat.com wrote:
From: Martyn Taylor <mtaylor@redhat.com>

---
 lib/aeolus_cli/command/delete_command.rb           |   37 +++++++++--------
 spec/command/delete_command_spec.rb                |   14 +++++++
 .../delete_image_no_provider_content.yml           |   42 ++++++++++++++++++++
 3 files changed, 75 insertions(+), 18 deletions(-)
 create mode 100644 spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml

diff --git a/lib/aeolus_cli/command/delete_command.rb b/lib/aeolus_cli/command/delete_command.rb
index 54de83f..1fb12f2 100644
--- a/lib/aeolus_cli/command/delete_command.rb
+++ b/lib/aeolus_cli/command/delete_command.rb
@@ -78,28 +78,29 @@ module Aeolus
       private
       def print_provider_content(content_xml)
         h = Hash.from_xml(content_xml)
-        provider_content = h[h.keys.first]["content"]["provider_content"]
+        if provider_content = h[h.keys.first]["content"]["provider_content"]
         content = provider_content.instance_of?(Array) ? provider_content : [provider_content]
-        if content.size > 0
-          widths = calculate_widths(content)
-          puts "N.B. The following provider content must be manually removed"
-          puts ""
-
-          # Print Headers
-          printf("%-#{widths[:provider] + 5}s", "Provider")
-          printf("%-#{widths[:id] + 5}s", "ID")
-          puts ""
+          if content.size > 0
+            widths = calculate_widths(content)
+            puts "N.B. The following provider content must be manually removed"
+            puts ""
 
-          # Print Column Lines
-          printf("%-#{widths[:provider] + 5}s", "-" * widths[:provider])
-          printf("%-#{widths[:id] + 5}s", "-" * widths[:id])
-          puts ""
+            # Print Headers
+            printf("%-#{widths[:provider] + 5}s", "Provider")
+            printf("%-#{widths[:id] + 5}s", "ID")
+            puts ""
 
-          # Print Content
-          content.each do |pc|
-            printf("%-#{widths[:provider] + 5}s", pc["provider"])
-            printf("%-#{widths[:id] + 5}s", pc["target_identifier"])
+            # Print Column Lines
+            printf("%-#{widths[:provider] + 5}s", "-" * widths[:provider])
+            printf("%-#{widths[:id] + 5}s", "-" * widths[:id])
             puts ""
+
+            # Print Content
+            content.each do |pc|
+              printf("%-#{widths[:provider] + 5}s", pc["provider"])
+              printf("%-#{widths[:id] + 5}s", pc["target_identifier"])
+              puts ""
+            end
           end
         end
       end
diff --git a/spec/command/delete_command_spec.rb b/spec/command/delete_command_spec.rb
index 7325161..6bafd1d 100644
--- a/spec/command/delete_command_spec.rb
+++ b/spec/command/delete_command_spec.rb
@@ -125,6 +125,20 @@ module Aeolus
             $stdout.string.should include("Could not find ProviderImage 1234")
           end
         end
+
+        it "should not throw an error on delete when no provider content is found" do
+          VCR.use_cassette('command/delete_command/delete_image_no_provider_content') do
+            @options = {:image => "5f32b61f-1aad-495e-8ad7-45783ee802c5"}
+            dc = DeleteCommand.new(@options)
+            begin
+              dc.image
+            rescue SystemExit => e
+              e.status.should == 0
+            end
This is not the way how to test exit status with rspec. Correct way should be something like
it "should exit cleanly" do
  lambda { dc.image }.should exit_with_code(0)
end
that is much cleaner way.
+            $stdout.string.should include("Image: 5f32b61f-1aad-495e-8ad7-45783ee802c5 Deleted Successfully")
+            $stdout.string.should_not include("ERROR")
+          end
+        end
       end
     end
   end
diff --git a/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml b/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
new file mode 100644
index 0000000..e099845
--- /dev/null
+++ b/spec/vcr/cassettes/command/delete_command/delete_image_no_provider_content.yml
@@ -0,0 +1,42 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+  request: !ruby/struct:VCR::Request
+    method: :delete
+    uri: https://admin:password@localhost:443/conductor/api/images/5f32b61f-1aad-495e-8ad7-45783ee802c5.xml
+    body:
+    headers:
+      accept-language:
+      - en
+      accept:
+      - application/xml
+  response: !ruby/struct:VCR::Response
+    status: !ruby/struct:VCR::ResponseStatus
+      code: 200
+      message: OK
+    headers:
+      x-ua-compatible:
+      - IE=Edge,chrome=1
+      etag:
+      - "\"b7717357bc6e7bb39051de814ee273d4\""
+      content-type:
+      - application/xml; charset=utf-8
+      server:
+      - thin 1.2.11 codename Bat-Shit Crazy
+      date:
+      - Fri, 06 Jan 2012 14:36:45 GMT
+      x-runtime:
+      - "0.329900"
+      set-cookie:
+      - _session_id=BAh7CCIPc2Vzc2lvbl9pZCIlZmZhMmU0N2Y5Y2ZlMmI4YzFjN2VjZDhkN2NhMmI3ZjMiGXdhcmRlbi51c2VyLnVzZXIua2V5aQYiEGJyZWFkY3J1bWJzWwA%3D--f3390c131bb0b6f28873e1ad8d8197f8414accee; path=/; HttpOnly
+      cache-control:
+      - max-age=0, private, must-revalidate
+      transfer-encoding:
+      - chunked
+    body: |
+      <image href='https://localhost/conductor/api/images/5f32b61f-1aad-495e-8ad7-45783ee802c5' id='5f32b61f-1aad-495e-8ad7-45783ee802c5'>
+      <status>DELETED</status>
+      <content>
+      </content>
+      </image>
+
+    http_version: "1.1"
\ No newline at end of file
ACK. one nit inline