Skip to content

Commit

Permalink
spec fixes and tests for the new monitor functions
Browse files Browse the repository at this point in the history
  • Loading branch information
freeformz authored and Wesley Beary committed Feb 14, 2011
1 parent c937fe3 commit e2a755b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 25 deletions.
43 changes: 22 additions & 21 deletions lib/fog/vcloud/terremark/ecloud/requests/add_internet_service.rb
Expand Up @@ -41,6 +41,28 @@ def validate_internet_service_data(service_data, configure=false)
raise ArgumentError.new("Required Internet Service data missing: #{(required_opts - service_data.keys).map(&:inspect).join(", ")}")
end
end

def ensure_monitor_defaults!(monitor)
if monitor[:http_headers].is_a?(String)
monitor[:http_headers] = [ monitor[:http_headers] ]
end

unless monitor[:retries]
monitor[:retries] = 3
end

unless monitor[:response_timeout]
monitor[:response_timeout] = 2
end

unless monitor[:down_time]
monitor[:down_time] = 30
end

unless monitor[:interval]
monitor[:interval] = 5
end
end
end

class Real
Expand Down Expand Up @@ -97,27 +119,6 @@ def generate_monitor_section(builder, monitor)
}
end

def ensure_monitor_defaults!(monitor)
if monitor[:http_headers].is_a?(String)
monitor[:http_headers] = [ monitor[:http_headers] ]
end

unless monitor[:retries]
monitor[:retries] = 3
end

unless monitor[:response_timeout]
monitor[:response_timeout] = 2
end

unless monitor[:down_time]
monitor[:down_time] = 30
end

unless monitor[:interval]
monitor[:interval] = 5
end
end
end

class Mock
Expand Down
4 changes: 4 additions & 0 deletions spec/vcloud/spec_helper.rb
Expand Up @@ -30,6 +30,10 @@ def arrayify(item)
item.is_a?(Array) ? item : [ item ]
end

def ecloud_disabled_default_monitor
{:url_send_string=>nil, :receive_string=>nil, :response_timeout=>2, :retries=>3, :is_enabled=>"true", :down_time=>30, :type=>"Disabled", :http_headers=>nil, :interval=>5, :downtime=>nil}
end

shared_examples_for "all responses" do
it { should be_an_instance_of Excon::Response }
it { should respond_to :body }
Expand Down
23 changes: 19 additions & 4 deletions spec/vcloud/terremark/ecloud/models/internet_service_spec.rb
Expand Up @@ -76,11 +76,26 @@
end
end

context "with a disabled monitor" do
describe "disable monitoring via #monitor=" do
specify do
expect { subject.monitor = {:type => "Disabled", :is_enabled => "true" }; subject.save }.to change {subject.monitor}.from(nil).to(ecloud_disabled_default_monitor)
end

end

describe "disable monitoring via #disable_monitor" do
specify do
expect { subject.monitor = {:type => "Disabled", :is_enabled => "true" }; subject.save }.to
change {@mock_service[:monitor]}.from(nil).
to({:url_send_string=>nil, :http_headers=>nil, :receive_string=>nil, :interval=>nil, :is_enabled=>"true", :type=>"Disabled", :response_timeout=>nil, :downtime=>nil, :retries=>nil})
expect { subject.disable_monitor }.to change {subject.monitor}.from(nil).to(ecloud_disabled_default_monitor)
end
end

context "with a disabled monitor" do
before { subject.disable_monitor }

describe "enable ping monitoring via #enable_ping_monitor" do
specify do
expect { subject.enable_ping_monitor }.to change {subject.monitor}.from(ecloud_disabled_default_monitor).to(nil)
end
end
end
end
Expand Down

0 comments on commit e2a755b

Please sign in to comment.