forked from CycloneDX/cdxgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpostgen.test.js
70 lines (67 loc) · 2.29 KB
/
postgen.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
import { filterBom } from "./postgen.js";
import { readFileSync } from "node:fs";
import { expect, test } from "@jest/globals";
test("filter bom tests", () => {
const bomJson = JSON.parse(
readFileSync("./test/data/bom-postgen-test.json", "utf-8")
);
let newBom = filterBom(bomJson, {});
expect(bomJson).toEqual(newBom);
expect(newBom.components.length).toEqual(1060);
newBom = filterBom(bomJson, { requiredOnly: true });
for (const comp of newBom.components) {
if (comp.scope && comp.scope !== "required") {
throw new Error(`${comp.scope} is unexpected`);
}
}
expect(newBom.components.length).toEqual(345);
});
test("filter bom tests2", () => {
const bomJson = JSON.parse(
readFileSync("./test/data/bom-postgen-test2.json", "utf-8")
);
let newBom = filterBom(bomJson, {});
expect(bomJson).toEqual(newBom);
expect(newBom.components.length).toEqual(199);
newBom = filterBom(bomJson, { requiredOnly: true });
for (const comp of newBom.components) {
if (comp.scope && comp.scope !== "required") {
throw new Error(`${comp.scope} is unexpected`);
}
}
expect(newBom.components.length).toEqual(199);
newBom = filterBom(bomJson, { filter: [""] });
expect(newBom.components.length).toEqual(199);
newBom = filterBom(bomJson, { filter: ["apache"] });
for (const comp of newBom.components) {
if (comp.purl.includes("apache")) {
throw new Error(`${comp.purl} is unexpected`);
}
}
expect(newBom.components.length).toEqual(177);
newBom = filterBom(bomJson, { filter: ["apache", "json"] });
for (const comp of newBom.components) {
if (comp.purl.includes("apache") || comp.purl.includes("json")) {
throw new Error(`${comp.purl} is unexpected`);
}
}
expect(newBom.components.length).toEqual(172);
expect(newBom.compositions).toBeUndefined();
newBom = filterBom(bomJson, {
only: ["org.springframework"],
specVersion: 1.5,
autoCompositions: true
});
for (const comp of newBom.components) {
if (!comp.purl.includes("org.springframework")) {
throw new Error(`${comp.purl} is unexpected`);
}
}
expect(newBom.components.length).toEqual(37);
expect(newBom.compositions).toEqual([
{
aggregate: "incomplete_first_party_only",
"bom-ref": "pkg:maven/sec/[email protected]?type=jar"
}
]);
});