Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
- 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:
ruby-version:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
- head
gemfile-path:
- Gemfile
- gemfiles/faraday_0.gemfile
- gemfiles/faraday_1.gemfile
- gemfiles/faraday_2.gemfile
env:
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile-path }}
steps:
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run tests
run: bin/test

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/freno/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion lib/freno/client/errors.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

module Freno
Error = Class.new(StandardError)
class Error < StandardError
end
end
3 changes: 2 additions & 1 deletion lib/freno/client/preconditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ class Client
module Preconditions
module_function

PreconditionNotMet = Class.new(ArgumentError)
class PreconditionNotMet < ArgumentError
end

class Checker
attr_reader :errors
Expand Down
5 changes: 3 additions & 2 deletions lib/freno/client/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions test/freno/client/requests/check_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading