apigeelint
Version:
Node module and tool to lint a bundle for an Apigee API Proxy or sharedflow.
76 lines (69 loc) • 2.52 kB
JavaScript
/*
Copyright © 2019-2021, 2026 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* global it, describe */
const assert = require("node:assert"),
// debug = require("debug")("apigeelint:flowConditions"),
Endpoint = require("../../lib/package/Endpoint.js"),
Dom = require("@xmldom/xmldom").DOMParser,
test = function (exp, assertion) {
it("testing flow conditions", function () {
const result = [],
doc = new Dom().parseFromString(exp),
ep = new Endpoint(doc, this, "/dummy/test/apiproxy/proxies/foo.xml"),
flows = ep.getFlows();
flows.forEach(function (f) {
result.push(f.getCondition().getExpression());
});
assert.deepEqual(
result,
assertion,
result ? "conditions did not match" : "conditions matched",
);
});
};
describe("FlowConditions", function () {
test(
`
<ProxyEndpoint name="default">
<Flows>
<Flow name="condition1">
<Description>This is condition 1</Description>
<Request>
<Step>
<Name>jsCalculate</Name>
</Step>
</Request>
<Response>
</Response>
<Condition>(request.verb = "GET") and (proxy.pathsuffix MatchesPath "/condition1")</Condition>
</Flow>
<Flow name="condition2">
<Description>This is condition 2</Description>
<Request>
<Step>
<Name>jsCalculateFromContext</Name>
</Step>
</Request>
<Response>
</Response>
<Condition>(request.verb = "GET") and (proxy.pathsuffix MatchesPath "/condition2")</Condition>
</Flow>
</Flows>
</ProxyEndpoint>
`,
[
`(request.verb = "GET") and (proxy.pathsuffix MatchesPath "/condition1")`,
`(request.verb = "GET") and (proxy.pathsuffix MatchesPath "/condition2")`,
],
);
});