Kuadrant / Kuadrant/testsuite

Add tests for named HTTPRouteRule sectionName targeting

Open
#942 1 comment 0 reactions 0 assignees View on GitHub
enhancement good first issue
Dominant language
Python
Stars
7
Forks
29
Avg merge
1d 9h
Merged PRs (30d)
7

Description

## Summary

Gateway API introduced explicit naming for `HTTPRouteRule` entries ([kubernetes-sigs/gateway-api#995](https://github.com/kubernetes-sigs/gateway-api/issues/995)), allowing users to set a `name` field on individual rules in `spec.rules[].name` instead of relying on auto-generated names like `rule-1`, `rule-2`. Kuadrant's policy-machinery added support for this in [Kuadrant/policy-machinery#63](https://github.com/Kuadrant/policy-machinery/pull/63).

The testsuite currently targets HTTPRoute rules via auto-generated sectionName values (e.g. `"rule-1"`). We need tests that verify policies can target explicitly named HTTPRouteRules.

## Suggested Code Changes

### 1. `HTTPRoute.add_rule()` and `add_backend()` — add `name` parameter

In `testsuite/gateway/gateway_api/route.py`, both `add_rule()` and `add_backend()` build rule dicts without a `name` field. Add an optional `name` parameter so tests can create named rules:

```python
@modify
def add_backend(self, backend: "Backend", prefix="/", name: str = None):
rule = {"backendRefs": [backend.reference], "matches": [{"path": {"value": prefix, "type": "PathPrefix"}}]}
if name:
rule["name"] = name
self.model.spec.rules.append(rule)
```

Same change for `add_rule()`.

### 2. New test coverage

Add tests (e.g. under `testsuite/tests/singlecluster/limitador/section/` and `testsuite/tests/singlecluster/gateway/authpolicy/`) that:

- Create an HTTPRoute with explicitly named rules (e.g. `name="get-rule"`, `name="anything-rule"`)
- Attach a policy targeting one named rule via `section_name="get-rule"`
- Verify the policy applies only to the targeted rule and not the other

This should mirror the existing pattern in `test_route_rule.py` and `test_authpolicy_section_targeting_http_route.py`, but use explicit rule names instead of auto-generated ones.

Contributor guide

Open the contributing guide

Research direction

Start in testsuite/gateway/gateway_api/route.py and compare test_route_rule.py with test_authpolicy_section_targeting_http_route.py. Add named HTTPRouteRule setup and tests in the indicated section directories, then verify a policy targeting section_name="get-rule" applies only to that rule and not the other named rule.

Written by the indexing model from the issue text.

Assessment

Tech stack
kubernetes, python
Domain
networking, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.