Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add request_head option to http scout. Tests are somewhat sloppy, but…

… it works.
  • Loading branch information...
commit f55fe0bd911f350495774a15731d965f62e67980 1 parent c942764
@brain-geek brain-geek authored
Showing with 33 additions and 1 deletion.
  1. +6 −1 lib/outpost/scouts/http.rb
  2. +27 −0 test/outpost/scouts/http_test.rb
View
7 lib/outpost/scouts/http.rb
@@ -34,13 +34,18 @@ def setup(options)
@port = options[:port] || 80
@path = options[:path] || '/'
@http_class = options[:http_class] || Net::HTTP
+ @request_head = options.has_key?(:request_head) ? options[:request_head] : false
end
# Runs the scout, connecting to the host and getting the response code,
# body and time.
def execute
previous_time = Time.now
- response = @http_class.get_response(@host, @path, @port)
+ if @request_head
+ response = @http_class.request_head(@host, @path, @port)
+ else
+ response = @http_class.get_response(@host, @path, @port)
+ end
@response_time = (Time.now - previous_time) * 1000 # Miliseconds
@response_code = response.code.to_i
View
27 test/outpost/scouts/http_test.rb
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'ostruct'
describe Outpost::Scouts::Http do
class NetHttpStub
@@ -8,6 +9,22 @@ def response(&block); @response = block; end
def get_response(*args)
@response.call
end
+
+ def request_head(*args)
+ throw "Unexpected call"
+ end
+ end
+ end
+
+ class NetHttpHeadStub < NetHttpStub
+ class << self
+ def request_head(*args)
+ OpenStruct.new :code => 200, :body => 'Body'
+ end
+
+ def get_response(*args)
+ throw "Unexpected call"
+ end
end
end
@@ -47,6 +64,16 @@ def get_response(*args)
refute @subject.response_body
end
+ it "should make HEAD request if option is passed" do
+ config_stub = config_stub(:host => 'localhost', :http_class => NetHttpHeadStub, :request_head => true)
+ @subject = Outpost::Scouts::Http.new("description", config_stub)
+
+ @subject.run
+
+ assert_equal 200 , @subject.response_code
+ assert_equal 'Body', @subject.response_body
+ end
+
private
def config_stub(options={})

0 comments on commit f55fe0b

Please sign in to comment.
Something went wrong with that request. Please try again.