From 16dc86389610c6b832e61cc0c2f9eaaab5ea9796 Mon Sep 17 00:00:00 2001 From: matthewkeil Date: Sun, 23 Jul 2023 01:20:15 -0400 Subject: [PATCH] tes(db)t: add check for gdu vs du --- packages/db/test/unit/controller/level.test.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/db/test/unit/controller/level.test.ts b/packages/db/test/unit/controller/level.test.ts index 337274b5eb53..38d8274ebb22 100644 --- a/packages/db/test/unit/controller/level.test.ts +++ b/packages/db/test/unit/controller/level.test.ts @@ -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"; @@ -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]);