-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #352 from jsmolar/request_assert
Add tests for Reconcile Sub Component Limitador CR
- Loading branch information
Showing
4 changed files
with
114 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"""Kuadrant CR object""" | ||
|
||
from openshift_client import selector | ||
|
||
from testsuite.openshift import OpenShiftObject, modify | ||
from testsuite.openshift.deployment import Deployment | ||
|
||
|
||
class KuadrantCR(OpenShiftObject): | ||
"""Represents Kuadrant CR objects""" | ||
|
||
LIMITADOR = "limitador-limitador" | ||
|
||
@property | ||
def limitador(self) -> dict: | ||
"""Returns spec.limitador from Kuadrant object""" | ||
return self.model.spec.setdefault("limitador", {}) | ||
|
||
@limitador.setter | ||
@modify | ||
def limitador(self, value: dict): | ||
"""Sets the value of spec.limitador""" | ||
self.model.spec["limitador"] = value | ||
|
||
@property | ||
def limitador_deployment(self): | ||
"""Returns Deployment object for this Authorino""" | ||
with self.context: | ||
return selector(f"deployment/{self.LIMITADOR}").object(cls=Deployment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
63 changes: 63 additions & 0 deletions
63
testsuite/tests/kuadrant/reconciliation/cr_configuration/test_reconcile_limitador.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Tests for Kuadrant sub component - Limitador CR configuration via Kuadrant CR""" | ||
|
||
import pytest | ||
|
||
pytestmark = [pytest.mark.kuadrant_only] | ||
|
||
|
||
@pytest.fixture() | ||
def commit(): | ||
"""Omitting authorization and rate limiting as it is not needed""" | ||
|
||
|
||
@pytest.fixture(autouse=True) | ||
def kuadrant_clean_up(request, kuadrant): | ||
""" | ||
Return fields to default values. | ||
This can be simplified once https://github.com/Kuadrant/kuadrant-operator/issues/617 is fixed. | ||
""" | ||
|
||
def _finalize(): | ||
kuadrant.limitador = {"replicas": 1, "resourceRequirements": {"requests": {"cpu": "250m", "memory": "32Mi"}}} | ||
|
||
request.addfinalizer(_finalize) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"field, value", | ||
[ | ||
pytest.param("replicas", 2, id="replicas"), | ||
pytest.param( | ||
"resourceRequirements", {"requests": {"cpu": "300m", "memory": "40Mi"}}, id="resourceRequirements" | ||
), | ||
], | ||
) | ||
def test_fields_to_reconcile(kuadrant, field, value): | ||
""" | ||
Test: | ||
- change specific `field` to `value` in Kuadrant CR | ||
- assert that `field` in Kuadrant CR Limitador is equal to `value` | ||
- assert that `field` in Limitador deployment is equal to `value` | ||
""" | ||
kuadrant.limitador = {field: value} | ||
|
||
assert value == kuadrant.limitador[field] | ||
assert str(value) in str(kuadrant.limitador_deployment.model.spec) | ||
|
||
|
||
@pytest.mark.xfail | ||
@pytest.mark.issue("https://github.com/Kuadrant/kuadrant-operator/issues/617") | ||
def test_blank_fields_wont_reconcile(kuadrant): | ||
""" | ||
Test: | ||
- setup limitador with replicas and resourceRequirements != default | ||
- change replicas to 3 | ||
- assert replicas field is 3 for limitador deployment | ||
- assert blank field resourceRequirements is returned to default for limitador deployment | ||
""" | ||
kuadrant.limitador = {"replicas": 2, "resourceRequirements": {"requests": {"cpu": "300m", "memory": "40Mi"}}} | ||
|
||
kuadrant.limitador = {"replicas": 3} | ||
|
||
assert kuadrant.limitador_deployment.model.spec.replicas == 3 | ||
assert "'cpu': '250m', 'memory': '32Mi'" in str(kuadrant.limitador_deployment.model.spec) |