wy471x opened a new pull request, #7175: URL: https://github.com/apache/shenyu/pull/7175
<!-- Fixes #6679 --> Make sure that: - [X] You have read the [contribution guidelines](https://shenyu.apache.org/community/contributor-guide). - [X] You submit test cases (unit or integration tests) that back your changes. - [X] Your local test passed `./mvnw clean install -Dmaven.javadoc.skip=true`. ## Summary `shenyu-kubernetes-controller` translates `V1Ingress` into ShenYu selectors/rules through the `org.apache.shenyu.k8s.parser` package, but only `DivideIngressParser`/`DubboIngressParser` and the sibling reconcilers had coverage. `IngressParser` (the plugin dispatcher), `WebSocketParser`, `GrpcParser`, `SofaParser`, `ContextPathParser` and `IngressReconciler` had no tests at all, so a regression in the ingress → selector/rule translation could ship silently. This PR adds the missing unit tests; no production code is changed. ### Changes: 1. `WebSocketParserTest` (new) — `WebSocketParser` path filters/operators, selector + rule construction, upstream parsing (weight/protocol, `shenyu.apache.org/upstreams-protocol` on the backend `Service`), fallback to the default backend upstream, `[]` handle when endpoints are absent, TLS (`Ingress.spec.tls` → `coreV1Api.readNamespacedSecret` → `SslCrtAndKeyStream`), and the empty config returned when `spec` is null. 2. `GrpcParserTest` (new) — grpc rule/metadata translation from the labeled metadata `Service` (`plugin-grpc-*` annotations → `RuleData`/`MetaData`), upstream weight 100 for rules vs 50 for the global default backend, `getRpcRouteConfig` defaults when `rules` is empty (appName `grpc`, path `/grpc/helloService/hello`, service `hello.HelloService`, contextPath `/grpc`, enabled), path-type → operator mapping and the empty handle when endpoints have no subsets. 3. `SofaParserTest` (new) — sofa rule/metadata translation (`plugin-sofa-*` annotations), `getSofaRouteConfig` defaults (`sofa` app, `/sofa/findAll`, `findAll`, `/sofa`, `IngressConstants.ID` on selector/rule), path-type → operator mapping, and the null/null result when neither rules nor a default backend exist. 4. `ContextPathParserTest` (new) — context-path selector/rule construction, `ContextMappingRuleHandle` (`contextPath`/`addPrefix`/`addPrefixed`, defaults when annotations are missing), path-type → operator mapping, and null-path/rules/spec handling. 5. `IngressParserTest` (new) — the annotation-driven dispatch: `plugin-dubbo/web-socket/grpc/sofa-enabled=true` routes to exactly one matching parser, no annotation (or all disabled) selects divide, and a `Prefix` path additionally emits a context-path config alongside the divide one. 6. `IngressReconcilerTest` (new) — reconcile of a new ingress (selector/rule saved, `IngressCache`/`ServiceIngressCache` populated, upstream handle refreshed from `V1Endpoints` ports instead of the ingress backend port), the websocket plugin path (`saveOrUpdatePluginData` for `web_socket`, `ws://` upstream handle), skipping an ingress whose class is not `shenyu`, accepting `spec.ingressClassName: shenyu` when the annotation is absent, the update path (`needUpdate` → delete stale selector/rule → save the new config), and the delete path (`V1Ingress` gone → caches cleaned, `deleteSelectorData` called). ### Test Cases: 1. `WebSocketParserTest` — 9 cases. 2. `GrpcParserTest` — 6 cases. 3. `SofaParserTest` — 5 cases. 4. `ContextPathParserTest` — 6 cases. 5. `IngressParserTest` — 7 cases. 6. `IngressReconcilerTest` — 6 cases. ## Verification - `mvn -pl shenyu-kubernetes-controller test` (JDK 21): `Tests run: 59, Failures: 0, Errors: 0, Skipped: 0` — 39 new cases plus the 20 pre-existing ones (no cross-test interference from the singleton caches, each test cleans/uses its own namespace). - `mvn clean install -Dmaven.javadoc.skip=true` (JDK 21): BUILD SUCCESS over the whole reactor, checkstyle (0 violations) + RAT included. Fixes #6679 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
