-
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.
Updated RouteSelector tests to use SectionNames
Signed-off-by: Martin Hesko <[email protected]>
- Loading branch information
1 parent
489cc18
commit 1eb61c1
Showing
9 changed files
with
147 additions
and
70 deletions.
There are no files selected for viewing
33 changes: 0 additions & 33 deletions
33
testsuite/tests/singlecluster/limitador/route/test_limit_targeting_two_rules.py
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
testsuite/tests/singlecluster/limitador/route/test_route_rule.py
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
24 changes: 24 additions & 0 deletions
24
testsuite/tests/singlecluster/limitador/section/test_listener.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,24 @@ | ||
"""Tests that the RLP is correctly applies to the Gateway Listener.""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, gateway): | ||
"""Add a RateLimitPolicy targeting the Gateway Listener.""" | ||
rlp = RateLimitPolicy.create_instance(cluster, blame("limit"), gateway, "api", labels={"testRun": module_label}) | ||
rlp.add_limit("basic", [Limit(5, "10s")]) | ||
return rlp | ||
|
||
|
||
def test_listener_match(client): | ||
"""Tests that RLP correctly applies to the given Gateway Listener""" | ||
responses = client.get_many("/get", 5) | ||
responses.assert_all(status_code=200) | ||
|
||
assert client.get("/get").status_code == 429 | ||
assert client.get("/anything").status_code == 429 |
51 changes: 51 additions & 0 deletions
51
testsuite/tests/singlecluster/limitador/section/test_multiple_rules.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,51 @@ | ||
"""Test multiple RLP's targeting different HTTPRouteRules do not interfere with each other.""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRouteRule.""" | ||
rate_limit = RateLimitPolicy.create_instance( | ||
cluster, blame("limit"), route, "rule-1", labels={"testRun": module_label} | ||
) | ||
rate_limit.add_limit("basic", [Limit(3, "5s")]) | ||
return rate_limit | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit2(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the second HTTPRouteRule.""" | ||
rlp = RateLimitPolicy.create_instance(cluster, blame("limit"), route, "rule-2", labels={"testRun": module_label}) | ||
rlp.add_limit("basic", [Limit(2, "5s")]) | ||
return rlp | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def commit(request, rate_limit, rate_limit2): | ||
"""Commit and wait for RateLimitPolicies to be fully enforced""" | ||
for policy in [rate_limit, rate_limit2]: | ||
request.addfinalizer(policy.delete) | ||
policy.commit() | ||
policy.wait_for_ready() | ||
|
||
|
||
def test_multiple_limits_targeting_rules(client): | ||
"""Test targeting separate HTTPRouteRules with different limits""" | ||
responses = client.get_many("/get", 3) | ||
assert all( | ||
r.status_code == 200 for r in responses | ||
), f"Rate Limited resource unexpectedly rejected requests {responses}" | ||
|
||
responses = client.get_many("/anything", 2) | ||
assert all( | ||
r.status_code == 200 for r in responses | ||
), f"Rate Limited resource unexpectedly rejected requests {responses}" | ||
|
||
assert client.get("/get").status_code == 429 | ||
assert client.get("/anything").status_code == 429 |
28 changes: 28 additions & 0 deletions
28
testsuite/tests/singlecluster/limitador/section/test_multiple_same_listener.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,28 @@ | ||
"""Test that multiple limits targeting same Gateway Listener are correctly applied""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, gateway): | ||
"""Add a RateLimitPolicy targeting the Gateway Listener with multiple limits.""" | ||
rate_limit = RateLimitPolicy.create_instance( | ||
cluster, blame("limit"), gateway, "api", labels={"testRun": module_label} | ||
) | ||
rate_limit.add_limit("test1", [Limit(8, "10s")]) | ||
rate_limit.add_limit("test2", [Limit(3, "5s")]) | ||
return rate_limit | ||
|
||
|
||
def test_two_limits_targeting_one_listener(client): | ||
"""Test that one limit ends up shadowing others""" | ||
responses = client.get_many("/get", 3) | ||
assert all( | ||
r.status_code == 200 for r in responses | ||
), f"Rate Limited resource unexpectedly rejected requests {responses}" | ||
assert client.get("/get").status_code == 429 |
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
26 changes: 26 additions & 0 deletions
26
testsuite/tests/singlecluster/limitador/section/test_route_rule.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,26 @@ | ||
"""Tests that the RLP is correctly applied to the route rule""" | ||
|
||
import pytest | ||
|
||
from testsuite.kuadrant.policy.rate_limit import Limit, RateLimitPolicy | ||
|
||
pytestmark = [pytest.mark.kuadrant_only, pytest.mark.limitador] | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def rate_limit(cluster, blame, module_label, route): | ||
"""Add a RateLimitPolicy targeting the first HTTPRouteRule.""" | ||
rlp = RateLimitPolicy.create_instance(cluster, blame("limit"), route, "rule-1", labels={"testRun": module_label}) | ||
rlp.add_limit("basic", [Limit(5, "10s")]) | ||
return rlp | ||
|
||
|
||
def test_rule_match(client): | ||
"""Tests that RLP correctly applies to the given HTTPRouteRule""" | ||
responses = client.get_many("/get", 5) | ||
responses.assert_all(status_code=200) | ||
|
||
assert client.get("/get").status_code == 429 | ||
|
||
response = client.get("/anything") | ||
assert response.status_code == 200 |