Sha256: 0ab2cf9ef3122ab81f8f47325342ccb9ef36eefff4e18152bd4f67772f3b309a

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

module  Asserter
  class Url
    attr_accessor :check_protocol
    attr_accessor :check_host
    attr_accessor :check_port
    attr_accessor :check_uri
    attr_accessor :check_response_string

    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
depengine-3.0.23 lib/depengine/asserter/url.rb
depengine-3.0.22 lib/depengine/asserter/url.rb
depengine-3.0.21 lib/depengine/asserter/url.rb