From 654142be53e6d0858d1b81e904ca528b8ed182b9 Mon Sep 17 00:00:00 2001 From: Vladislav Trotsenko Date: Thu, 28 Mar 2024 12:16:51 +0100 Subject: [PATCH] Feature/Ability to use configuration configuration with default settings without block (#23) * Updated OnStrum::Healthcheck.configure, tests * Updated gem documentation --- README.md | 8 ++++---- lib/on_strum/healthcheck.rb | 2 ++ spec/on_strum/healthcheck_spec.rb | 23 +++++++++++++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b5e77ea..eac3a19 100644 --- a/README.md +++ b/README.md @@ -155,7 +155,7 @@ Please note, to start using this middleware you should configure `OnStrum::Healt require 'on_strum/healthcheck' # Configuring OnStrum::Healthcheck with default settings -OnStrum::Healthcheck.configure {} +OnStrum::Healthcheck.configure Rack::Builder.app do use OnStrum::Healthcheck::RackMiddleware @@ -169,7 +169,7 @@ end require 'on_strum/healthcheck' # Configuring OnStrum::Healthcheck with default settings -OnStrum::Healthcheck.configure {} +OnStrum::Healthcheck.configure class YourApplication < Roda use OnStrum::Healthcheck::RackMiddleware @@ -184,7 +184,7 @@ end require 'on_strum/healthcheck' # Configuring OnStrum::Healthcheck with default settings -OnStrum::Healthcheck.configure {} +OnStrum::Healthcheck.configure ``` ```ruby @@ -203,7 +203,7 @@ end require 'on_strum/healthcheck' # Configuring OnStrum::Healthcheck with default settings -OnStrum::Healthcheck.configure {} +OnStrum::Healthcheck.configure ``` ```ruby diff --git a/lib/on_strum/healthcheck.rb b/lib/on_strum/healthcheck.rb index 9b83bbe..866d4dd 100644 --- a/lib/on_strum/healthcheck.rb +++ b/lib/on_strum/healthcheck.rb @@ -14,6 +14,8 @@ def configuration(&block) end def configure(&block) + return configuration {} unless block # rubocop:disable Lint/EmptyBlock + configuration(&block) end diff --git a/spec/on_strum/healthcheck_spec.rb b/spec/on_strum/healthcheck_spec.rb index 78e5bf2..2290005 100644 --- a/spec/on_strum/healthcheck_spec.rb +++ b/spec/on_strum/healthcheck_spec.rb @@ -23,8 +23,27 @@ let(:config_block) { nil } context 'without block' do - it { expect(configuration).to be_nil } - it { expect { configuration }.not_to change(described_class, :configuration) } + it 'sets default attributes into configuration instance' do + expect { configuration } + .to change(described_class, :configuration) + .from(nil) + .to(be_instance_of(OnStrum::Healthcheck::Configuration)) + expect(configuration).to be_an_instance_of(OnStrum::Healthcheck::Configuration) + expect(configuration.services).to eq({}) + expect(configuration.services_startup).to eq([]) + expect(configuration.services_liveness).to eq([]) + expect(configuration.services_readiness).to eq([]) + expect(configuration.endpoints_namespace).to eq(OnStrum::Healthcheck::Configuration::ENDPOINTS_NAMESPACE) + expect(configuration.endpoint_startup).to eq(OnStrum::Healthcheck::Configuration::ENDPOINT_STARTUP) + expect(configuration.endpoint_liveness).to eq(OnStrum::Healthcheck::Configuration::ENDPOINT_LIVENESS) + expect(configuration.endpoint_readiness).to eq(OnStrum::Healthcheck::Configuration::ENDPOINT_READINESS) + expect(configuration.endpoint_startup_status_success).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_SUCCESS) + expect(configuration.endpoint_liveness_status_success).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_SUCCESS) + expect(configuration.endpoint_readiness_status_success).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_SUCCESS) + expect(configuration.endpoint_startup_status_failure).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_FAILURE) + expect(configuration.endpoint_liveness_status_failure).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_FAILURE) + expect(configuration.endpoint_readiness_status_failure).to eq(OnStrum::Healthcheck::Configuration::DEFAULT_HTTP_STATUS_FAILURE) + end end context 'with block' do