fix(truenas): guard empty dataset percentage
This commit is contained in:
1 parent
425dd90871
commit
f6137b2dcc
2 files changed
+15
-1
No files matched your search
@@ -218,6 +218,19 @@ describe("TrueNasIntegration", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("reports zero usage for an empty root dataset", async () => {
|
||||||
|
ws.setResponder((method) =>
|
||||||
|
method === "pool.dataset.query"
|
||||||
|
? [{ id: "tank", used: { parsed: 0 }, available: { parsed: 0 } }]
|
||||||
|
: happyResponder(method),
|
||||||
|
);
|
||||||
|
const integration = createIntegration(credentials);
|
||||||
|
|
||||||
|
const result = await integration.getSystemInfoAsync();
|
||||||
|
|
||||||
|
expect(result.fileSystem[0]?.percentage).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
test("authenticates with an API key when one is configured", async () => {
|
test("authenticates with an API key when one is configured", async () => {
|
||||||
const integration = createIntegration([{ kind: "apiKey", value: "api-key-123" }]);
|
const integration = createIntegration([{ kind: "apiKey", value: "api-key-123" }]);
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ export class TrueNasIntegration extends Integration implements ISystemHealthMoni
|
|||||||
deviceName: dataset.name,
|
deviceName: dataset.name,
|
||||||
available: `${dataset.available}`,
|
available: `${dataset.available}`,
|
||||||
used: `${dataset.used}`,
|
used: `${dataset.used}`,
|
||||||
percentage: (dataset.used / (dataset.used + dataset.available)) * 100,
|
percentage:
|
||||||
|
dataset.used + dataset.available === 0 ? 0 : (dataset.used / (dataset.used + dataset.available)) * 100,
|
||||||
})),
|
})),
|
||||||
availablePkgUpdates: 0,
|
availablePkgUpdates: 0,
|
||||||
network: {
|
network: {
|
||||||
|
|||||||
Reference in new issue
Block a user