|
1 | 1 | import { describe, expect, it } from "vitest"; |
2 | 2 | import type { RoutingRule } from "../../../generated/bindings"; |
3 | | -import { isCatchAllRule } from "../helpers"; |
| 3 | +import { isCatchAllRule, isRedundantCatchAll } from "../helpers"; |
4 | 4 |
|
5 | 5 | const rule = (patch: Partial<RoutingRule>): RoutingRule => ({ |
6 | 6 | id: "r1", |
@@ -47,3 +47,31 @@ describe("isCatchAllRule", () => { |
47 | 47 | expect(isCatchAllRule(rule({ port: "0-abc" }))).toBe(false); |
48 | 48 | }); |
49 | 49 | }); |
| 50 | + |
| 51 | +describe("isRedundantCatchAll", () => { |
| 52 | + const catchAll = (patch: Partial<RoutingRule> = {}) => rule({ port: "0-65535", ...patch }); |
| 53 | + |
| 54 | + it("flags a trailing catch-all that only repeats the final proxy fallback", () => { |
| 55 | + expect(isRedundantCatchAll([rule({ ip: ["geoip:ru"] }), catchAll()], 1)).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + it("ignores one that still shadows an enabled rule below", () => { |
| 59 | + expect(isRedundantCatchAll([catchAll(), rule({ ip: ["geoip:ru"] })], 0)).toBe(false); |
| 60 | + }); |
| 61 | + |
| 62 | + it("looks past disabled rules below", () => { |
| 63 | + expect(isRedundantCatchAll([catchAll(), rule({ ip: ["geoip:ru"], enabled: false })], 0)).toBe( |
| 64 | + true, |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + it("ignores a catch-all routed anywhere but the proxy", () => { |
| 69 | + expect(isRedundantCatchAll([catchAll({ outboundTag: "direct" })], 0)).toBe(false); |
| 70 | + expect(isRedundantCatchAll([catchAll({ outboundTag: "block" })], 0)).toBe(false); |
| 71 | + }); |
| 72 | + |
| 73 | + it("ignores an index that points at no rule", () => { |
| 74 | + expect(isRedundantCatchAll([catchAll()], -1)).toBe(false); |
| 75 | + expect(isRedundantCatchAll([], 0)).toBe(false); |
| 76 | + }); |
| 77 | +}); |
0 commit comments