Mock df child_process

This commit is contained in:
Tessa Walsh 2023-07-05 16:24:42 -04:00
parent 8c83814b1b
commit c0db99d364

View file

@ -1,6 +1,6 @@
import { jest } from "@jest/globals";
import { calculatePercentageUsed, checkDiskUtilization, getDiskUsage } from "../util/storage.js";
import child_process from "child_process";
import { calculatePercentageUsed, checkDiskUtilization } from "../util/storage.js";
const mockDfOutput = `Filesystem 1K-blocks Used Available Use% Mounted on
grpcfuse 971350180 270314600 701035580 28% /crawls`;
@ -17,13 +17,7 @@ test("ensure calculatePercentageUsed returns expected values", () => {
expect(calculatePercentageUsed(0, 5)).toEqual(0);
});
jest.mock("../util/storage.js", () => {
const original = jest.requireActual("../util/storage.js");
return {
...original,
getDiskUsage: jest.fn()
};
});
jest.mock("child_process");
test("verify end-to-end disk utilization check works as expected with mock df return", async () => {
const params = {
@ -32,7 +26,7 @@ test("verify end-to-end disk utilization check works as expected with mock df re
generateWACZ: true
};
getDiskUsage.mockImplementation(() => (mockDfOutput));
child_process.exec.mockImplementation((command, callback) => callback(null, {stdout: mockDfOutput}));
const returnValue = await checkDiskUtilization(params, 7500000);
expect(returnValue).toEqual({