forked from CycloneDX/cdxgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotobom.test.js
32 lines (29 loc) · 1.08 KB
/
protobom.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
import { expect, test } from "@jest/globals";
import { tmpdir } from "node:os";
import { existsSync, rmSync, mkdtempSync, readFileSync } from "node:fs";
import { join } from "node:path";
import { writeBinary, readBinary } from "./protobom.js";
const tempDir = mkdtempSync(join(tmpdir(), "bin-tests-"));
const testBom = JSON.parse(
readFileSync("./test/data/bom-java.json", { encoding: "utf-8" })
);
test("proto binary tests", () => {
const binFile = join(tempDir, "test.cdx.bin");
writeBinary({}, binFile);
expect(existsSync(binFile)).toBeTruthy();
writeBinary(testBom, binFile);
expect(existsSync(binFile)).toBeTruthy();
let bomObject = readBinary(binFile);
expect(bomObject).toBeDefined();
expect(bomObject.serialNumber).toEqual(
"urn:uuid:cc8b5a04-2698-4375-b04c-cedfa4317fee"
);
bomObject = readBinary(binFile, false);
expect(bomObject).toBeDefined();
expect(bomObject.serialNumber).toEqual(
"urn:uuid:cc8b5a04-2698-4375-b04c-cedfa4317fee"
);
if (tempDir && tempDir.startsWith(tmpdir()) && rmSync) {
rmSync(tempDir, { recursive: true, force: true });
}
});