fix(network-map): подписать unbound-пути парой серверов
Docker images / prepare-release (push) Successful in 7s
Docker images / backend-test (push) Successful in 2m22s
Docker images / frontend-image (push) Successful in 3m29s
Docker images / updater-image (push) Successful in 52s
Docker images / backend-image (push) Successful in 2m41s
Docker images / notify-webhook (push) Skipped
Docker images / publish-release (push) Successful in 12s
Docker images / prepare-release (push) Successful in 7s
Docker images / backend-test (push) Successful in 2m22s
Docker images / frontend-image (push) Successful in 3m29s
Docker images / updater-image (push) Successful in 52s
Docker images / backend-image (push) Successful in 2m41s
Docker images / notify-webhook (push) Skipped
Docker images / publish-release (push) Successful in 12s
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
import assert from "node:assert/strict"
|
||||
import {
|
||||
formatServicePathLabel,
|
||||
formatServicePathTitle,
|
||||
isUnboundServicePath,
|
||||
} from "./format-service-path-label.ts"
|
||||
|
||||
const bound = {
|
||||
clientId: "u1",
|
||||
clientName: "D",
|
||||
viaId: "7",
|
||||
viaName: "nsk-gw01",
|
||||
enId: "9",
|
||||
enName: "arn-gw01",
|
||||
serviceId: "svc:cdn",
|
||||
}
|
||||
|
||||
const jhEn = {
|
||||
clientId: "—",
|
||||
clientName: "—",
|
||||
viaId: "7",
|
||||
viaName: "msk-gw01",
|
||||
enId: "9",
|
||||
enName: "arn-gw01",
|
||||
serviceId: "svc:cdn",
|
||||
}
|
||||
|
||||
const enOnly = {
|
||||
clientId: "—",
|
||||
clientName: "—",
|
||||
viaId: "9",
|
||||
viaName: "arn-gw01",
|
||||
enId: "9",
|
||||
enName: "arn-gw01",
|
||||
serviceId: "svc:cdn",
|
||||
}
|
||||
|
||||
assert.equal(isUnboundServicePath(jhEn), true)
|
||||
assert.equal(isUnboundServicePath(bound), false)
|
||||
|
||||
assert.equal(
|
||||
formatServicePathLabel(jhEn, "via", { viaName: "msk-gw01.rtnt.top", enName: "arn-gw01.rtnt.top" }),
|
||||
"msk-gw01.rtnt.top → arn-gw01.rtnt.top",
|
||||
)
|
||||
assert.equal(formatServicePathLabel(enOnly, "via"), "arn-gw01 · без привязки")
|
||||
assert.equal(formatServicePathLabel(enOnly, "service"), "arn-gw01 · без привязки")
|
||||
|
||||
assert.equal(
|
||||
formatServicePathLabel(bound, "via", { viaSite: "NSK" }),
|
||||
"D · NSK",
|
||||
)
|
||||
assert.equal(
|
||||
formatServicePathLabel(bound, "service", { serviceLabel: "CDN" }),
|
||||
"D · CDN",
|
||||
)
|
||||
|
||||
assert.equal(
|
||||
formatServicePathTitle("msk-gw01 → arn-gw01", "CDN"),
|
||||
"msk-gw01 → arn-gw01 · CDN",
|
||||
)
|
||||
|
||||
console.log("format-service-path-label.test.ts: ok")
|
||||
@@ -0,0 +1,45 @@
|
||||
export const UNBOUND_PATH_CLIENT = "—"
|
||||
|
||||
export interface ServicePathLabelInput {
|
||||
clientId: string
|
||||
clientName: string
|
||||
viaId: string
|
||||
viaName: string
|
||||
enId: string
|
||||
enName: string
|
||||
serviceId: string
|
||||
}
|
||||
|
||||
export interface ServicePathLabelNames {
|
||||
viaName?: string
|
||||
viaSite?: string
|
||||
enName?: string
|
||||
serviceLabel?: string
|
||||
}
|
||||
|
||||
export function isUnboundServicePath(p: Pick<ServicePathLabelInput, "clientId" | "clientName">): boolean {
|
||||
return p.clientId === UNBOUND_PATH_CLIENT || p.clientName === UNBOUND_PATH_CLIENT
|
||||
}
|
||||
|
||||
export function formatServicePathLabel(
|
||||
p: ServicePathLabelInput,
|
||||
viaMode: "via" | "service",
|
||||
names: ServicePathLabelNames = {},
|
||||
): string {
|
||||
const viaName = names.viaName || p.viaName
|
||||
const enName = names.enName || p.enName
|
||||
if (isUnboundServicePath(p)) {
|
||||
if (p.viaId !== p.enId) return `${viaName} → ${enName}`
|
||||
return `${enName} · без привязки`
|
||||
}
|
||||
const viaLabel = names.viaSite || p.viaName
|
||||
const mid = viaMode === "via" ? viaLabel : (names.serviceLabel || p.serviceId)
|
||||
return `${p.clientName} · ${mid}`
|
||||
}
|
||||
|
||||
export function formatServicePathTitle(label: string, serviceLabel: string): string {
|
||||
const svc = serviceLabel.trim()
|
||||
if (!svc) return label
|
||||
if (label.includes(svc)) return label
|
||||
return `${label} · ${svc}`
|
||||
}
|
||||
Reference in New Issue
Block a user