-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathPO039-test.js
105 lines (93 loc) · 3.51 KB
/
PO039-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
Copyright 2019-2024 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.
*/
const testID = "PO039",
assert = require("assert"),
fs = require("fs"),
path = require("path"),
bl = require("../../lib/package/bundleLinter.js"),
plugin = require(bl.resolvePlugin(testID)),
debug = require("debug")("apigeelint:" + testID),
Policy = require("../../lib/package/Policy.js"),
Dom = require("@xmldom/xmldom").DOMParser,
rootDir = path.resolve(__dirname, "../fixtures/resources/PO039");
const test = (suffix, cb) => {
const filename = `ML-test-${suffix}.xml`;
it(`should correctly process ${filename}`, () => {
const fqfname = path.join(rootDir, filename),
policyXml = fs.readFileSync(fqfname, "utf-8"),
doc = new Dom().parseFromString(policyXml),
p = new Policy(rootDir, filename, this, doc);
p.getElement = () => doc.documentElement;
//plugin.onBundle({ profile: "apigee" });
plugin.onPolicy(p, (e, foundIssues) => {
assert.equal(e, undefined, "should be undefined");
cb(p, foundIssues);
});
});
};
describe(`${testID} - MessageLogging RessourceType element`, () => {
// test all the valid cases
fs.readdirSync(rootDir)
.map((shortFileName) => {
let m = shortFileName.match("^.+-(valid.+)\\.xml$");
if (m) {
return m[1];
}
})
.filter((suffix) => suffix)
.forEach((suffix) => {
test(suffix, (p, foundIssues) => {
const messages = p.getReport().messages;
assert.ok(messages, "messages undefined");
debug(messages);
assert.equal(foundIssues, false);
});
});
test("invalid1", (p, foundIssues) => {
assert.equal(foundIssues, true);
const messages = p.getReport().messages;
assert.ok(messages, "messages undefined");
debug(messages);
assert.equal(messages.length, 1, "unexpected number of messages");
assert.ok(messages[0].message, "did not find message 0");
assert.equal(
messages[0].message,
"The value 'gce_instance' should not be used here. ResourceType should be 'api'",
);
});
test("invalid2", (p, foundIssues) => {
assert.equal(foundIssues, true);
const messages = p.getReport().messages;
assert.ok(messages, "messages undefined");
debug(messages);
assert.equal(messages.length, 1, "unexpected number of messages");
assert.ok(messages[0].message, "did not find message 0");
assert.equal(
messages[0].message,
"The value 'apigee.googleapis.com/Environment' should not be used here. ResourceType should be 'api'",
);
});
test("invalid3", (p, foundIssues) => {
assert.equal(foundIssues, true);
const messages = p.getReport().messages;
assert.ok(messages, "messages undefined");
debug(messages);
assert.equal(messages.length, 2, "unexpected number of messages");
assert.ok(messages[0].message, "did not find message 0");
assert.equal(messages[0].message, "Unsupported element 'NotKey'");
assert.equal(
messages[1].message,
"Label is missing a required Element: Key.",
);
});
});