Class: Asserter::Url

Inherits:
Object
  • Object
show all
Defined in:
lib/depengine/asserter/url.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#check_hostObject

Returns the value of attribute check_host.



4
5
6
# File 'lib/depengine/asserter/url.rb', line 4

def check_host
  @check_host
end

#check_portObject

Returns the value of attribute check_port.



5
6
7
# File 'lib/depengine/asserter/url.rb', line 5

def check_port
  @check_port
end

#check_protocolObject

Returns the value of attribute check_protocol.



3
4
5
# File 'lib/depengine/asserter/url.rb', line 3

def check_protocol
  @check_protocol
end

#check_response_stringObject

Returns the value of attribute check_response_string.



7
8
9
# File 'lib/depengine/asserter/url.rb', line 7

def check_response_string
  @check_response_string
end

#check_uriObject

Returns the value of attribute check_uri.



6
7
8
# File 'lib/depengine/asserter/url.rb', line 6

def check_uri
  @check_uri
end

Instance Method Details

#assert_url_response_of(_options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/depengine/asserter/url.rb', line 9

def assert_url_response_of(_options = {})
  Helper.validates_presence_of check_protocol, 'check_protocol not set'
  Helper.validates_presence_of check_host, 'check_host not set'
  Helper.validates_presence_of check_port, 'check_port not set'
  Helper.validates_presence_of check_uri, 'check_uri not set'
  Helper.validates_presence_of check_response_string, 'check_response_string not set'

  check_url = "#{check_protocol}://#{check_host}:#{check_port}#{check_uri}"
  $log.writer.info "Checking URL = #{check_url} for \"#{check_response_string}\""

  # Net::HTTP.start(check_host, Integer(check_port)) do |http|
  port = Integer(check_port)
  Net::HTTP.start(check_host, port) do |http|
    request = Net::HTTP::Get.new check_uri
    response = http.request request # Net::HTTPResponse object
    $log.writer.debug "ResponseCode: #{response.code}"
    $log.writer.debug "ResponseMessage: #{response.message}"
    $log.writer.debug "ResponseBody: #{response.body}"
    unless response.code == '200'
      $log.writer.error "Got response code: #{response.code}"
      exit 1
    end
    unless response.body =~ Regexp.new(check_response_string)
      $log.writer.error "Expected: #{check_response_string}"
      $log.writer.error "Got: #{response.body}"
      exit 1
    end
  end
end