mirror of
https://github.com/status-im/eth-rpc-proxy.git
synced 2026-08-30 19:21:09 +00:00
75 lines
2.2 KiB
Lua
75 lines
2.2 KiB
Lua
-- Minimal cache_test.lua for go-proxy-cache integration
|
|
-- Tests basic functionality without complex mocking
|
|
|
|
describe("cache.lua integration with go-proxy-cache", function()
|
|
local cache
|
|
local chain, network, request_body, response_body
|
|
|
|
before_each(function()
|
|
chain = "ethereum"
|
|
network = "mainnet"
|
|
request_body = '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
|
|
response_body = '{"jsonrpc":"2.0","result":"0x123456","id":1}'
|
|
|
|
-- Mock environment
|
|
_G.os = _G.os or {}
|
|
_G.os.getenv = function(var)
|
|
if var == "GO_CACHE_SOCKET" then
|
|
return "/tmp/cache.sock"
|
|
end
|
|
return nil
|
|
end
|
|
|
|
cache = require("cache.cache")
|
|
end)
|
|
|
|
describe("basic functionality", function()
|
|
it("should have check_cache function", function()
|
|
assert.is_function(cache.check_cache)
|
|
end)
|
|
|
|
it("should have save_to_cache function", function()
|
|
assert.is_function(cache.save_to_cache)
|
|
end)
|
|
|
|
it("should handle invalid JSON body gracefully", function()
|
|
local result = cache.check_cache(chain, network, "invalid json")
|
|
assert.is_table(result)
|
|
assert.are.equal(chain, result.chain)
|
|
assert.are.equal(network, result.network)
|
|
end)
|
|
|
|
it("should not save when cache_type is nil (BYPASS)", function()
|
|
local cache_info = {
|
|
cache_key = "test_key",
|
|
raw_body = request_body,
|
|
cache_type = nil, -- BYPASS case
|
|
chain = chain,
|
|
network = network
|
|
}
|
|
|
|
local result = cache.save_to_cache(cache_info, response_body)
|
|
assert.is_false(result)
|
|
end)
|
|
|
|
it("should handle missing cache info gracefully", function()
|
|
local invalid_cache_info = {}
|
|
local result = cache.save_to_cache(invalid_cache_info, response_body)
|
|
assert.is_false(result)
|
|
end)
|
|
end)
|
|
|
|
describe("diagnostic functions", function()
|
|
it("should provide reset_cache_instances function", function()
|
|
assert.is_function(cache.reset_cache_instances)
|
|
-- Should not crash when called
|
|
cache.reset_cache_instances()
|
|
end)
|
|
|
|
it("should provide run_diagnostics function", function()
|
|
assert.is_function(cache.run_diagnostics)
|
|
-- Should not crash when called
|
|
cache.run_diagnostics()
|
|
end)
|
|
end)
|
|
end) |