26 lines
1.5 KiB
TypeScript
26 lines
1.5 KiB
TypeScript
const failures: Record<string, string> = {
|
|
"authentication failed": "RouterOS отклонил авторизацию bandwidth-test",
|
|
"can not connect": "Bandwidth-test не смог подключиться к назначению",
|
|
"can not start test": "RouterOS не смог начать bandwidth-test",
|
|
"remote is busy": "Устройство назначения занято",
|
|
"test unsupported": "Устройство назначения не поддерживает bandwidth-test",
|
|
"disconnected": "Соединение bandwidth-test прервано до завершения",
|
|
}
|
|
|
|
/** HTTP success is insufficient: the last reported native state must confirm completion. */
|
|
export function assertBandwidthTestCompleted(raw: unknown): asserts raw is Array<Record<string, unknown>> {
|
|
const unknown = () => new Error("RouterOS не подтвердил завершение bandwidth-test. Результат операции неизвестен")
|
|
if (!Array.isArray(raw) || !raw.length) throw unknown()
|
|
let lastStatus: string | undefined
|
|
for (const row of raw) {
|
|
if (!row || typeof row !== "object" || Array.isArray(row)) throw unknown()
|
|
if ("error" in row || "failure" in row || "!trap" in row) throw unknown()
|
|
if (row.status === undefined) continue
|
|
if (typeof row.status !== "string" || !row.status.trim()) throw unknown()
|
|
const status = row.status.trim().toLowerCase()
|
|
if (Object.hasOwn(failures, status)) throw new Error(failures[status])
|
|
lastStatus = status
|
|
}
|
|
if (lastStatus !== "done testing") throw unknown()
|
|
}
|