UNPKG

apigeelint

Version:

Node module and tool to lint a bundle for an Apigee API Proxy or sharedflow.

67 lines (59 loc) 2.17 kB
/* Copyright © 2019-2022, 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 describe, it */ const assert = require("node:assert"), path = require("node:path"), testID = "PD001", bl = require("../../lib/package/bundleLinter.js"); describe(`${testID} - bundle with reference to missing target`, () => { it("should generate the expected error", () => { const configuration = { debug: true, source: { type: "filesystem", path: path.resolve( __dirname, "../fixtures/resources/PD001-missing-target/apiproxy", ), bundleType: "apiproxy", }, profile: "apigee", excluded: {}, setExitCode: false, output: () => {}, // suppress output }; bl.lint(configuration, (bundle) => { const items = bundle.getReport(); assert.ok(items); assert.ok(items.length); const itemsWithErrors = items.filter( (item) => item.messages && item.messages.length && item.messages.find((m) => m.ruleId == testID), ); assert.equal(itemsWithErrors.length, 1); assert.ok(itemsWithErrors[0].messages.length); const diags = JSON.stringify(itemsWithErrors[0].messages); assert.equal(itemsWithErrors[0].messages.length, 2, diags); const expectedErrors = [ "RouteRule refers to an unknown TargetEndpoint (target1).", "RouteRule specifies an empty TargetEndpoint.", ]; itemsWithErrors[0].messages.forEach((e, ix) => { assert.ok(e.message, diags); assert.equal(e.message, expectedErrors[ix], e.message); }); }); }); });