httpx/test/response_cache_store_test.rb
HoneyryderChuck 7e9de9faf3 options: cache options names in class var, use it to set ivars in a predictable order
the way it was setup, the options class was object shape unfriendly, as the order of creation of ivars was dependent on input and undeterministic; this change fixes it by storing the option names in an array in the class, properly allowing it for extension on plugin calls, freezing it on demand when necessary, and using it to find unsupported options in cases where the former implementation didn't

some code was juggled to delay certain instantiations for later, and option_ setters are now private, as they should
2025-09-02 11:47:46 +01:00

36 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require_relative "test_helper"
require "httpx/plugins/response_cache/store"
class ResponseCacheStoreTest < Minitest::Test
include ResponseCacheStoreTests
def test_internal_store_set
internal_store = store.instance_variable_get(:@store)
request = make_request("GET", "http://example.com/")
response = cached_response(request)
assert internal_store.size == 1
assert internal_store[request.response_cache_key] == response
response1 = cached_response(request, extra_headers: { "content-language" => "en" })
assert internal_store.size == 1
assert internal_store[request.response_cache_key] == response1
response2 = cached_response(request, extra_headers: { "content-language" => "en", "vary" => "accept-language" })
assert internal_store.size == 1
assert internal_store[request.response_cache_key] == response2
request.merge_headers("accept-language" => "pt")
response3 = cached_response(request, extra_headers: { "content-language" => "pt", "vary" => "accept-language" }, body: "teste")
assert internal_store.size == 2
assert internal_store[request.response_cache_key] == response3
end
private
def init_store
Plugins::ResponseCache::Store.new
end
end