Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(db): add check for gdu vs du #5788

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/db/test/unit/controller/level.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {execSync} from "node:child_process";
import os from "node:os";
import {expect} from "chai";
import leveldown from "leveldown";
import all from "it-all";
Expand Down Expand Up @@ -135,9 +136,23 @@ describe("LevelDB controller", () => {
expect(approxSize).gt(0, "approximateSize return not > 0");
});

function getDuCommand(): string {
if (os.platform() === "darwin") {
try {
const res = execSync("gdu --help", {encoding: "utf8"});
if (res?.startsWith("Usage: gdu ")) {
return "gdu";
}
} catch {
/* no-op */
}
}
return "du";
}

function getDbSize(): number {
// 116 ./.__testdb
const res = execSync(`du -bs ${dbLocation}`, {encoding: "utf8"});
const res = execSync(`${getDuCommand()} -bs ${dbLocation}`, {encoding: "utf8"});
const match = res.match(/^(\d+)/);
if (!match) throw Error(`Unknown du response \n${res}`);
return parseInt(match[1]);
Expand Down