Docker images / prepare-release (push) Successful in 14s
Docker images / backend-test (push) Successful in 12m24s
Docker images / frontend-image (push) Successful in 2m21s
Docker images / updater-image (push) Successful in 41s
Docker images / netflow-agent-image (push) Successful in 32s
Docker images / backend-image (push) Successful in 1m52s
Docker images / publish-release (push) Successful in 17s
Docker images / notify-webhook (push) Successful in 2s
98 lines
5.6 KiB
TypeScript
98 lines
5.6 KiB
TypeScript
import { test } from "node:test"
|
||
import assert from "node:assert/strict"
|
||
import { MAP_CARD_H, MAP_CARD_W, MAP_PILL_H, mapLinkPath, mapLinkPoint, mapRibbons, placeMapLinkLabels, type MapBox } from "../../lib/network-map-layout"
|
||
import { mapObservationRoute } from "../../lib/network-map-observation-route"
|
||
|
||
const card = (x: number, y: number): MapBox => ({ x: x - MAP_CARD_W / 2, y: y - MAP_CARD_H / 2, w: MAP_CARD_W, h: MAP_CARD_H })
|
||
const hit = (a: MapBox, b: MapBox) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h
|
||
const pill = (p: { x: number; y: number; w: number }): MapBox => ({ x: p.x - p.w / 2, y: p.y - MAP_PILL_H / 2, w: p.w, h: MAP_PILL_H })
|
||
|
||
test("кривая связи проходит через концы и середину", () => {
|
||
const l = mapLinkPath({ x: 0, y: 0 }, 10, { x: 200, y: 100 }, 10)
|
||
assert.deepEqual(mapLinkPoint(l, 0), { x: 10, y: 0 })
|
||
assert.deepEqual(mapLinkPoint(l, 1), { x: 190, y: 100 })
|
||
assert.deepEqual(mapLinkPoint(l, 0.5), { x: 100, y: 50 })
|
||
})
|
||
|
||
test("наблюдение IPFIX огибает промежуточный узел в обоих направлениях", () => {
|
||
const blocker = card(400, 100)
|
||
for (const [sourceX, serviceX] of [[100, 800], [800, 100]]) {
|
||
const link = mapLinkPath({x: sourceX, y: 100}, 80, {x: serviceX, y: 100}, 140)
|
||
const route = mapObservationRoute(link, [blocker], [])
|
||
assert.ok(route)
|
||
assert.ok(route.d.startsWith(`M ${link.x1} 100 `) && route.d.endsWith(`L ${link.x2} 100`))
|
||
assert.ok(route.track < blocker.y || route.track > blocker.y + blocker.h)
|
||
}
|
||
})
|
||
|
||
test("неисправная связь выходит на отдельную верхнюю полку, обычная обходит промежуточную колонку", () => {
|
||
const a = {x: 100, y: 170}, b = {x: 680, y: 230}
|
||
const issue = mapLinkPath(a, 70, b, 75, {faultY: 49})
|
||
assert.equal(issue.x1, 30)
|
||
assert.equal(issue.x2, 755)
|
||
assert.deepEqual(issue.points.slice(2, 4), [{x:25,y:49}, {x:761,y:49}])
|
||
assert.match(issue.d, / Q /)
|
||
const normal = mapLinkPath(a, 70, b, 75, {obstacles:[{x:340,y:140,w:120,h:125}]})
|
||
assert.equal(normal.x1, 170)
|
||
assert.equal(normal.x2, 605)
|
||
assert.ok(normal.points[2].y < 140 || normal.points[2].y > 265)
|
||
})
|
||
|
||
test("GRE одной колонки остаётся снаружи правых граней обеих карточек при любом состоянии", () => {
|
||
const top = {x: 400, y: 120}, bottom = {x: 400, y: 320}
|
||
for (const [a,b] of [[top,bottom],[bottom,top]]) {
|
||
for (const faultY of [undefined,64]) {
|
||
const link = mapLinkPath(a, 70, b, 70, {faultY})
|
||
assert.deepEqual(mapLinkPoint(link,0), {x:470,y:a.y})
|
||
assert.deepEqual(mapLinkPoint(link,1), {x:470,y:b.y})
|
||
assert.ok(link.points.slice(1,-1).every(p => p.x > 470))
|
||
if (faultY != null) assert.ok(link.points.some(p => p.y === faultY))
|
||
}
|
||
}
|
||
})
|
||
|
||
test("подписи не наезжают на карточки и друг на друга, длинная — укорачивается или пропадает", () => {
|
||
// Три JH слева сходятся в один EN справа; у каждой пары — длинный и короткий вариант подписи.
|
||
const jh = [100, 180, 260].map((y) => ({ x: 542, y }))
|
||
const en = { x: 780, y: 180 }
|
||
const obstacles = [...jh.map((p) => card(p.x, p.y)), card(en.x, en.y)]
|
||
const labels = jh.map((p, i) => ({
|
||
id: "jh" + i,
|
||
link: mapLinkPath(p, MAP_CARD_W / 2, en, MAP_CARD_W / 2),
|
||
texts: ["24 мс · 86 Мбит/с", "24 мс"],
|
||
}))
|
||
// Горизонтальная связь в узком зазоре: длинной подписи места нет нигде.
|
||
labels.push({ id: "flat", link: mapLinkPath({ x: 542, y: 400 }, MAP_CARD_W / 2, { x: 780, y: 400 }, MAP_CARD_W / 2), texts: ["очень длинная подпись связи"] })
|
||
obstacles.push(card(542, 400), card(780, 400))
|
||
const placed = placeMapLinkLabels(labels, obstacles)
|
||
assert.ok(placed.length >= 3, "подписи трёх сходящихся связей размещены")
|
||
assert.equal(placed.find((p) => p.id === "flat"), undefined, "не влезающая подпись не рисуется")
|
||
for (const [i, a] of placed.entries()) {
|
||
for (const o of obstacles) assert.equal(hit(pill(a), o), false, a.id + " поверх карточки")
|
||
for (const b of placed.slice(i + 1)) assert.equal(hit(pill(a), pill(b)), false, a.id + " поверх " + b.id)
|
||
}
|
||
})
|
||
|
||
test("ленты NetFlow уложены стопкой у узла и толще у большей скорости", () => {
|
||
const exit = { x: 780, y: 300 }
|
||
const flows = [
|
||
{ id: "a", from: exit, fromHalfW: 80, to: { x: 1080, y: 200 }, toHalfW: 140, bps: 300 },
|
||
{ id: "b", from: exit, fromHalfW: 80, to: { x: 1080, y: 400 }, toHalfW: 140, bps: 100 },
|
||
]
|
||
const [a, b] = mapRibbons(flows, 40)
|
||
assert.equal(a.w, 30)
|
||
assert.equal(b.w, 10)
|
||
// У выхода ленты лежат вплотную по центру карточки (стопка 40 px при пике 400 — сумма у выхода).
|
||
assert.match(a.d, /^M 860 295\.0 /)
|
||
assert.match(b.d, /^M 860 315\.0 /)
|
||
assert.match(a.d, / 940 200\.0$/)
|
||
})
|
||
|
||
test("совпадающие середины двух связей разводятся по своим кривым", () => {
|
||
const a = mapLinkPath({ x: 0, y: 0 }, 0, { x: 300, y: 200 }, 0)
|
||
const b = mapLinkPath({ x: 0, y: 200 }, 0, { x: 300, y: 0 }, 0)
|
||
const placed = placeMapLinkLabels([{ id: "a", link: a, texts: ["12 мс"] }, { id: "b", link: b, texts: ["14 мс"] }], [])
|
||
assert.equal(placed.length, 2)
|
||
assert.equal(hit(pill(placed[0]), pill(placed[1])), false)
|
||
})
|