25 lines
1.8 KiB
TypeScript
25 lines
1.8 KiB
TypeScript
import { test } from "node:test"
|
|
import assert from "node:assert/strict"
|
|
import { assertBandwidthTestCompleted } from "./bandwidth-test-status.js"
|
|
import { readBandwidthTestRates } from "./bandwidth-test-rates.js"
|
|
|
|
test("confirmed completion preserves one-direction unknown and explicit zero", () => {
|
|
const rows = [{ status: "connecting" }, { status: "running", "rx-current": "20Mbps" }, { status: "done testing", "rx-total-average": "0bps" }]
|
|
assert.doesNotThrow(() => assertBandwidthTestCompleted(rows))
|
|
const result = readBandwidthTestRates(rows)
|
|
assert.equal(result.txAvgMbps, null)
|
|
assert.equal(result.rxAvgMbps, 0)
|
|
assert.doesNotThrow(() => assertBandwidthTestCompleted([{ status: "done testing" }, { "tx-total-average": "10Mbps" }]))
|
|
})
|
|
test("all native failures reject even with valid rates or a subsequent success marker", () => {
|
|
for (const status of ["authentication failed", "can not connect", "can not start test", "remote is busy", "test unsupported", "disconnected"]) {
|
|
assert.throws(() => assertBandwidthTestCompleted([{ status, "tx-total-average": "50Mbps" }]))
|
|
assert.throws(() => assertBandwidthTestCompleted([{ status }, { status: "done testing" }]))
|
|
}
|
|
})
|
|
test("missing, incomplete and malformed native replies never count as completed", () => {
|
|
for (const raw of [null, {}, [], [null], [[]], [{ status: 8 }], [{ status: "" }], [{ "tx-total-average": "50Mbps" }], [{ status: "running" }], [{ status: "connecting" }], [{ status: "done testing" }, { status: "running" }], [{ status: "done testing" }, { status: "future status" }], [{ status: "done testing", error: "failure" }], [{ status: "done testing", failure: "failure" }], [{ status: "done testing", "!trap": true }]]) {
|
|
assert.throws(() => assertBandwidthTestCompleted(raw), /Результат операции неизвестен/)
|
|
}
|
|
})
|