Sha256: 72259c94a49e74f22597b299e644a84404dcf47d20d41256bb9bfdb33b53891f
Contents?: true
Size: 1.22 KB
Versions: 2
Compression:
Stored size: 1.22 KB
Contents
# frozen_string_literal: true require 'minitest/autorun' require_relative '../lib/throttler' class ThrottlerTest < Minitest::Test def setup @endpoint = 'getItemOffers' @prefix = 'US' @redis = Minitest::Mock.new @options = Throttler::DEFAULT_OPTIONS @burst_key = "#{@prefix}:#{@endpoint}:burst" @subject = Throttler.new(@endpoint, @prefix, @options) end def test_initialize assert_equal @endpoint, @subject.instance_variable_get(:@endpoint) assert_equal @prefix, @subject.instance_variable_get(:@prefix) assert_equal @options, @subject.instance_variable_get(:@options) end def test_with_throttling block = proc { 'result' } @redis.expect(:pttl, 0) @redis.expect(:psetex, true) assert_equal 'result', @subject.with_throttling(&block) end def test_with_throttling_when_api_error_with_code_429_occurs block = proc { raise StandardError.new(code: 429) } assert_raises(StandardError) { @subject.with_throttling(&block) } assert_mock @redis end def test_with_throttling_when_api_error_with_code_500_occurs block = proc { raise StandardError.new(code: 500) } assert_raises(StandardError) { @subject.with_throttling(&block) } assert_mock @redis end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
EasyThrottle-0.1.0 | test/test_easy_throttle.rb |
EasyThrottle-0.0.2 | test/test_easy_throttle.rb |