Skip to content

Commit

Permalink
updated query api order, fixed spec and added error to split logger
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal Al committed May 1, 2024
1 parent 0f5ac2f commit db9311a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/splitclient-rb/engine/api/splits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def since(since, fetch_options = { cache_control_headers: false, till: nil, sets
start = Time.now

params = { s: SplitIoClient::Spec::FeatureFlags::SPEC_VERSION, since: since }
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
params[:sets] = @flag_sets_filter.join(",") unless @flag_sets_filter.empty?
params[:till] = fetch_options[:till] unless fetch_options[:till].nil?
@config.logger.debug("Fetching from splitChanges with #{params}: ")
response = get_api("#{@config.base_uri}/splitChanges", @api_key, params, fetch_options[:cache_control_headers])
if response.status == 414
Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/engine/matchers/between_semver_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def initialize(attribute, start_value, end_value, logger, validator)
end

def match?(args)
@logger.debug('[BetweenSemverMatcher] evaluating value and attributes.')
@logger.log_if_debug('[BetweenSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
Expand All @@ -26,7 +26,7 @@ def match?(args)
end
matches = ([0, -1].include?(@semver_start.compare(value_to_match)) &&
[0, 1].include?(@semver_end.compare(value_to_match)))
@logger.debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}")
@logger.log_if_debug("[BetweenMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/engine/matchers/equal_to_semver_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator)
end

def match?(args)
@logger.debug('[EqualsToSemverMatcher] evaluating value and attributes.')
@logger.log_if_debug('[EqualsToSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
Expand All @@ -24,7 +24,7 @@ def match?(args)
return false
end
matches = (@semver.version == value_to_match.version)
@logger.debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
@logger.log_if_debug("[EqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator)
end

def match?(args)
@logger.debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.')
@logger.log_if_debug('[GreaterThanOrEqualsToSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
Expand All @@ -24,7 +24,7 @@ def match?(args)
return false
end
matches = [0, 1].include?(value_to_match.compare(@semver))
@logger.debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
@logger.log_if_debug("[GreaterThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/splitclient-rb/engine/matchers/in_list_semver_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(attribute, list_value, logger, validator)
end

def match?(args)
@logger.debug('[InListSemverMatcher] evaluating value and attributes.')
@logger.log_if_debug('[InListSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args) && args[:attributes][@attribute.to_sym].is_a?(String)

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
Expand All @@ -24,7 +24,7 @@ def match?(args)
return false
end
matches = (@semver_list.map { |item| item.version == value_to_match.version }).any? { |item| item == true }
@logger.debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}")
@logger.log_if_debug("[InListSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def initialize(attribute, string_value, logger, validator)
end

def match?(args)
@logger.debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.')
@logger.log_if_debug('[LessThanOrEqualsToSemverMatcher] evaluating value and attributes.')
return false unless @validator.valid_matcher_arguments(args)

value_to_match = SplitIoClient::Semver.build(args[:attributes][@attribute.to_sym], @logger)
Expand All @@ -24,7 +24,7 @@ def match?(args)
return false
end
matches = [0, -1].include?(value_to_match.compare(@semver))
@logger.debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
@logger.log_if_debug("[LessThanOrEqualsToSemverMatcher] #{value_to_match} matches -> #{matches}")
matches
end
end
Expand Down
4 changes: 4 additions & 0 deletions lib/splitclient-rb/split_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ def log_if_debug(message)
def log_if_transport(message)
@config.logger.debug(message) if @config.transport_debug_enabled
end

def error(message)
@config.logger.error(message)
end
end
end
28 changes: 16 additions & 12 deletions spec/engine/matchers/semver_matchers_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@
let(:user) { 'fake_user_id_1' }

before do
stub_request(:any, /https:\/\/telemetry.*/).to_return(status: 200, body: 'ok')
stub_request(:any, /https:\/\/events.*/).to_return(status: 200, body: "", headers: {})
stub_request(:any, /https:\/\/telemetry\.*/).to_return(status: 200, body: 'ok')
stub_request(:any, /https:\/\/events\.*/).to_return(status: 200, body: "", headers: {})
stub_request(:any, /https:\/\/metrics\.*/).to_return(status: 200, body: "", headers: {})
stub_request(:post, "https://telemetry.split.io/api/v1/metrics/config").to_return(status: 200, body: "", headers: {})
end

context 'equal to matcher' do
before do
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since\.*/)
.to_return(status: 200, body: semver_equalto_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: semver_equalto_matcher_splits)
stub_request(:get, "https://sdk.split.io/api/splitChanges?s=1.1&since=1675259356568")
.to_return(status: 200, body: semver_equalto_matcher_splits)
sleep 1
subject.block_until_ready
Expand All @@ -70,9 +74,9 @@

context 'greater than or equal to matcher' do
before do
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: semver_greater_or_equalto_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: semver_greater_or_equalto_matcher_splits)
sleep 1
subject.block_until_ready
Expand All @@ -92,9 +96,9 @@

context 'less than or equal to matcher' do
before do
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: semver_less_or_equalto_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: semver_less_or_equalto_matcher_splits)
sleep 1
subject.block_until_ready
Expand All @@ -114,9 +118,9 @@

context 'in list matcher' do
before do
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: semver_inlist_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: semver_inlist_matcher_splits)
sleep 1
subject.block_until_ready
Expand All @@ -136,9 +140,9 @@

context 'between matcher' do
before do
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?since/)
stub_request(:get, /https:\/\/sdk\.split\.io\/api\/splitChanges\?s=1\.1&since/)
.to_return(status: 200, body: semver_between_matcher_splits)
stub_request(:get, 'https://sdk.split.io/api/splitChanges?since=-1')
stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1')
.to_return(status: 200, body: semver_between_matcher_splits)
sleep 1
subject.block_until_ready
Expand Down

0 comments on commit db9311a

Please sign in to comment.