apigeelint
Version:
Node module and tool to lint a bundle for an Apigee API Proxy or sharedflow.
95 lines (83 loc) • 3.05 kB
JavaScript
/*
Copyright 2019-2022,2025 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 describe, it */
const ruleId = "PD006",
assert = require("node:assert"),
path = require("node:path"),
util = require("node:util"),
debug = require("debug")(`apigeelint:${ruleId}-test`),
bl = require("../../lib/package/bundleLinter.js");
describe(`${ruleId} - proxyEndpoint basepath and other hygiene`, () => {
let reportedItems = null;
const insure = (cb) => {
if (reportedItems == null) {
const configuration = {
debug: true,
source: {
type: "filesystem",
path: path.resolve(__dirname, "../fixtures/resources/PD006/apiproxy"),
bundleType: "apiproxy",
},
profile: "apigeex",
excluded: {},
setExitCode: false,
output: () => {}, // suppress output
};
bl.lint(configuration, (bundle) => {
reportedItems = bundle.getReport();
assert.ok(reportedItems);
assert.ok(reportedItems.length);
debug(util.format(reportedItems));
cb();
});
} else {
cb();
}
};
it("should lint the bundle", () => {
insure(() => {
assert.ok(reportedItems);
assert.ok(reportedItems.length);
});
});
const expectations = {
"endpoint1.xml": [["Request is not supported here.", 2]],
"endpoint2.xml": [],
"endpoint3.xml": [["Missing required BasePath element.", 2]],
"endpoint4.xml": [
["More than one BasePath element found.", 2],
["Request is not supported here.", 1],
],
};
Object.keys(expectations).forEach((key) => {
const expectedMsgs = expectations[key];
it(`should find ${expectedMsgs.length > 0 ? "the expected errors" : "no errors"} in ${key}`, () => {
const epItems = reportedItems.filter((e) => e.filePath.endsWith(key));
assert.ok(epItems);
debug(util.format(epItems));
//assert.equal(expectations[key], epItems.length);
assert.equal(1, epItems.length);
const pd006Messages = epItems[0].messages.filter((m) => m.ruleId == ruleId);
debug(util.format(pd006Messages));
assert.equal(expectedMsgs.length, pd006Messages.length);
expectedMsgs.forEach((msgObject) => {
const found = pd006Messages.find((m) => m.message == msgObject[0]);
assert.ok(
found,
`Cannot find ${msgObject[0]} in ${pd006Messages.map((e) => e.message).toString()}`,
);
assert.equal(found.severity, msgObject[1]);
});
});
});
});