Skip to content

Commit

Permalink
Merge pull request #241 from averevki/fix-metrics-tests
Browse files Browse the repository at this point in the history
Fix metrics tests broken by reformat
  • Loading branch information
pehala authored Oct 16, 2023
2 parents 1cac07a + af0e4f5 commit d5aff98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
5 changes: 5 additions & 0 deletions testsuite/openshift/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ def get_route(self, name):
with self.context:
return oc.selector(f"route/{name}").object(cls=OpenshiftRoute)

def get_routes_for_service(self, service_name: str) -> list[OpenshiftRoute]:
"""Returns list of routes for given service"""
with self.context:
return oc.selector("route", field_selectors={"spec.to.name": service_name}).objects(cls=OpenshiftRoute)

def do_action(self, verb: str, *args, auto_raise: bool = True, parse_output: bool = False):
"""Run an oc command."""
with self.context:
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/kuadrant/authorino/metrics/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def prometheus(request, openshift):
# find thanos-querier route in the openshift-monitoring project
# this route allows to query metrics
openshift_monitoring = openshift.change_project("openshift-monitoring")
routes = openshift_monitoring.routes.for_service("thanos-querier")
routes = openshift_monitoring.get_routes_for_service("thanos-querier")
if len(routes) > 0:
url = ("https://" if "tls" in routes[0]["spec"] else "http://") + routes[0]["spec"]["host"]
url = ("https://" if "tls" in routes[0].model.spec else "http://") + routes[0].model.spec.host
prometheus = Prometheus(url, openshift.token, openshift.project)
request.addfinalizer(prometheus.close)
return prometheus
Expand Down
20 changes: 6 additions & 14 deletions testsuite/tests/kuadrant/authorino/metrics/test_deep_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Tests for the functionality of the deep-evaluator metric samples"""
import pytest

from testsuite.objects import Property, Value


@pytest.fixture(scope="module")
def mockserver_expectation(request, mockserver, module_label):
Expand All @@ -20,20 +22,10 @@ def authorization(authorization, mockserver_expectation):
- http metadata from the mockserver
- non-empty response
"""
authorization.identity.anonymous("anonymous", metrics=True)
authorization.authorization.opa_policy("opa", "allow { true }", metrics=True)
authorization.metadata.http_metadata("http", mockserver_expectation, "GET", metrics=True)
authorization.responses.add(
{
"name": "json",
"json": {
"properties": [
{"name": "auth", "value": "response"},
]
},
},
metrics=True,
)
authorization.identity.add_anonymous("anonymous", metrics=True)
authorization.authorization.add_opa_policy("opa", "allow { true }", metrics=True)
authorization.metadata.add_http("http", mockserver_expectation, "GET", metrics=True)
authorization.responses.add_json("json", [Property("auth", Value("response"))], metrics=True)

return authorization

Expand Down

0 comments on commit d5aff98

Please sign in to comment.