mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 06:23:16 +00:00
Mock df child_process
This commit is contained in:
parent
8c83814b1b
commit
c0db99d364
1 changed files with 4 additions and 10 deletions
|
@ -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({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue