httpx/test/response_cache_file_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

33 lines
937 B
Ruby

# frozen_string_literal: true
require_relative "test_helper"
require "httpx/plugins/response_cache/file_store"
class ResponseCacheFileStoreTest < Minitest::Test
include ResponseCacheStoreTests
def test_internal_store_set
request = make_request("GET", "http://store-set/")
assert !File.exist?(store.dir.join(request.response_cache_key))
response = cached_response(request)
assert File.exist?(store.dir.join(request.response_cache_key))
store.set(request, response)
assert File.exist?(store.dir.join(request.response_cache_key))
end
def test_finished
request = make_request("GET", "http://store-cache/")
cached_response(request)
response = store.get(request)
assert response.finished?
end
private
def init_store
tmpdir = Pathname.new(Dir.tmpdir).join(SecureRandom.alphanumeric)
FileUtils.mkdir_p(tmpdir)
HTTPX::Plugins::ResponseCache::FileStore.new(tmpdir)
end
end