Sha256: 844206b6ca1059d28a5bccea3347067935b0f4eba7830e83bde66b8a05028821

Contents?: true

Size: 1.54 KB

Versions: 16

Compression:

Stored size: 1.54 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://hc-ping.com/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://hc-ping.com/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://hc-ping.com/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://hc-ping.com/foo").and_raise("fail")
    expect(BarsoomUtils::ExceptionNotifier).to receive(:message).with(anything, /foo/)

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
barsoom_utils-0.2.0.47 spec/ping_health_check_spec.rb
barsoom_utils-0.2.0.46 spec/ping_health_check_spec.rb
barsoom_utils-0.2.0.44 spec/ping_health_check_spec.rb
barsoom_utils-0.2.0.43 spec/ping_health_check_spec.rb
barsoom_utils-0.2.0.42 spec/ping_health_check_spec.rb
barsoom_utils-0.2.0.41 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.40 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.39 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.38 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.36 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.34 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.33 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.32 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.31 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.30 spec/ping_health_check_spec.rb
barsoom_utils-0.1.1.29 spec/ping_health_check_spec.rb