Skip to content

Commit

Permalink
add check for multiple fallbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoChiesa committed Sep 27, 2024
1 parent 45c7c88 commit db94be1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ const onTargetEndpoint = function (endpoint, cb) {

if (loadBalancers.length == 1) {
const loadBalancer = loadBalancers[0];
// check multiple fallbacks
const fallbacks = xpath.select(
"Server[IsFallback = 'true']",
loadBalancer
);
if (fallbacks.length > 1) {
endpoint.addMessage({
plugin,
line: loadBalancers[0].lineNumber,
column: loadBalancers[0].columnNumber,
message: "Multiple Server entries with IsFallback=true"
});
flagged = true;
}

const servers = xpath.select("Server", loadBalancer);
if (servers.length > 1) {
const previouslyDetected = [];
Expand Down
14 changes: 14 additions & 0 deletions test/fixtures/resources/TD008/fail/t4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<TargetEndpoint name="default">
<HTTPTargetConnection>
<LoadBalancer>
<Server name="server1"/>
<!-- two servers marked fallback will fail the TD008 check -->
<Server name="server2">
<IsFallback>true</IsFallback>
</Server>
<Server name="server3">
<IsFallback>true</IsFallback>
</Server>
</LoadBalancer>
</HTTPTargetConnection>
</TargetEndpoint>
12 changes: 12 additions & 0 deletions test/fixtures/resources/TD008/pass/t4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<TargetEndpoint name="default">
<HTTPTargetConnection>
<LoadBalancer>
<Server name="server1"/>
<Server name="server2"/>
<!-- single fallback is OK -->
<Server name="server3">
<IsFallback>true</IsFallback>
</Server>
</LoadBalancer>
</HTTPTargetConnection>
</TargetEndpoint>

0 comments on commit db94be1

Please sign in to comment.