diff --git a/.gitignore b/.gitignore index 390299b..5d59f01 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ tags doc/apidoc/ .idea *.swp +.DS_Store diff --git a/roles/metrics-export.lua b/roles/metrics-export.lua index 42c86b1..561e960 100644 --- a/roles/metrics-export.lua +++ b/roles/metrics-export.lua @@ -100,7 +100,7 @@ end local http_handlers = { json = function(req) local json_exporter = require('metrics.plugins.json') - return req:render({ text = json_exporter.export() }) + return req:render({ json = json_exporter.export() }) end, prometheus = function(...) local http_handler = require('metrics.plugins.prometheus').collect_http diff --git a/test/unit/http_test.lua b/test/unit/http_test.lua index a2cb581..59e9ece 100644 --- a/test/unit/http_test.lua +++ b/test/unit/http_test.lua @@ -1140,3 +1140,53 @@ for name, case in pairs(test_tls_cases) do end end end + +local function assert_content_type(uri, expected_content_type, tls_opts) + local response = http_client:get(uri, tls_opts) + t.assert_equals(response.status, 200) -- Убедимся, что эндпоинт доступен + t.assert_equals(response.headers['content-type'], expected_content_type) -- Проверка Content-Type +end + +local test_content_type_cases = { + ['json'] = { + cfg = { + http = { + { + listen = 8081, + endpoints = { + { + path = "/json_metrics", + format = "json", + }, + }, + }, + }, + }, + expected_url = "http://127.0.0.1:8081/json_metrics", + expected_content_type = "application/json; charset=utf-8", + }, + ['prometheus'] = { + cfg = { + http = { + { + listen = 8081, + endpoints = { + { + path = "/prometheus_metrics", + format = "prometheus", + }, + }, + }, + }, + }, + expected_url = "http://127.0.0.1:8081/prometheus_metrics", + expected_content_type = "text/plain; charset=utf-8", + }, +} + +for name, case in pairs(test_content_type_cases) do + g['test_content_type_' .. name] = function(cg) + cg.role.apply(case.cfg) + assert_content_type(case.expected_url, case.expected_content_type) + end +end