From f0a09d2fd367b8d2d5242bd9f2882bc02acc84b8 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Fri, 9 Nov 2012 13:51:58 -0500 Subject: [PATCH] Adds some more ChefSpec tests to cover Openstack::endpoints --- libraries/default.rb | 2 ++ spec/default_spec.rb | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libraries/default.rb b/libraries/default.rb index cf4ad98e..d3743c80 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -44,5 +44,7 @@ module Openstack @node['openstack']['endpoints'].each do | name, info | block.call(name, info) end + rescue + nil end end diff --git a/spec/default_spec.rb b/spec/default_spec.rb index 804e3704..47402ba5 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -74,4 +74,26 @@ describe ::Openstack do @subject.endpoint_uri("compute-api").should eq "http://localhost" end end + describe "#endpoints" do + it "does nothing when no endpoints" do + @subject.instance_variable_set(:@node, {}) + @subject.endpoints.should be_nil + end + it "does nothing when empty endpoints" do + @subject.instance_variable_set(:@node, {"openstack" => { "endpoints" => {}}}) + @count = 0 + @subject.endpoints do | ep | + @count += 1 + end + @count.should eq 0 + end + it "executes block count when have endpoints" do + @subject.instance_variable_set(:@node, @chef_run.node) + @count = 0 + @subject.endpoints do | ep | + @count += 1 + end + @count.should >= 1 + end + end end