Skip to content

Commit

Permalink
feat: add support for PACT_BROKER_WEBHOOK_RETRY_SCHEDULE environment …
Browse files Browse the repository at this point in the history
…variable
  • Loading branch information
pitschr authored Feb 1, 2021
1 parent 16db095 commit 536a61b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
1 change: 1 addition & 0 deletions pact_broker/config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ app = PactBroker::App.new do | config |
config.webhook_host_whitelist = dc.webhook_host_whitelist
config.webhook_http_method_whitelist = dc.webhook_http_method_whitelist
config.webhook_scheme_whitelist = dc.webhook_scheme_whitelist
config.webhook_retry_schedule = dc.webhook_retry_schedule
config.base_equality_only_on_content_that_affects_verification_results = dc.base_equality_only_on_content_that_affects_verification_results
config.order_versions_by_date = dc.order_versions_by_date
config.disable_ssl_verification = dc.disable_ssl_verification
Expand Down
34 changes: 34 additions & 0 deletions pact_broker/docker_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def webhook_http_method_whitelist
space_delimited_string_list_or_default(:webhook_http_method_whitelist)
end

def webhook_retry_schedule
space_delimited_integer_list_or_default(:webhook_retry_schedule)
end

def database_configuration
if database_url
database_configuration_from_url
Expand Down Expand Up @@ -128,6 +132,36 @@ def to_s
end
end

def space_delimited_integer_list_or_default property_name
if env_populated?(property_name)
SpaceDelimitedIntegerList.parse(env(property_name))
else
default(property_name)
end
end

class SpaceDelimitedIntegerList < Array
def initialize list
super(list)
end

def self.integer?(string)
(Integer(string) rescue nil) != nil
end

def self.parse(string)
array = (string || '')
.split(' ')
.filter { |word| integer?(word) }
.collect(&:to_i)
SpaceDelimitedIntegerList.new(array)
end

def to_s
collect(&:to_s).join(' ')
end
end

private

def database_url
Expand Down
54 changes: 52 additions & 2 deletions spec/docker_configuration_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$: << "."
require "pact_broker/docker_configuration"
require_relative "../pact_broker/docker_configuration"
require 'rspec/its'

RSpec.describe PactBroker::DockerConfiguration do
Expand All @@ -9,15 +9,19 @@
let(:env) do
{
"PACT_BROKER_WEBHOOK_HOST_WHITELIST" => host_whitelist,
"PACT_BROKER_WEBHOOK_RETRY_SCHEDULE" => retry_schedule,
"PACT_BROKER_ORDER_VERSIONS_BY_DATE" => "false"
}
end

let(:host_whitelist) { "" }

let(:retry_schedule) { "" }

let(:default_configuration) do
instance_double('default configuration',
webhook_host_whitelist: 'default'
webhook_host_whitelist: 'default',
webhook_retry_schedule: 'default'
)
end

Expand Down Expand Up @@ -207,6 +211,19 @@
its(:webhook_host_whitelist) { is_expected.to eq 'default' }
end
end

describe "webhook_retry_schedule" do
context "when PACT_BROKER_WEBHOOK_RETRY_SCHEDULE is '1 2 3'" do
let(:retry_schedule) { "1 2 3" }
its(:webhook_retry_schedule) { is_expected.to eq [1, 2, 3] }
end

context "when PACT_BROKER_WEBHOOK_RETRY_SCHEDULE is ''" do
let(:retry_schedule) { "" }
its(:webhook_retry_schedule) { is_expected.to eq 'default' }
end
end

end

class PactBroker::DockerConfiguration
Expand Down Expand Up @@ -249,4 +266,37 @@ class PactBroker::DockerConfiguration
end
end
end

describe SpaceDelimitedIntegerList do
describe "parse" do
subject { SpaceDelimitedIntegerList.parse(input) }

context "when input is ''" do
let(:input) { "" }

it { is_expected.to eq [] }
it { is_expected.to be_a SpaceDelimitedIntegerList }

its(:to_s) { is_expected.to eq input }
end

context "when input is '0 1 1 2 3 5 8 13 21 34'" do
let(:input) { "0 1 1 2 3 5 8 13 21 34" }

it { is_expected.to eq [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] }
it { is_expected.to be_a SpaceDelimitedIntegerList }

its(:to_s) { is_expected.to eq input }
end

context "when input is '13 17 foo 19'" do
let(:input) { "13 17 foo 19" }

it { is_expected.to eq [13, 17, 19] }
it { is_expected.to be_a SpaceDelimitedIntegerList }

its(:to_s) { is_expected.to eq "13 17 19" }
end
end
end
end

0 comments on commit 536a61b

Please sign in to comment.