Mock promisify

This commit is contained in:
Tessa Walsh 2023-07-05 16:40:44 -04:00
parent c0db99d364
commit e3ef7c192a

View file

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