Files

75 lines
2.2 KiB
Lua
Raw Permalink Normal View History

2025-09-02 17:30:55 +04:00
-- Minimal cache_test.lua for go-proxy-cache integration
-- Tests basic functionality without complex mocking
2025-09-02 17:30:55 +04:00
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"
2025-09-02 17:30:55 +04:00
request_body = '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
response_body = '{"jsonrpc":"2.0","result":"0x123456","id":1}'
2025-08-18 16:25:27 +04:00
2025-09-02 17:30:55 +04:00
-- Mock environment
2025-08-18 16:25:27 +04:00
_G.os = _G.os or {}
_G.os.getenv = function(var)
2025-09-02 17:30:55 +04:00
if var == "GO_CACHE_SOCKET" then
return "/tmp/cache.sock"
2025-08-18 16:25:27 +04:00
end
return nil
end
2025-09-02 17:30:55 +04:00
cache = require("cache.cache")
end)
2025-07-21 14:50:12 +04:00
2025-09-02 17:30:55 +04:00
describe("basic functionality", function()
it("should have check_cache function", function()
assert.is_function(cache.check_cache)
end)
2025-09-02 17:30:55 +04:00
it("should have save_to_cache function", function()
assert.is_function(cache.save_to_cache)
end)
2025-09-02 17:30:55 +04:00
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)
2025-08-18 16:25:27 +04:00
end)
2025-09-02 17:30:55 +04:00
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
}
2025-09-02 17:30:55 +04:00
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)
2025-09-02 17:30:55 +04:00
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)
2025-09-02 17:30:55 +04:00
it("should provide run_diagnostics function", function()
assert.is_function(cache.run_diagnostics)
-- Should not crash when called
cache.run_diagnostics()
end)
end)
2025-08-18 16:25:27 +04:00
end)