Docker images / prepare-release (push) Successful in 11s
Docker images / backend-test (push) Successful in 3s
Docker images / frontend-image (push) Successful in 2m14s
Docker images / updater-image (push) Successful in 40s
Docker images / netflow-agent-image (push) Successful in 34s
Docker images / backend-image (push) Successful in 16s
Docker images / publish-release (push) Successful in 10s
Docker images / notify-webhook (push) Successful in 1s
82 lines
7.3 KiB
TypeScript
82 lines
7.3 KiB
TypeScript
import { test, expect, type Page } from "@playwright/test"
|
||
|
||
// Подписи и карточки холста не наезжают друг на друга: проверяем видимые тела (data-map-box), а не фоновые полосы.
|
||
const empty = { hops: [], live: true, rangeMinutes: 5, windowSec: 300, totalBytes: 0, namedBytes: 0, unclassifiedBytes: 0, asnLoaded: false, countryLoaded: false, services: [], serviceEdges: [], servicePaths: [], countries: [], countryEdges: [], countryPaths: [], countryServiceGroups: [], mapServiceMinSharePct: 0, dedupApplied: false, excludeMeshApplied: false, excludeOverlayApplied: false }
|
||
const srv = (id: number, name: string, type: string, country = "RU", status = "online") =>
|
||
({ id, name, host: `192.0.2.${id}`, type, country, enabled: true, status, latency: 10 + id })
|
||
const gre = (id: string, owner: number, peer: number, status = "up") => ({
|
||
id, serverId: String(owner), name: id, localAddress: `192.0.2.${owner}`, remoteAddress: `192.0.2.${peer}`, localInnerIp: "", remoteInnerIp: "",
|
||
poolId: "", ipsec: null, mtu: 1400, keepaliveInterval: 10, keepaliveRetries: 3, dscp: "inherit", clampTcpMss: true, allowFastPath: false, comment: "", enabled: true, status,
|
||
})
|
||
|
||
async function serve(page: Page, servers: unknown[], tunnels: ReturnType<typeof gre>[], flow: Record<string, unknown>) {
|
||
await page.route("**/health", (r) => r.fulfill({ json: { ok: true } }))
|
||
await page.route("**/api/**", (r) => {
|
||
const p = new URL(r.request().url()).pathname
|
||
const json = p === "/api/servers" ? servers : p === "/api/filters/gre-tunnels" ? { tunnels, failures: [] }
|
||
: p === "/api/uptime/speed-probes" ? { probes: [] } : p === "/api/traffic/flow/map-hops" ? { ...empty, ...flow }
|
||
: p === "/api/ix/topology" ? { links: [] } : p === "/api/auth/config" ? { required: false } : {}
|
||
return r.fulfill({ json })
|
||
})
|
||
}
|
||
|
||
async function overlaps(page: Page) {
|
||
return page.getByRole("group", { name: "Интерактивная карта сети" }).evaluate((svg) => {
|
||
const boxes = [...svg.querySelectorAll("[data-map-box]")].map((el) => ({ kind: el.getAttribute("data-map-box")!, label: el.closest("[aria-label]")?.getAttribute("aria-label") ?? el.parentElement?.textContent ?? "", text: el.parentElement?.querySelector(":scope > text")?.textContent ?? "", r: el.getBoundingClientRect() }))
|
||
// Панель масштаба и миникарта лежат поверх холста — они тоже не должны закрывать карточки и подписи.
|
||
const overlays = [...document.querySelectorAll("[data-map-overlay]")].map((el) => ({ kind: el.getAttribute("data-map-overlay")!, label: "", r: el.getBoundingClientRect() }))
|
||
const hits: string[] = []
|
||
const pairs = [...boxes.flatMap((a, i) => boxes.slice(i + 1).map((b) => [a, b] as const)), ...overlays.flatMap((o) => boxes.map((b) => [o, b] as const))]
|
||
for (const [a, b] of pairs) {
|
||
const ix = Math.min(a.r.right, b.r.right) - Math.max(a.r.left, b.r.left), iy = Math.min(a.r.bottom, b.r.bottom) - Math.max(a.r.top, b.r.top)
|
||
if (ix > 1 && iy > 1) hits.push(`${a.kind} «${a.label}» × ${b.kind} «${b.label}»`)
|
||
}
|
||
return { overlays: overlays.length, rates: boxes.filter((b) => b.kind === "pill" && /бит\/с/.test(b.text)).length, pills: boxes.filter((b) => b.kind === "pill").length, cards: boxes.filter((b) => b.kind === "card").length, hits }
|
||
})
|
||
}
|
||
|
||
test("Карта: 3 JH → Exit + IX, параллельные GRE и 8 сервисов без наложений", async ({ page }) => {
|
||
const servers = [
|
||
srv(1, "msk-gw01.example.net", "jump-host"), srv(2, "msk-gw02.example.net", "jump-host"), srv(3, "nov-gw01.example.net", "jump-host"),
|
||
srv(4, "arn-gw01.example.net", "exit-node", "SE"), srv(5, "chr-ix.example.net", "ix-node", "PL"),
|
||
]
|
||
// У каждого JH два туннеля до выхода и запись встречного конца на выходе; один JH ещё и до IX.
|
||
const tunnels = [1, 2, 3].flatMap((jh) => [gre(`gre-${jh}a`, jh, 4), gre(`gre-${jh}b`, jh, 4, jh === 3 ? "down" : "up"), gre(`gre-4-${jh}`, 4, jh)])
|
||
tunnels.push(gre("gre-ix", 1, 5))
|
||
const names = ["Прочее", "YouTube", "Cloudflare", "main", "AWS", "Akamai", "Google", "Telegram"]
|
||
const services = names.map((label, i) => ({ id: "svc:" + i, label, category: "Веб", bytes: 9e6 - i * 1e6, bps: 6e6 - i * 7e5, share: 0.2 - i * 0.02 }))
|
||
const serviceEdges = services.map((s) => ({ fromId: "4", toId: s.id, bytes: s.bytes, bps: s.bps, bpsFwd: s.bps / 4, bpsRev: (s.bps * 3) / 4 }))
|
||
const interfaceTraffic = tunnels.map((t, i) => ({ serverId: t.serverId, iface: t.name, rxBytes: 4e6 + i * 1e5, txBytes: 1e6, rxPackets: 10, txPackets: 5, inWindow: true, lastBucketAt: "2026-11-23T07:00:00Z" }))
|
||
await serve(page, servers, tunnels, { services, serviceEdges, interfaceTraffic, totalBytes: 5e7, namedBytes: 5e7 })
|
||
await page.goto("/network-map")
|
||
await page.getByRole("button", { name: /^Остальные сервисы \(/ }).first().click()
|
||
await expect(page.getByRole("button", { name: "Сервис Telegram", exact: true })).toBeVisible()
|
||
await expect.poll(async () => (await overlaps(page)).cards).toBe(5)
|
||
const result = await overlaps(page)
|
||
expect(result.cards).toBe(5)
|
||
expect(result.overlays).toBe(2)
|
||
expect(result.hits).toEqual([])
|
||
// Скорость NetFlow пары не теряется: она на подписи или, если не влезла между карточками, — в title линии.
|
||
expect(result.rates + await page.locator("path > title", { hasText: /^Связь .*бит\/с/ }).count()).toBeGreaterThan(0)
|
||
// Имя хоста без домена, параллельные туннели — одной подписью.
|
||
await expect(page.getByRole("group", { name: "Интерактивная карта сети" }).getByText("msk-gw01", { exact: true })).toBeVisible()
|
||
const pair = /^Связь msk-gw01\.example\.net → arn-gw01\.example\.net: .*GRE ×2/
|
||
expect(await page.getByRole("button", { name: pair }).count()).toBeLessThanOrEqual(1)
|
||
expect(await page.locator("path > title", { hasText: pair }).count()).toBeGreaterThan(0)
|
||
})
|
||
|
||
test("Карта: сетка JH × Exit и аплинки WAN без наложений подписей", async ({ page }) => {
|
||
const wan = (i: number) => ({ id: "w" + i, name: "WAN" + i, iface: "ether" + i, isp: "ISP-" + i, ip: `198.51.100.${i}`, maxDl: 100, maxUl: 50 })
|
||
const servers = [
|
||
{ ...srv(1, "home-msk", "home-router"), wanUplinks: [wan(1), wan(2)] }, { ...srv(2, "home-spb", "home-router"), wanUplinks: [wan(3), wan(4)] },
|
||
srv(3, "mt-msk-core-01", "jump-host"), srv(4, "mt-msk-lab-01", "jump-host"), srv(5, "mt-ams-test-01", "jump-host", "NL"),
|
||
srv(6, "mt-fra-edge-01", "exit-node", "DE"), srv(7, "mt-sgp-edge-01", "exit-node", "SG", "offline"), srv(8, "mt-spb-edge-01", "exit-node"), srv(9, "mt-ams-edge-01", "exit-node", "NL", "degraded"),
|
||
]
|
||
const tunnels = [3, 4, 5].flatMap((jh) => [6, 7, 8, 9].map((en) => gre(`gre-${jh}-${en}`, jh, en, en === 7 ? "down" : "up")))
|
||
await serve(page, servers, tunnels, {})
|
||
await page.goto("/network-map")
|
||
await expect(page.getByRole("button", { name: /^Устройство mt-ams-edge-01/ })).toBeVisible()
|
||
await expect.poll(async () => (await overlaps(page)).pills).toBeGreaterThan(2)
|
||
expect((await overlaps(page)).hits).toEqual([])
|
||
})
|