Skip to content

Commit

Permalink
Add authorino tracing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
averevki committed Mar 4, 2024
1 parent dc32bcd commit 2d0c4bf
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 1 deletion.
17 changes: 16 additions & 1 deletion testsuite/openshift/authorino.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
"""Authorino CR object"""

import abc
from typing import Any, Dict, List
from typing import Any, Optional, Dict, List
from dataclasses import dataclass

from openshift_client import selector, timeout

from testsuite.openshift.client import OpenShiftClient
from testsuite.openshift import OpenShiftObject
from testsuite.lifecycle import LifecycleObject
from testsuite.utils import asdict


@dataclass
class TracingOptions:
"""Dataclass containing authorino tracing specification"""

endpoint: str
tags: Optional[dict[str, str]] = None
insecure: Optional[bool] = None


class Authorino(LifecycleObject):
Expand Down Expand Up @@ -45,6 +56,7 @@ def create_instance(
cluster_wide=False,
label_selectors: List[str] = None,
listener_certificate_secret=None,
tracing: TracingOptions = None,
log_level=None,
):
"""Creates base instance"""
Expand All @@ -68,6 +80,9 @@ def create_instance(
if listener_certificate_secret:
model["spec"]["listener"]["tls"] = {"enabled": True, "certSecretRef": {"name": listener_certificate_secret}}

if tracing:
model["spec"]["tracing"] = asdict(tracing)

with openshift.context:
return cls(model)

Expand Down
Empty file.
20 changes: 20 additions & 0 deletions testsuite/tests/kuadrant/authorino/tracing/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""Conftest for tracing tests"""

import pytest

from testsuite.openshift.authorino import TracingOptions


@pytest.fixture(scope="module")
def authorino_parameters(authorino_parameters, jaeger, testconfig):
"""Deploy authorino with tracing enabled"""
jaeger_insecure = testconfig["jaeger"]["insecure"]
authorino_parameters["tracing"] = TracingOptions(endpoint=jaeger.collector_url, insecure=jaeger_insecure)
return authorino_parameters


@pytest.fixture(scope="module")
def authorization(authorization):
"""Add response with 'request.id' to found this traced request later in Jaeger"""
authorization.responses.add_simple("request.id")
return authorization
18 changes: 18 additions & 0 deletions testsuite/tests/kuadrant/authorino/tracing/test_tracing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"""Test tracing with Jaeger"""

import pytest

from testsuite.utils import extract_response

pytestmark = [pytest.mark.authorino, pytest.mark.standalone_only]


def test_tracing(client, auth, jaeger):
"""Send request and check if it's trace is saved to Jaeger"""
response = client.get("/get", auth=auth)
assert response.status_code == 200

request_id = extract_response(response) % None
assert request_id is not None

assert jaeger.find_trace("Check", request_id)
30 changes: 30 additions & 0 deletions testsuite/tests/kuadrant/authorino/tracing/test_tracing_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Test custom tags set for request traces"""

import pytest

from testsuite.utils import extract_response

pytestmark = [pytest.mark.authorino, pytest.mark.standalone_only]


TAG_KEY = "test-key"
TAG_VALUE = "test-value"


@pytest.fixture(scope="module")
def authorino_parameters(authorino_parameters):
"""Deploy authorino with tracing enabled and custom tags set"""
authorino_parameters["tracing"].tags = {TAG_KEY: TAG_VALUE}
return authorino_parameters


@pytest.mark.issue("https://github.com/Kuadrant/authorino-operator/issues/171")
def test_tracing_tags(client, auth, jaeger):
"""Send request and check if it's trace with custom tags is saved to Jaeger"""
response = client.get("/get", auth=auth)
assert response.status_code == 200

request_id = extract_response(response) % None
assert request_id is not None

assert jaeger.find_tagged_trace("Check", request_id, TAG_KEY, TAG_VALUE)

0 comments on commit 2d0c4bf

Please sign in to comment.