fix(evobgp): проверять каталог и сохранять навигацию при ошибках API
This commit is contained in:
1 parent
a0263c22a5
commit
0d2affaf6b
7 files changed
+77
-4
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { test } from "node:test"
|
||||
import { parseEvoBgpCatalog } from "./evobgp-catalog"
|
||||
const empty = { fetchedAt: "2026-10-01T00:00:00Z", modules: [], domains: [], ipRanges: [], asns: [], communities: [] }
|
||||
const domain = { id: "domain-1", domain: "example.test", resolvedIp: "—", asn: "—", purpose: "", filter: "", updated: "—", enabled: false }
|
||||
test("known empty and false stay explicit without invented rows", () => {
|
||||
assert.deepEqual(parseEvoBgpCatalog(empty), empty)
|
||||
assert.equal(parseEvoBgpCatalog({ ...empty, domains: [domain] }).domains[0].enabled, false)
|
||||
})
|
||||
test("malformed or partial catalogue never reaches consumers as a snapshot", () => {
|
||||
for (const raw of [{}, null, { ...empty, domains: undefined }, { ...empty, asns: {} }, { ...empty, fetchedAt: "bad" }, { ...empty, domains: [null] }, { ...empty, domains: [{ ...domain, enabled: undefined }] }, { ...empty, domains: [domain, domain] }]) assert.throws(() => parseEvoBgpCatalog(raw), /Каталог Evolution не подтверждён/)
|
||||
})
|
||||
test("ASN and community zero counts are preserved, invalid counts rejected", () => {
|
||||
const asn = { id: "asn-1", asn: "AS1", org: "", country: "", prefixes: 0, filter: "", updated: "—", enabled: false }
|
||||
assert.equal(parseEvoBgpCatalog({ ...empty, asns: [asn] }).asns[0].prefixes, 0)
|
||||
assert.throws(() => parseEvoBgpCatalog({ ...empty, asns: [{ ...asn, prefixes: -1 }] }))
|
||||
})
|
||||
Reference in new issue
Block a user