hanicz commented on code in PR #1196:
URL: https://github.com/apache/knox/pull/1196#discussion_r3064713603
##########
.github/workflows/tests/test_health.py:
##########
@@ -53,6 +54,32 @@ def test_health_metrics_returns_json(self):
payload = json.loads(response.text)
self.assertIsInstance(payload, dict)
+ def test_health_metrics_contains_core_fields(self):
+ """Metrics JSON should expose the same top-level keys as the Java
GatewayHealthFuncTest."""
+ url = self.base_url + "gateway/health/v1/metrics?pretty=true"
+ response = knox_get(url)
+ self.assertEqual(response.status_code, 200)
+ payload = json.loads(response.text)
+ expected = {"timers", "histograms", "counters", "gauges", "version",
"meters"}
+ self.assertTrue(expected.issubset(payload.keys()), msg=f"Missing keys:
{expected - set(payload.keys())}")
+
+ def test_health_metrics_without_pretty_returns_json(self):
+ """Metrics without pretty still returns 200 and parseable JSON."""
+ url = self.base_url + "gateway/health/v1/metrics"
+ response = knox_get(url)
+ self.assertEqual(response.status_code, 200)
+ self.assertIn("application/json", response.headers.get("Content-Type",
""))
+ payload = json.loads(response.text)
+ self.assertIsInstance(payload, dict)
+
+ def test_health_ping_content_type_is_plain_text(self):
+ """Ping response declares text/plain Content-Type."""
+ url = self.base_url + "gateway/health/v1/ping"
+ response = knox_get(url)
+ self.assertEqual(response.status_code, 200)
+ content_type = response.headers.get("Content-Type", "")
+ self.assertIn("text/plain", content_type)
Review Comment:
Could you check for the actual content as well? (OK)
##########
.github/workflows/tests/test_health.py:
##########
@@ -53,6 +54,32 @@ def test_health_metrics_returns_json(self):
payload = json.loads(response.text)
self.assertIsInstance(payload, dict)
+ def test_health_metrics_contains_core_fields(self):
+ """Metrics JSON should expose the same top-level keys as the Java
GatewayHealthFuncTest."""
+ url = self.base_url + "gateway/health/v1/metrics?pretty=true"
+ response = knox_get(url)
+ self.assertEqual(response.status_code, 200)
+ payload = json.loads(response.text)
+ expected = {"timers", "histograms", "counters", "gauges", "version",
"meters"}
+ self.assertTrue(expected.issubset(payload.keys()), msg=f"Missing keys:
{expected - set(payload.keys())}")
+
+ def test_health_metrics_without_pretty_returns_json(self):
+ """Metrics without pretty still returns 200 and parseable JSON."""
+ url = self.base_url + "gateway/health/v1/metrics"
+ response = knox_get(url)
+ self.assertEqual(response.status_code, 200)
+ self.assertIn("application/json", response.headers.get("Content-Type",
""))
Review Comment:
It would make sense to check for the same payload keys as you did in the
pretty test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]