apigeelint
Version:
Node module and tool to lint a bundle for an Apigee API Proxy or sharedflow.
102 lines (93 loc) • 3.63 kB
JavaScript
/*
Copyright © 2019-2023, 2025-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"),
pu = require("../../lib/package/plugins/_pluginUtil.js");
describe("TemplateCheck", function () {
const testCases = [
["{}", "empty template reference at position 1"],
["{a}", undefined],
["{{a}", "unterminated curly brace"],
["{{a}}", undefined], // dbl curly just means ... curly
["{[]}", "unexpected character at position 1: ["],
["{a[]}", "unexpected character at position 2: ["],
["{a", "unterminated curly brace"],
["}a", undefined], // but useless and sloppy
["{a}}", undefined], // but sloppy
["}a{", undefined], // but weird
["{a}b", undefined],
["{a}{b}", undefined],
["{a}.{b}", undefined],
["{a.b}", undefined],
["{3}", "unexpected character at position 1: 3"],
[
"{timeFormatUTCMs(propertyset.set1.timeformat,system.timestamp)}",
undefined,
],
[
"{timeFormatUTCMs(propertyset.set1.timeformat,system.timestamp) }",
"unexpected character at position 62: ",
],
[
`{ "organization": "{organization.name}", "environment": "{environment.name}" } `,
undefined,
],
[
`{ "organization": "{organization.name}", "environment": "{environment.{name}}" } `,
"unexpected character at position 71: {",
],
[
`{ "organization": "{organization.name}", "other": {"environment": "{environment.name}" } } `,
undefined,
],
["{createUuid()}", undefined],
["{createUuid( )}", "spaces between parens for function createUuid"],
["{timeFormatUTCMs()}", "empty arg string for function timeFormatUTCMs"],
["{notARealfunction()}", "unsupported function name (notARealfunction)"],
["{createUuid[]}", "unexpected character at position 11: ["],
["{ createUuid() }", undefined], // but ineffective and misleading
["{jsonPath('$.quota.[*].appname',jsondata)}", undefined],
[
"{jsonPath('$.quota.[*].appname,jsondata)}",
"unterminated open ' at position 39",
],
];
testCases.forEach((item, _ix) => {
const [expression, expectedError] = item;
it(`validateTemplate (${expression}) should return ${expectedError}`, function () {
const actualResult = pu.validateTemplate(expression);
assert.equal(actualResult, expectedError);
});
});
});
describe("PropertySetRefCheck", function () {
const testCases = [
["{foo.bar}", undefined],
[
"{foo.bar}.{var2}.setting",
"there is more than one dot in the template result",
],
["foo.bar.var2.setting", "there are 3 dots ( !=1 ) in the template result"],
["{foo.bar}.setting", undefined],
["{foo.bar}.{flow.var2}", undefined],
];
testCases.forEach((item, _ix) => {
const [expression, expectedResult] = item;
it(`PropertySetRef (${expression}) should be ${
expectedResult ? "valid" : "not valid"
}`, function () {
const actualResult = pu.validatePropertySetRef(expression);
assert.equal(actualResult, expectedResult);
});
});
});