diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index a23112d..7ca7ce7 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -8,7 +8,9 @@ on: - main jobs: test: - runs-on: ubuntu-latest + # Ruby 3.0 and 3.1 builds aren't available for Ubuntu 26.04, which + # ubuntu-latest now points to. + runs-on: ubuntu-24.04 strategy: fail-fast: false matrix: diff --git a/CHANGELOG.md b/CHANGELOG.md index 23db9a1..f439c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- `headers` request option to send custom HTTP headers with a check + ## [0.9.0] - 2024-04-18 ### Added diff --git a/lib/freno/client.rb b/lib/freno/client.rb index 36505e1..4674bb5 100644 --- a/lib/freno/client.rb +++ b/lib/freno/client.rb @@ -233,7 +233,7 @@ def decorated(request) outermost = to_decorate[0] current = outermost - (to_decorate[1..]).each do |decorator| + to_decorate[1..].each do |decorator| current.request = decorator current = current.request end diff --git a/lib/freno/client/errors.rb b/lib/freno/client/errors.rb index afbb591..fbbb7a1 100644 --- a/lib/freno/client/errors.rb +++ b/lib/freno/client/errors.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true module Freno - Error = Class.new(StandardError) + class Error < StandardError + end end diff --git a/lib/freno/client/preconditions.rb b/lib/freno/client/preconditions.rb index a49174b..2c5ed55 100644 --- a/lib/freno/client/preconditions.rb +++ b/lib/freno/client/preconditions.rb @@ -5,7 +5,8 @@ class Client module Preconditions module_function - PreconditionNotMet = Class.new(ArgumentError) + class PreconditionNotMet < ArgumentError + end class Checker attr_reader :errors diff --git a/lib/freno/client/request.rb b/lib/freno/client/request.rb index 2b36935..53e84e0 100644 --- a/lib/freno/client/request.rb +++ b/lib/freno/client/request.rb @@ -9,7 +9,7 @@ class Client class Request include Freno::Client::Preconditions - attr_reader :faraday, :args, :options, :raise_on_timeout + attr_reader :faraday, :args, :options, :raise_on_timeout, :headers def self.perform(**kwargs) new(**kwargs).perform @@ -22,6 +22,7 @@ def initialize(**kwargs) @raise_on_timeout = options.fetch(:raise_on_timeout, true) @verb = options.fetch(:verb, :head) + @headers = options.fetch(:headers, nil) end def perform @@ -38,7 +39,7 @@ def perform protected def request(verb, path, params) - faraday.send(verb, path, params) + faraday.send(verb, path, params, headers) end def path diff --git a/test/freno/client/requests/check_test.rb b/test/freno/client/requests/check_test.rb index 931e664..4c1c371 100644 --- a/test/freno/client/requests/check_test.rb +++ b/test/freno/client/requests/check_test.rb @@ -79,4 +79,25 @@ def test_perform_calls_the_proper_service_endpoint_with_low_priority_and_succeed assert_equal 200, response.code assert_equal({ "StatusCode" => 200, "Value" => 0.025075, "Threshold" => 1, "Message" => "" }, response.body) end + + def test_perform_sends_custom_headers + faraday = stubbed_faraday do |stub| + stub.head("/check/github/mysql/main") do |env| + assert_equal "1", env.request_headers["X-Example"] + [200, {}, <<-BODY] + {"StatusCode":200, "Value":0.025075, "Threshold":1, "Message":""} + BODY + end + end + + request = Check.new( + faraday: faraday, + app: "github", + store_type: "mysql", + store_name: "main", + options: { headers: { "X-Example" => "1" } } + ) + + assert_equal :ok, request.perform.meaning + end end