Sha256: 8175e917c4a5e65e68601de9720d63f9a03acbb7bbc50b91531a0218ee2694e6

Contents?: true

Size: 1.53 KB

Versions: 22

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true
require "barsoom_utils/ping_health_check"

RSpec.describe BarsoomUtils::PingHealthCheck, ".call" do
  around do |example|
    ENV["ENABLE_HEALTH_CHECKS"] = "true"
    example.run
    ENV["ENABLE_HEALTH_CHECKS"] = nil
  end

  it "does nothing on a 200 OK response" do
    expect(HTTParty).to receive(:get).with("https://hchk.io/foo").and_return(double(:response, code: 200, headers: {}))

    BarsoomUtils::PingHealthCheck.call("foo")
  end

  it "includes CloudFlare request ID header information in failure message" do
    expect(HTTParty).to receive(:get).with("https://hchk.io/foo").and_return(double(:response, code: 503, headers: { "cf-request-id" => "023aa754ae0000517ab8829200000001" }))
    expect(BarsoomUtils::ExceptionNotifier).to receive(:message).with(anything, /cf-request-id header: 023aa754ae0000517ab8829200000001/)

    BarsoomUtils::PingHealthCheck.call("foo")
  end

  it "silently reports an error to devs if it fails with a bad response code" do
    expect(HTTParty).to receive(:get).with("https://hchk.io/foo").and_return(double(:response, code: 404, headers: {}))
    expect(BarsoomUtils::ExceptionNotifier).to receive(:message).with(anything, /foo/)

    BarsoomUtils::PingHealthCheck.call("foo")
  end

  it "silently reports an error to devs if it fails with an exception" do
    expect(HTTParty).to receive(:get).with("https://hchk.io/foo").and_raise("fail")
    expect(BarsoomUtils::ExceptionNotifier).to receive(:message).with(anything, /foo/)

    BarsoomUtils::PingHealthCheck.call("foo")
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
barsoom_utils-0.1.1.8 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1 spec/ping_health_check_spec.rb