From a9d36e3ccf927294123a4e3c0c05a8b8d7333c78 Mon Sep 17 00:00:00 2001 From: Gahow Wang Date: Fri, 15 May 2026 11:14:06 +0800 Subject: [PATCH] test: add GPU and quota service tests --- test/gpu.test.js | 26 ++++++++++++++++++++++++++ test/quota.test.js | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/gpu.test.js create mode 100644 test/quota.test.js diff --git a/test/gpu.test.js b/test/gpu.test.js new file mode 100644 index 0000000..39ec046 --- /dev/null +++ b/test/gpu.test.js @@ -0,0 +1,26 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import { parseNvidiaSmiCsv } from '../src/services/gpu.js'; + +describe('parseNvidiaSmiCsv', () => { + it('parses GPU memory and utilization rows', () => { + const result = parseNvidiaSmiCsv('0, NVIDIA A100, 1024, 40960, 87\n1, RTX 4090, 12, 24564, 3'); + + assert.deepEqual(result, [ + { + index: 0, + name: 'NVIDIA A100', + memoryUsedMiB: 1024, + memoryTotalMiB: 40960, + gpuUtilizationPercent: 87 + }, + { + index: 1, + name: 'RTX 4090', + memoryUsedMiB: 12, + memoryTotalMiB: 24564, + gpuUtilizationPercent: 3 + } + ]); + }); +}); diff --git a/test/quota.test.js b/test/quota.test.js new file mode 100644 index 0000000..f7b109d --- /dev/null +++ b/test/quota.test.js @@ -0,0 +1,22 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import { summarizeQuotaOutput } from '../src/services/quota.js'; + +describe('summarizeQuotaOutput', () => { + it('summarizes ipads-quota json output', () => { + const result = summarizeQuotaOutput('{"remaining":123,"usage":{"total":45}}'); + + assert.equal(result.kind, 'json'); + assert.equal(result.remaining, 123); + assert.equal(result.used, 45); + }); + + it('summarizes text output from custom quota commands', () => { + const result = summarizeQuotaOutput('remaining: 80 used: 20 limit: 100'); + + assert.equal(result.kind, 'text'); + assert.equal(result.remaining, 80); + assert.equal(result.used, 20); + assert.equal(result.limit, 100); + }); +});