Skip to content

Commit

Permalink
tes(db)t: add check for gdu vs du
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewkeil committed Jul 23, 2023
1 parent 3257345 commit 16dc863
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit 16dc863

Please sign in to comment.